use of io.swagger.v3.jaxrs2.resources.model.Pet in project swagger-parser by swagger-api.
the class FileReferenceTest method testAllOfFlatAndNested.
@Test
public void testAllOfFlatAndNested() {
for (String path : Arrays.asList("./src/test/resources/allOf-properties-ext-ref/models/swagger.json", "./src/test/resources/allOf-properties-ext-ref/swagger.json")) {
OpenAPI swagger = new OpenAPIV3Parser().read(path);
assertEquals(3, swagger.getComponents().getSchemas().size());
ComposedSchema composedModel = (ComposedSchema) swagger.getComponents().getSchemas().get("record");
assertEquals(composedModel.getAllOf().get(0).get$ref(), "#/components/schemas/pet");
Map<String, Schema> props = composedModel.getAllOf().get(1).getProperties();
assertEquals(props.get("mother").get$ref(), "#/components/schemas/pet");
assertEquals(((ArraySchema) props.get("siblings")).getItems().get$ref(), "#/components/schemas/pet");
}
}
use of io.swagger.v3.jaxrs2.resources.model.Pet in project swagger-parser by swagger-api.
the class OpenAPIResolverTest method pathsResolver.
@Test
public void pathsResolver() throws Exception {
final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
String pathFile = FileUtils.readFileToString(new File("src/test/resources/oas3.yaml.template"));
pathFile = pathFile.replace("${dynamicPort}", String.valueOf(this.serverPort));
final JsonNode rootNode = mapper.readTree(pathFile.getBytes());
final OpenAPIDeserializer deserializer = new OpenAPIDeserializer();
final SwaggerParseResult result = deserializer.deserialize(rootNode);
Assert.assertNotNull(result);
final OpenAPI openAPI = result.getOpenAPI();
Assert.assertNotNull(openAPI);
assertEquals(new OpenAPIResolver(openAPI, new ArrayList<>(), null).resolve(), openAPI);
// internal url pathItem
assertEquals(openAPI.getPaths().get("/pathItemRef2"), openAPI.getPaths().get("/pet"));
// internal array schema inside operation -> responses -> content
ArraySchema schema = (ArraySchema) openAPI.getPaths().get("/pet").getPut().getResponses().get("400").getContent().get("application/json").getSchema();
assertEquals(schema.getItems().get$ref(), "#/components/schemas/VeryComplexType");
// replace of parameters in operation and remove the ones from the pathItem
Assert.assertNotNull(openAPI.getPaths().get("/pet").getPost().getParameters());
Assert.assertNull(openAPI.getPaths().get("/pet").getParameters());
// remote ref pathItem
assertEquals(openAPI.getPaths().get("/pathItemRef").getSummary(), "summary");
assertEquals(openAPI.getPaths().get("/pathItemRef").getPost().getResponses().get("405").getDescription(), "Invalid input");
// internal pathItem operation -> response -> schema
Assert.assertNotNull(openAPI.getPaths().get("/pet/{petId}").getGet().getResponses());
assertEquals(openAPI.getPaths().get("/pet/{petId}").getGet().getResponses().get("200").getContent().get("application/xml").getSchema().get$ref(), "#/components/schemas/Pet");
// internal pathItem -> operation -> callback -> pathItem -> operation -> response -> schema
assertEquals(openAPI.getPaths().get("/pet/{petId}").getGet().getCallbacks().get("mainHook").get("$request.body#/url").getPost().getResponses().get("200").getContent().get("application/xml").getSchema().get$ref(), "#/components/schemas/Pet");
// internal pathItem -> operation -> requestBody
Schema id = (Schema) openAPI.getPaths().get("/pet/findByStatus").getGet().getRequestBody().getContent().get("multipart/mixed").getSchema().getProperties().get("id");
assertEquals(id.get$ref(), "#/components/schemas/Pet");
// internal parameter url
assertEquals(openAPI.getPaths().get("/store/inventory").getGet().getParameters().get(0), openAPI.getComponents().getParameters().get("limitParam"));
}
use of io.swagger.v3.jaxrs2.resources.model.Pet in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testIssue360.
@Test
public void testIssue360() {
OpenAPIV3Parser parser = new OpenAPIV3Parser();
final OpenAPI openAPI = parser.read("src/test/resources/issue_360.yaml");
assertNotNull(openAPI);
RequestBody body = openAPI.getPaths().get("/pets").getPost().getRequestBody();
assertNotNull(body);
assertNotNull(body.getContent().get("application/json").getSchema());
Schema model = body.getContent().get("application/json").getSchema();
assertNotNull(model.getProperties().get("foo"));
Map<String, Object> extensions = body.getExtensions();
assertNotNull(extensions);
assertNotNull(extensions.get("x-examples"));
Object o = extensions.get("x-examples");
assertTrue(o instanceof Map);
Map<String, Object> on = (Map<String, Object>) o;
Object jn = on.get("application/json");
assertTrue(jn instanceof Map);
Map<String, Object> objectNode = (Map<String, Object>) jn;
assertEquals(objectNode.get("foo"), "bar");
RequestBody stringBodyParameter = openAPI.getPaths().get("/otherPets").getPost().getRequestBody();
assertTrue(stringBodyParameter.getRequired());
Schema sbpModel = stringBodyParameter.getContent().get("application/json").getSchema();
assertEquals(sbpModel.getType(), "string");
assertEquals(sbpModel.getFormat(), "uuid");
RequestBody bodyParameter = openAPI.getPaths().get("/evenMorePets").getPost().getRequestBody();
assertTrue(bodyParameter.getRequired());
Schema refModel = bodyParameter.getContent().get("application/json").getSchema();
assertTrue(refModel.get$ref() != null);
assertEquals(refModel.get$ref(), "#/components/schemas/Pet");
}
use of io.swagger.v3.jaxrs2.resources.model.Pet in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testPetstore.
@Test
public void testPetstore() throws Exception {
OpenAPIV3Parser parser = new OpenAPIV3Parser();
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult result = parser.readLocation("src/test/resources/petstore.yaml", null, options);
assertNotNull(result);
assertTrue(result.getMessages().size() == 2);
OpenAPI openAPI = result.getOpenAPI();
Map<String, Schema> definitions = openAPI.getComponents().getSchemas();
Set<String> expectedDefinitions = new HashSet<String>();
expectedDefinitions.add("User");
expectedDefinitions.add("Category");
expectedDefinitions.add("Pet");
expectedDefinitions.add("Tag");
expectedDefinitions.add("Order");
expectedDefinitions.add("PetArray");
assertEquals(definitions.keySet(), expectedDefinitions);
Schema petModel = definitions.get("Pet");
Set<String> expectedPetProps = new HashSet<String>();
expectedPetProps.add("id");
expectedPetProps.add("category");
expectedPetProps.add("name");
expectedPetProps.add("photoUrls");
expectedPetProps.add("tags");
expectedPetProps.add("status");
assertEquals(petModel.getProperties().keySet(), expectedPetProps);
ArraySchema petArrayModel = (ArraySchema) definitions.get("PetArray");
assertEquals(petArrayModel.getType(), "array");
Schema refProp = petArrayModel.getItems();
assertEquals(refProp.get$ref(), "#/components/schemas/Pet");
assertNull(petArrayModel.getProperties());
}
use of io.swagger.v3.jaxrs2.resources.model.Pet in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testRelativePath2.
@Test
public void testRelativePath2() {
OpenAPIV3Parser parser = new OpenAPIV3Parser();
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult readResult = parser.readLocation("src/test/resources/codegen-remote-responses/openapi.yaml", null, options);
Assert.assertEquals(readResult.getOpenAPI().getPaths().get("/pet/findByTags").getGet().getResponses().get("default").getContent().get("application/json").getSchema().get$ref(), "#/components/schemas/ErrorModel");
}
Aggregations