use of io.swagger.v3.oas.annotations.parameters.RequestBody in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method testArrayItems.
@Test
public void testArrayItems() {
String yaml = "openapi: 3.0.0\n" + "info:\n" + " title: Test\n" + " version: 1.0.0\n" + "paths:\n" + " \"/store/inventory\":\n" + " post:\n" + " requestBody:\n" + " content:\n" + " application/json:\n" + " schema:\n" + " type: array\n" + " minItems: 1\n" + " responses:\n" + " '200':\n" + " description: successful operation\n" + " content:\n" + " application/json:\n" + " schema:\n" + " items:\n" + " type: string";
OpenAPIV3Parser parser = new OpenAPIV3Parser();
SwaggerParseResult result = parser.readContents(yaml, null, null);
assertEquals(result.getMessages(), Arrays.asList("attribute paths.'/store/inventory'(post).requestBody.content.'application/json'.schema.items is missing"));
OpenAPI openAPI = result.getOpenAPI();
Schema body = openAPI.getPaths().get("/store/inventory").getPost().getRequestBody().getContent().get("application/json").getSchema();
assertFalse(body.getClass().equals(ArraySchema.class), "body is an ArraySchema");
assertEquals(body.getType(), "array");
assertEquals(body.getMinItems(), Integer.valueOf(1));
Schema response = openAPI.getPaths().get("/store/inventory").getPost().getResponses().get("200").getContent().get("application/json").getSchema();
assertTrue(response.getClass().equals(ArraySchema.class), "response is an ArraySchema");
assertEquals(body.getType(), "array");
}
use of io.swagger.v3.oas.annotations.parameters.RequestBody in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method testDeserializeBinaryString.
@Test
public void testDeserializeBinaryString() {
String yaml = "openapi: 3.0.0\n" + "servers: []\n" + "info:\n" + " title: foo\n" + " version: ''\n" + "paths:\n" + " /test:\n" + " post:\n" + " responses:\n" + " '200':\n" + " description: ok\n" + " requestBody:\n" + " content:\n" + " application/json:\n" + " schema:\n" + " type: string\n" + " format: binary";
OpenAPIV3Parser parser = new OpenAPIV3Parser();
SwaggerParseResult result = parser.readContents(yaml, null, null);
final OpenAPI resolved = new OpenAPIResolver(result.getOpenAPI(), null).resolve();
assertTrue(resolved.getPaths().get("/test").getPost().getRequestBody().getContent().get("application/json").getSchema() instanceof BinarySchema);
}
use of io.swagger.v3.oas.annotations.parameters.RequestBody in project swagger-parser by swagger-api.
the class InlineModelResolverTest method testArbitraryRequestBody.
@Test
public void testArbitraryRequestBody() {
OpenAPI openAPI = new OpenAPI();
openAPI.path("/hello", new PathItem().get(new Operation().requestBody(new RequestBody().content(new Content().addMediaType("*/*", new MediaType().schema(new Schema()))))));
new InlineModelResolver().flatten(openAPI);
Operation operation = openAPI.getPaths().get("/hello").getGet();
RequestBody requestBody = operation.getRequestBody();
assertTrue(requestBody.getContent().get("*/*").getSchema() instanceof Schema);
Schema schema = requestBody.getContent().get("*/*").getSchema();
assertNull(schema.getType());
}
use of io.swagger.v3.oas.annotations.parameters.RequestBody in project swagger-parser by swagger-api.
the class InlineModelResolverTest method resolveInlineRequestBody.
@Test
public void resolveInlineRequestBody() throws Exception {
OpenAPI openAPI = new OpenAPI();
ObjectSchema objectSchema = new ObjectSchema();
objectSchema.addProperties("street", new StringSchema());
Schema schema = new Schema();
schema.addProperties("address", objectSchema);
schema.addProperties("name", new StringSchema());
MediaType mediaType = new MediaType();
mediaType.setSchema(schema);
Content content = new Content();
content.addMediaType("*/*", mediaType);
RequestBody requestBody = new RequestBody();
requestBody.setContent(content);
Operation operation = new Operation();
operation.setRequestBody(requestBody);
PathItem pathItem = new PathItem();
pathItem.setGet(operation);
openAPI.path("/hello", pathItem);
new InlineModelResolver().flatten(openAPI);
Operation getOperation = openAPI.getPaths().get("/hello").getGet();
RequestBody body = getOperation.getRequestBody();
assertTrue(body.getContent().get("*/*").getSchema().get$ref() != null);
Schema bodySchema = openAPI.getComponents().getSchemas().get("hello_body");
assertTrue(bodySchema instanceof Schema);
assertNotNull(bodySchema.getProperties().get("address"));
}
use of io.swagger.v3.oas.annotations.parameters.RequestBody in project swagger-parser by swagger-api.
the class InlineModelResolverTest method notResolveNonModelRequestBody.
@Test
public void notResolveNonModelRequestBody() throws Exception {
OpenAPI openAPI = new OpenAPI();
openAPI.path("/hello", new PathItem().get(new Operation().requestBody(new RequestBody().content(new Content().addMediaType("*/*", new MediaType().schema(new Schema().type("string").format("binary")))))));
new InlineModelResolver().flatten(openAPI);
Operation operation = openAPI.getPaths().get("/hello").getGet();
RequestBody body = operation.getRequestBody();
assertTrue(body.getContent().get("*/*").getSchema() instanceof Schema);
Schema schema = body.getContent().get("*/*").getSchema();
assertEquals("string", schema.getType());
assertEquals("binary", schema.getFormat());
}
Aggregations