use of io.swagger.v3.jaxrs2.resources.model.Pet in project swagger-parser by swagger-api.
the class FileReferenceTest method testRelativeRefIssue421.
@Test
public void testRelativeRefIssue421() {
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult result = new OpenAPIV3Parser().readLocation("./src/test/resources/main.yaml", null, options);
assertNotNull(result.getOpenAPI());
OpenAPI swagger = result.getOpenAPI();
assertNotNull(swagger);
assertNotNull(swagger.getPaths().get("pets"));
assertNotNull(swagger.getPaths().get("pets").getGet());
assertNotNull(swagger.getPaths().get("pets").getGet().getResponses());
assertNotNull(swagger.getPaths().get("pets").getGet().getResponses().get("200"));
assertNotNull(swagger.getPaths().get("pets").getGet().getResponses().get("200").getContent().get("*/*").getSchema());
assertTrue(swagger.getPaths().get("pets").getGet().getResponses().get("200").getContent().get("*/*").getSchema().get$ref() != null);
assertEquals(swagger.getPaths().get("pets").getGet().getResponses().get("200").getContent().get("*/*").getSchema().get$ref(), "#/components/schemas/Pet");
assertTrue(swagger.getComponents().getSchemas().get("Pet") instanceof Schema);
assertTrue(swagger.getComponents().getSchemas().get("Pet").getProperties().size() == 2);
}
use of io.swagger.v3.jaxrs2.resources.model.Pet in project swagger-parser by swagger-api.
the class FileReferenceTest method testIssue421.
@Test
public void testIssue421() {
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult result = new OpenAPIV3Parser().readLocation("./src/test/resources/nested-file-references/issue-421.yaml", null, options);
assertNotNull(result.getOpenAPI());
OpenAPI swagger = result.getOpenAPI();
assertNotNull(swagger.getPaths().get("/pet/{petId}"));
assertNotNull(swagger.getPaths().get("/pet/{petId}").getGet());
assertNotNull(swagger.getPaths().get("/pet/{petId}").getGet().getParameters());
assertTrue(swagger.getPaths().get("/pet/{petId}").getGet().getParameters().size() == 1);
assertTrue(swagger.getPaths().get("/pet/{petId}").getGet().getParameters().get(0).getName().equals("petId"));
assertTrue(swagger.getComponents().getSchemas().get("Pet") instanceof Schema);
assertTrue(swagger.getComponents().getSchemas().get("Pet").getProperties().size() == 6);
assertNotNull(swagger.getPaths().get("/pet/{petId}").getPost());
assertNotNull(swagger.getPaths().get("/pet/{petId}").getPost().getParameters());
assertTrue(swagger.getPaths().get("/pet/{petId}").getPost().getParameters().size() == 1);
assertTrue(swagger.getPaths().get("/pet/{petId}").getPost().getRequestBody() != null);
assertTrue(swagger.getPaths().get("/pet/{petId}").getPost().getRequestBody().get$ref() != null);
assertEquals(swagger.getPaths().get("/pet/{petId}").getPost().getRequestBody().get$ref(), "#/components/requestBodies/requestBody");
assertTrue(swagger.getPaths().get("/pet/{petId}").getPost().getRequestBody().get$ref().equals("#/components/requestBodies/requestBody"));
assertNotNull(swagger.getPaths().get("/store/order"));
assertNotNull(swagger.getPaths().get("/store/order").getPost());
assertNotNull(swagger.getPaths().get("/store/order").getPost().getRequestBody());
assertNotNull(swagger.getPaths().get("/store/order").getPost().getRequestBody().getContent().get("application/json").getSchema());
assertTrue(swagger.getPaths().get("/store/order").getPost().getRequestBody().getContent().get("application/json").getSchema().get$ref() != null);
assertTrue(swagger.getPaths().get("/store/order").getPost().getRequestBody().getContent().get("application/json").getSchema().get$ref().equals("#/components/schemas/Order"));
assertTrue(swagger.getComponents().getSchemas().get("Order") instanceof Schema);
assertTrue(swagger.getComponents().getSchemas().get("Order").getProperties().size() == 6);
}
use of io.swagger.v3.jaxrs2.resources.model.Pet 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.jaxrs2.resources.model.Pet in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method testOneOfSchema.
@Test
public void testOneOfSchema(@Injectable List<AuthorizationValue> auths) {
String yaml = "openapi: '3.0'\n" + "components:\n" + " schemas:\n" + " Cat:\n" + " type: object\n" + " # all properties specific to a `Cat`\n" + " properties:\n" + " purring:\n" + " type: string\n" + " Dog:\n" + " type: object\n" + " # all properties specific to a `Dog`\n" + " properties:\n" + " bark:\n" + " type: string\n" + " Pet:\n" + " oneOf: \n" + " - $ref: '#/components/schemas/Cat'\n" + " - $ref: '#/components/schemas/Dog'\n" + " - type: object\n" + " # neither a `Cat` nor a `Dog`\n" + " properties:\n" + " name:\n" + " type: string\n";
OpenAPIV3Parser parser = new OpenAPIV3Parser();
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult result = parser.readContents(yaml, auths, options);
List<String> messageList = result.getMessages();
Set<String> messages = new HashSet<>(messageList);
Schema petSchema = result.getOpenAPI().getComponents().getSchemas().get("Pet");
assertTrue(petSchema != null);
assertTrue(petSchema instanceof ComposedSchema);
ComposedSchema petCompSchema = (ComposedSchema) petSchema;
List<Schema> oneOfSchemas = petCompSchema.getOneOf();
assertTrue(oneOfSchemas != null);
assertEquals(oneOfSchemas.size(), 3);
Schema refCatSchema = oneOfSchemas.get(0);
assertTrue(refCatSchema != null);
assertEquals(refCatSchema.get$ref(), "#/components/schemas/Cat");
Schema refDogSchema = oneOfSchemas.get(1);
assertTrue(refDogSchema != null);
assertEquals(refDogSchema.get$ref(), "#/components/schemas/Dog");
Schema otherSchema = oneOfSchemas.get(2);
assertTrue(otherSchema != null);
Schema nameProp = (Schema) otherSchema.getProperties().get("name");
assertTrue(nameProp != null);
assertEquals(nameProp.getType(), "string");
}
use of io.swagger.v3.jaxrs2.resources.model.Pet in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method testIssue204_allOf.
@Test
public void testIssue204_allOf() throws Exception {
String yaml = "openapi: 3.0.0\n" + "servers: []\n" + "info:\n" + " version: 2.0.0\n" + " title: Test allOf API\n" + " description: 'Tests the allOf API for parent, interface and child models.'\n" + "paths:\n" + " /:\n" + " get:\n" + " responses:\n" + " '200':\n" + " description: OK\n" + "components:\n" + " schemas:\n" + " Pet:\n" + " type: object\n" + " required:\n" + " - id\n" + " properties:\n" + " id:\n" + " type: integer\n" + " format: int64\n" + " Furry:\n" + " type: object\n" + " required:\n" + " - coatColour\n" + " properties:\n" + " coatColour:\n" + " type: string\n" + " Dog:\n" + " type: object\n" + " allOf:\n" + " - $ref: '#/components/schemas/Pet'\n" + " - $ref: '#/components/schemas/Furry'\n" + " - required:\n" + " - name\n" + " properties:\n" + " name:\n" + " type: string";
OpenAPIV3Parser parser = new OpenAPIV3Parser();
SwaggerParseResult result = parser.readContents(yaml, null, null);
assertTrue(result.getMessages().isEmpty());
OpenAPI openAPI = result.getOpenAPI();
assertNotNull(openAPI);
Map<String, Schema> definitions = openAPI.getComponents().getSchemas();
assertNotNull(definitions);
assertEquals(3, definitions.size());
Schema pet = definitions.get("Pet");
Schema furry = definitions.get("Furry");
Schema dog = definitions.get("Dog");
assertNotNull(pet);
assertNotNull(furry);
assertNotNull(dog);
assertTrue(dog instanceof ComposedSchema);
ComposedSchema dogComposed = (ComposedSchema) dog;
assertNotNull(dogComposed.getAllOf());
assertEquals(3, dogComposed.getAllOf().size());
Schema dogInterfaceRef = dogComposed.getAllOf().get(0);
Schema dogInterface = definitions.get(dogInterfaceRef.get$ref());
dogInterfaceRef = dogComposed.getAllOf().get(1);
dogInterface = definitions.get(dogInterfaceRef.get$ref());
assertTrue(dogComposed.getAllOf().get(0).get$ref() != null);
}
Aggregations