use of io.swagger.v3.parser.OpenAPIV3Parser in project swagger-parser by swagger-api.
the class OpenAPIResolverTest method propertyNameMixup.
@Test
public void propertyNameMixup() {
ParseOptions parseOptions = new ParseOptions();
parseOptions.setResolveFully(true);
OpenAPI openAPI = new OpenAPIV3Parser().read("simple.yaml", null, parseOptions);
assertEquals(((StringSchema) openAPI.getComponents().getSchemas().get("Manufacturer").getProperties().get("name")).getExample(), "ACME Corporation");
Schema schema = openAPI.getPaths().get("/inventory").getGet().getResponses().get("200").getContent().get("application/json").getSchema();
assertEquals(((ObjectSchema) ((ArraySchema) schema).getItems().getProperties().get("manufacturer")).getProperties().get("name").getExample(), "ACME Corporation");
}
use of io.swagger.v3.parser.OpenAPIV3Parser in project swagger-parser by swagger-api.
the class OpenAPIResolverTest method recursiveIssue984.
@Test
public void recursiveIssue984() {
ParseOptions parseOptions = new ParseOptions();
parseOptions.setResolve(true);
parseOptions.setResolveFully(true);
OpenAPI openAPI = new OpenAPIV3Parser().read("issue-984-simple.yaml", null, parseOptions);
if (openAPI == null)
fail("failed parsing issue-984");
try {
Json.pretty(openAPI);
// System.out.println(Json.pretty(openAPI));
} catch (Exception e) {
e.printStackTrace();
fail("Recursive loop found");
}
}
use of io.swagger.v3.parser.OpenAPIV3Parser in project swagger-parser by swagger-api.
the class OpenAPIResolverTest method resolveComposedSchema.
@Test
public void resolveComposedSchema(@Injectable final List<AuthorizationValue> auths) {
ParseOptions options = new ParseOptions();
options.setResolveCombinators(false);
options.setResolveFully(true);
OpenAPI openAPI = new OpenAPIV3Parser().readLocation("src/test/resources/oneof-anyof.yaml", auths, options).getOpenAPI();
assertTrue(openAPI.getPaths().get("/mixed-array").getGet().getResponses().get("200").getContent().get("application/json").getSchema() instanceof ArraySchema);
ArraySchema arraySchema = (ArraySchema) openAPI.getPaths().get("/mixed-array").getGet().getResponses().get("200").getContent().get("application/json").getSchema();
assertTrue(arraySchema.getItems() instanceof ComposedSchema);
ComposedSchema oneOf = (ComposedSchema) arraySchema.getItems();
assertEquals(oneOf.getOneOf().get(0).getType(), "string");
// System.out.println(openAPI.getPaths().get("/oneOf").getGet().getResponses().get("200").getContent().get("application/json").getSchema() );
assertTrue(openAPI.getPaths().get("/oneOf").getGet().getResponses().get("200").getContent().get("application/json").getSchema() instanceof ComposedSchema);
ComposedSchema oneOfSchema = (ComposedSchema) openAPI.getPaths().get("/oneOf").getGet().getResponses().get("200").getContent().get("application/json").getSchema();
assertEquals(oneOfSchema.getOneOf().get(0).getType(), "object");
}
use of io.swagger.v3.parser.OpenAPIV3Parser in project swagger-parser by swagger-api.
the class OpenAPIResolverTest method testIssue1157.
@Test
public void testIssue1157(@Injectable final List<AuthorizationValue> auths) {
ParseOptions options = new ParseOptions();
options.setResolve(true);
options.setResolveFully(true);
OpenAPI openAPIAnyOf = new OpenAPIV3Parser().readLocation("/issue-1157/anyOf-example.yaml", auths, options).getOpenAPI();
Schema petSchemaAnyOf = openAPIAnyOf.getComponents().getSchemas().get("Pet");
assertTrue(petSchemaAnyOf instanceof ComposedSchema);
assertTrue(((ComposedSchema) petSchemaAnyOf).getAnyOf() != null);
OpenAPI openAPIOneOf = new OpenAPIV3Parser().readLocation("/issue-1157/oneOf-example.yaml", auths, options).getOpenAPI();
Schema petSchemaOneOf = openAPIOneOf.getComponents().getSchemas().get("Pet");
assertTrue(petSchemaOneOf instanceof ComposedSchema);
assertTrue(((ComposedSchema) petSchemaOneOf).getOneOf() != null);
OpenAPI openAPIAllOf = new OpenAPIV3Parser().readLocation("/issue-1157/allOf-example.yaml", auths, options).getOpenAPI();
Schema petSchemaAllOf = openAPIAllOf.getComponents().getSchemas().get("Pet");
assertFalse(petSchemaAllOf instanceof ComposedSchema);
assertTrue(petSchemaAllOf.getProperties() != null);
}
use of io.swagger.v3.parser.OpenAPIV3Parser in project swagger-parser by swagger-api.
the class FileReferenceTest method testIssue340.
@Test
public void testIssue340() {
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult result = new OpenAPIV3Parser().readLocation("./src/test/resources/nested-file-references/issue-340.json", null, options);
assertNotNull(result.getOpenAPI());
OpenAPI swagger = result.getOpenAPI();
assertFalse(swagger.getComponents().getSchemas().get("BarData").get$ref() != null);
}
Aggregations