use of io.swagger.v3.parser.OpenAPIV3Parser in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testResolveFullyExample.
@Test
public void testResolveFullyExample() throws Exception {
String pathFile = FileUtils.readFileToString(new File("src/test/resources/oas3.yaml.template"));
pathFile = pathFile.replace("${dynamicPort}", String.valueOf(this.serverPort));
ParseOptions options = new ParseOptions();
options.setResolveFully(true);
SwaggerParseResult result = new OpenAPIV3Parser().readContents(pathFile, new ArrayList<>(), options);
Assert.assertNotNull(result);
Assert.assertNotNull(result.getOpenAPI());
Components components = result.getOpenAPI().getComponents();
ApiResponse response = result.getOpenAPI().getPaths().get("/mockResponses/objectMultipleExamples").getGet().getResponses().get("200");
assertEquals(response.getContent().get("application/json").getExamples().get("ArthurDent"), components.getExamples().get("Arthur"));
assertEquals(response.getContent().get("application/xml").getExamples().get("Trillian"), components.getExamples().get("Trillian"));
}
use of io.swagger.v3.parser.OpenAPIV3Parser in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testResolveFullyMap.
@Test
public void testResolveFullyMap() {
ParseOptions options = new ParseOptions();
options.setResolveFully(false);
OpenAPI openAPI = new OpenAPIV3Parser().readLocation("resolve-fully-map.yaml", null, options).getOpenAPI();
String yaml = Yaml.pretty(openAPI);
assertTrue(yaml.contains("$ref"));
options = new ParseOptions();
options.setResolveFully(true);
openAPI = new OpenAPIV3Parser().readLocation("resolve-fully-map.yaml", null, options).getOpenAPI();
yaml = Yaml.pretty(openAPI);
assertFalse(yaml.contains("$ref"));
}
use of io.swagger.v3.parser.OpenAPIV3Parser in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method checkAllOfWithRelativeReferencesAreFound.
@Test(description = "Issue #616 Relative references inside of 'allOf'")
public void checkAllOfWithRelativeReferencesAreFound() {
OpenAPI openAPI = new OpenAPIV3Parser().read("src/test/resources/allOf-relative-file-references/parent.yaml");
assertEquals(4, openAPI.getComponents().getSchemas().size());
}
use of io.swagger.v3.parser.OpenAPIV3Parser in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testIssue1309.
@Test
public void testIssue1309() {
OpenAPIV3Parser openApiParser = new OpenAPIV3Parser();
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult parseResult = openApiParser.readLocation("issue-1309.yaml", null, options);
OpenAPI openAPI = parseResult.getOpenAPI();
assertNotNull(openAPI);
assertEquals(parseResult.getMessages().get(0), "attribute components.schemas.customer-not-found.examples is unexpected");
}
use of io.swagger.v3.parser.OpenAPIV3Parser in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testIssue1039.
@Test
public void testIssue1039() {
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult parseResult = new OpenAPIV3Parser().readLocation("issue_1039.yaml", null, options);
OpenAPI apispec = parseResult.getOpenAPI();
assertNotNull(apispec);
assertEquals(apispec.getPaths().get("/pets").getGet().getParameters().get(0).getSchema().getType(), "array");
}
Aggregations