use of io.swagger.v3.parser.core.models.ParseOptions in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method doRelativeFileTest.
private OpenAPI doRelativeFileTest(String location) {
OpenAPIV3Parser parser = new OpenAPIV3Parser();
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult readResult = parser.readLocation(location, null, options);
if (readResult.getMessages().size() > 0) {
Json.prettyPrint(readResult.getMessages());
}
final OpenAPI openAPI = readResult.getOpenAPI();
final PathItem path = openAPI.getPaths().get("/health");
// we successfully converted the RefPath to a Path
assertEquals(path.getClass(), PathItem.class);
final List<Parameter> parameters = path.getParameters();
assertParamDetails(parameters, 0, QueryParameter.class, "param1", "query");
assertParamDetails(parameters, 1, HeaderParameter.class, "param2", "header");
final Operation operation = path.getGet();
final List<Parameter> operationParams = operation.getParameters();
assertParamDetails(operationParams, 0, PathParameter.class, "param3", "path");
assertParamDetails(operationParams, 1, HeaderParameter.class, "param4", "header");
final Map<String, ApiResponse> responsesMap = operation.getResponses();
assertResponse(openAPI, responsesMap, "200", "application/json", "Health information from the server", "#/components/schemas/health");
assertResponse(openAPI, responsesMap, "400", "*/*", "Your request was not valid", "#/components/schemas/error");
assertResponse(openAPI, responsesMap, "500", "*/*", "An unexpected error occur during processing", "#/components/schemas/error");
final Map<String, Schema> definitions = openAPI.getComponents().getSchemas();
final Schema refInDefinitions = definitions.get("refInDefinitions");
assertEquals(refInDefinitions.getDescription(), "The example model");
expectedPropertiesInModel(refInDefinitions, "foo", "bar");
final ArraySchema arrayModel = (ArraySchema) definitions.get("arrayModel");
final Schema arrayModelItems = arrayModel.getItems();
assertEquals(arrayModelItems.get$ref(), "#/components/schemas/foo");
final Schema fooModel = definitions.get("foo");
assertEquals(fooModel.getDescription(), "Just another model");
expectedPropertiesInModel(fooModel, "hello", "world");
final ComposedSchema composedCat = (ComposedSchema) definitions.get("composedCat");
final Schema child = composedCat.getAllOf().get(2);
expectedPropertiesInModel(child, "huntingSkill", "prop2", "reflexes", "reflexMap");
final ArraySchema reflexes = (ArraySchema) child.getProperties().get("reflexes");
final Schema reflexItems = reflexes.getItems();
assertEquals(reflexItems.get$ref(), "#/components/schemas/reflex");
assertTrue(definitions.containsKey(reflexItems.get$ref().substring(reflexItems.get$ref().lastIndexOf("/") + 1)));
final Schema reflexMap = (Schema) child.getProperties().get("reflexMap");
final Schema reflexMapAdditionalProperties = (Schema) reflexMap.getAdditionalProperties();
assertEquals(reflexMapAdditionalProperties.get$ref(), "#/components/schemas/reflex");
assertEquals(composedCat.getAllOf().size(), 3);
assertEquals(composedCat.getAllOf().get(0).get$ref(), "#/components/schemas/pet");
assertEquals(composedCat.getAllOf().get(1).get$ref(), "#/components/schemas/foo_1");
return openAPI;
}
use of io.swagger.v3.parser.core.models.ParseOptions in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testIssue1015.
@Test
public void testIssue1015() {
ParseOptions options = new ParseOptions();
options.setResolve(true);
options.setResolveCombinators(true);
SwaggerParseResult parseResult = new OpenAPIV3Parser().readLocation("issue-1015.json", null, options);
if (parseResult.getMessages() != null && !parseResult.getMessages().isEmpty()) {
parseResult.getMessages().forEach(s -> System.out.println(s));
fail("Error while loading apispec!");
}
OpenAPI apispec = parseResult.getOpenAPI();
assertNotNull(apispec);
}
use of io.swagger.v3.parser.core.models.ParseOptions in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testIssue_505.
@Test
public void testIssue_505() {
OpenAPIV3Parser openApiParser = new OpenAPIV3Parser();
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult parseResult = openApiParser.readLocation("issue-505/petstore.yml", null, options);
OpenAPI openAPI = parseResult.getOpenAPI();
assertNotNull(openAPI.getComponents().getSchemas().get("DateWithExample"));
assertNotNull(openAPI.getComponents().getExamples().get("DateWithExample"));
assertNotNull(openAPI.getComponents().getLinks().get("userRepository"));
assertEquals(3, openAPI.getPaths().get("/pets").getGet().getParameters().size());
}
use of io.swagger.v3.parser.core.models.ParseOptions in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testIssue1071.
@Test
public void testIssue1071() {
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult parseResult = new OpenAPIV3Parser().readLocation("issue-1071.yaml", null, options);
OpenAPI apispec = parseResult.getOpenAPI();
assertNotNull(apispec);
Schema test = apispec.getPaths().get("/mapschema").getGet().getResponses().get("200").getContent().get("application/json").getSchema();
assertTrue(test instanceof MapSchema);
}
use of io.swagger.v3.parser.core.models.ParseOptions in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method readingSpecStringShouldNotOverQuotingStringExample.
@Test(description = "A string example should not be over quoted when parsing a yaml string")
public void readingSpecStringShouldNotOverQuotingStringExample() throws Exception {
OpenAPIV3Parser parser = new OpenAPIV3Parser();
ParseOptions options = new ParseOptions();
options.setResolve(false);
final OpenAPI openAPI = parser.read("src/test/resources/over-quoted-example.yaml", null, options);
Map<String, Schema> definitions = openAPI.getComponents().getSchemas();
assertEquals("NoQuotePlease", definitions.get("CustomerType").getExample());
}
Aggregations