use of io.swagger.v3.oas.annotations.media.Content in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testIncompatibleRefs.
@Test
public void testIncompatibleRefs() {
String yaml = "openapi: 3.0.0\n" + "servers: []\n" + "paths:\n" + " /test:\n" + " post:\n" + " responses:\n" + " '200':\n" + " $ref: '#/components/schemas/Schema'\n" + " '400':\n" + " definitions: this is right\n" + " description: Bad Request\n" + " content:\n" + " '*/*':\n" + " schema:\n" + " $ref: '#/components/schemas/Schema'\n" + " requestBody:\n" + " content:\n" + " application/json:\n" + " schema:\n" + " $ref: '#/components/schemas/Schema'\n" + " required: true\n" + "info:\n" + " version: ''\n" + " title: ''\n" + "components:\n" + " schemas:\n" + " Schema: {}";
SwaggerParseResult result = new OpenAPIV3Parser().readContents(yaml, null, null);
assertNotNull(result.getOpenAPI());
}
use of io.swagger.v3.oas.annotations.media.Content in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testIssueSameRefsDifferentModel.
@Test
public void testIssueSameRefsDifferentModel() throws IOException {
String pathFile = FileUtils.readFileToString(new File("src/test/resources/same-refs-different-model-domain.yaml"), "UTF-8");
WireMock.stubFor(get(urlPathMatching("/issue-domain")).willReturn(aResponse().withStatus(HttpURLConnection.HTTP_OK).withHeader("Content-type", "application/json").withBody(pathFile.getBytes(StandardCharsets.UTF_8))));
pathFile = FileUtils.readFileToString(new File("src/test/resources/same-refs-different-model.yaml"), "UTF-8");
pathFile = pathFile.replace("${dynamicPort}", String.valueOf(this.serverPort));
OpenAPIV3Parser parser = new OpenAPIV3Parser();
ParseOptions options = new ParseOptions();
options.setResolve(true);
options.setResolveFully(true);
final SwaggerParseResult openAPI = parser.readContents(pathFile, null, options);
Yaml.prettyPrint(openAPI);
assertEquals(openAPI.getMessages().size(), 0);
}
use of io.swagger.v3.oas.annotations.media.Content in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testConverterIssue17.
@Test
public void testConverterIssue17() throws Exception {
String yaml = "openapi: 3.0.0\n" + "info:\n" + " version: 0.0.0\n" + " title: nada\n" + "paths:\n" + " /persons:\n" + " get:\n" + " parameters:\n" + " - name: testParam\n" + " in: query\n" + " style: form\n" + " schema:\n" + " type: array\n" + " items:\n" + " type: string\n" + " responses:\n" + " '200':\n" + " description: Successful response\n" + " content:\n" + " '*/*':\n" + " schema:\n" + " $ref: '#/components/schemas/Content'\n" + "components:\n" + " schemas:\n" + " Content:\n" + " type: object";
ParseOptions options = new ParseOptions();
options.setResolve(false);
SwaggerParseResult result = new OpenAPIV3Parser().readContents(yaml, null, options);
assertNotNull(result.getOpenAPI());
assertEquals((result.getOpenAPI().getPaths().get("/persons").getGet().getResponses().get("200").getContent().get("*/*").getSchema()).get$ref(), "#/components/schemas/Content");
}
use of io.swagger.v3.oas.annotations.media.Content in project swagger-parser by swagger-api.
the class InlineModelResolverTest method testInlineMapResponse.
@Test
public void testInlineMapResponse() throws Exception {
OpenAPI openAPI = new OpenAPI();
Schema schema = new Schema();
schema.setAdditionalProperties(new StringSchema());
schema.addExtension("x-ext", "ext-prop");
ApiResponse apiResponse = new ApiResponse();
apiResponse.description("it works!");
MediaType mediaType = new MediaType();
mediaType.setSchema(schema);
Content content = new Content();
content.addMediaType("*/*", mediaType);
apiResponse.setContent(content);
apiResponse.addExtension("x-foo", "bar");
ApiResponses apiResponses = new ApiResponses();
apiResponses.addApiResponse("200", apiResponse);
openAPI.path("/foo/baz", new PathItem().get(new Operation().responses(apiResponses)));
new InlineModelResolver().flatten(openAPI);
ApiResponse response = openAPI.getPaths().get("/foo/baz").getGet().getResponses().get("200");
Schema property = response.getContent().get("*/*").getSchema();
assertTrue(property.getAdditionalProperties() != null);
assertTrue(openAPI.getComponents().getSchemas() == null);
assertEquals(1, property.getExtensions().size());
assertEquals("ext-prop", property.getExtensions().get("x-ext"));
}
use of io.swagger.v3.oas.annotations.media.Content in project swagger-parser by swagger-api.
the class InlineModelResolverTest method resolveInlineArrayRequestBody.
@Test
public void resolveInlineArrayRequestBody() throws Exception {
OpenAPI openAPI = new OpenAPI();
ObjectSchema addressSchema = new ObjectSchema();
addressSchema.addProperties("street", new StringSchema());
ObjectSchema objectSchema = new ObjectSchema();
objectSchema.addProperties("address", addressSchema);
ArraySchema arraySchema = new ArraySchema();
arraySchema.items(objectSchema);
openAPI.path("/hello", new PathItem().get(new Operation().requestBody(new RequestBody().content(new Content().addMediaType("*/*", new MediaType().schema(arraySchema))))));
new InlineModelResolver().flatten(openAPI);
RequestBody body = openAPI.getPaths().get("/hello").getGet().getRequestBody();
Schema schema = body.getContent().get("*/*").getSchema();
assertTrue(schema instanceof ArraySchema);
ArraySchema am = (ArraySchema) schema;
Schema inner = am.getItems();
assertTrue(inner.get$ref() != null);
assertEquals("#/components/schemas/hello_body", inner.get$ref());
Schema inline = openAPI.getComponents().getSchemas().get("hello_body");
assertNotNull(inline);
assertTrue(inline instanceof Schema);
Schema address = (Schema) inline.getProperties().get("address");
assertNotNull(address);
assertEquals("#/components/schemas/hello_address", address.get$ref());
Schema inlineProp = openAPI.getComponents().getSchemas().get("hello_address");
assertNotNull(inlineProp);
assertTrue(inlineProp instanceof Schema);
assertNotNull(inlineProp.getProperties().get("street"));
assertTrue(inlineProp.getProperties().get("street") instanceof StringSchema);
}
Aggregations