use of io.swagger.v3.jaxrs2.resources.model.Pet in project swagger-core by swagger-api.
the class OpenAPI3_1DeserializationTest method testDeserializationOnOAS31.
@Test
public void testDeserializationOnOAS31() throws IOException {
final String jsonString = ResourceUtils.loadClassResource(getClass(), "specFiles/3.1.0/petstore-3.1_sample.yaml");
OpenAPI openAPI = Yaml31.mapper().readValue(jsonString, OpenAPI.class);
assertNotNull(openAPI);
assertEquals(openAPI.getInfo().getTitle(), "Swagger Petstore");
assertEquals(openAPI.getInfo().getVersion(), "1.0.0");
assertEquals(openAPI.getInfo().getSummary(), "petstore sample for OAS 3.1.0");
assertEquals(openAPI.getInfo().getLicense().getName(), "MIT");
assertEquals(openAPI.getInfo().getLicense().getIdentifier(), "test");
assertNotNull(openAPI.getWebhooks());
assertFalse(openAPI.getWebhooks().isEmpty());
assertNotNull(openAPI.getWebhooks().get("newPet"));
assertNotNull(openAPI.getWebhooks().get("newPet").getPost());
assertNotNull(openAPI.getComponents().getPathItems());
assertNotNull(openAPI.getComponents().getPathItems().get("/pet"));
assertEquals(openAPI.getComponents().getPathItems().get("/pet").getDescription(), "get a pet");
assertNotNull(openAPI.getComponents().getPathItems().get("/pet").getGet());
assertEquals(openAPI.getComponents().getPathItems().get("/pet").getGet().getOperationId(), "getPet");
assertNotNull(openAPI.getComponents().getSchemas());
assertNotNull(openAPI.getComponents().getSchemas().get("Pet"));
assertNotNull(openAPI.getComponents().getSchemas().get("Pet").getDiscriminator());
assertNotNull(openAPI.getComponents().getSchemas().get("Pet").getDiscriminator().getExtensions());
assertEquals(openAPI.getComponents().getSchemas().get("Pet").getDiscriminator().getExtensions().get("x-test-extension"), "extended");
assertNotNull(openAPI.getComponents().getResponses());
assertNotNull(openAPI.getComponents().getResponses().get("201"));
assertEquals(openAPI.getComponents().getResponses().get("201").getDescription(), "api response description");
assertNotNull(openAPI.getComponents().getParameters());
assertNotNull(openAPI.getComponents().getParameters().get("param"));
assertEquals(openAPI.getComponents().getParameters().get("param").getIn(), "query");
assertEquals(openAPI.getComponents().getParameters().get("param").getName(), "param0");
assertEquals(openAPI.getComponents().getParameters().get("param").getDescription(), "parameter description");
assertNotNull(openAPI.getComponents().getExamples());
assertNotNull(openAPI.getComponents().getExamples().get("example"));
assertEquals(openAPI.getComponents().getExamples().get("example").getDescription(), "example description");
assertEquals(openAPI.getComponents().getExamples().get("example").getSummary(), "example summary");
assertEquals(openAPI.getComponents().getExamples().get("example").getValue(), "This is an example");
assertNotNull(openAPI.getComponents().getRequestBodies());
assertNotNull(openAPI.getComponents().getRequestBodies().get("body"));
assertNotNull(openAPI.getComponents().getHeaders());
assertNotNull(openAPI.getComponents().getHeaders().get("test-head"));
assertEquals(openAPI.getComponents().getHeaders().get("test-head").getDescription(), "test header description");
assertNotNull(openAPI.getComponents().getSecuritySchemes());
assertNotNull(openAPI.getComponents().getSecuritySchemes().get("basic"));
assertEquals(openAPI.getComponents().getSecuritySchemes().get("basic").getDescription(), "security description");
assertEquals(openAPI.getComponents().getSecuritySchemes().get("basic").getType().toString(), "http");
assertNotNull(openAPI.getComponents().getLinks());
assertNotNull(openAPI.getComponents().getLinks().get("Link"));
assertEquals(openAPI.getComponents().getLinks().get("Link").getOperationRef(), "#/paths/~12.0~1repositories~1{username}/get");
assertNotNull(openAPI.getComponents().getCallbacks());
assertNotNull(openAPI.getComponents().getCallbacks().get("TestCallback"));
openAPI = Yaml.mapper().readValue(jsonString, OpenAPI.class);
assertNotNull(openAPI);
assertNull(openAPI.getInfo().getSummary());
assertNull(openAPI.getWebhooks());
assertNull(openAPI.getComponents().getPathItems());
assertNull(openAPI.getComponents().getSchemas().get("Pet").getDiscriminator().getExtensions());
}
use of io.swagger.v3.jaxrs2.resources.model.Pet in project swagger-core by swagger-api.
the class OpenAPI3_1DeserializationTest method testDeserializationOnOAS30.
@Test
public void testDeserializationOnOAS30() throws IOException {
final String jsonString = ResourceUtils.loadClassResource(getClass(), "specFiles/3.1.0/petstore-3.1_sample.yaml");
OpenAPI openAPI = Yaml.mapper().readValue(jsonString, OpenAPI.class);
assertNotNull(openAPI);
assertEquals(openAPI.getInfo().getTitle(), "Swagger Petstore");
assertEquals(openAPI.getInfo().getVersion(), "1.0.0");
assertNull(openAPI.getInfo().getSummary());
assertEquals(openAPI.getInfo().getLicense().getName(), "MIT");
assertNull(openAPI.getInfo().getLicense().getIdentifier());
assertNull(openAPI.getWebhooks());
assertNull(openAPI.getComponents().getPathItems());
assertNotNull(openAPI.getComponents().getSchemas());
assertNotNull(openAPI.getComponents().getSchemas().get("Pet"));
assertNotNull(openAPI.getComponents().getSchemas().get("Pet").getDiscriminator());
assertNull(openAPI.getComponents().getSchemas().get("Pet").getDiscriminator().getExtensions());
assertNotNull(openAPI.getComponents().getResponses());
assertNotNull(openAPI.getComponents().getResponses().get("201"));
assertEquals(openAPI.getComponents().getResponses().get("201").getDescription(), "api response description");
assertNotNull(openAPI.getComponents().getParameters());
assertNotNull(openAPI.getComponents().getParameters().get("param"));
assertEquals(openAPI.getComponents().getParameters().get("param").getIn(), "query");
assertEquals(openAPI.getComponents().getParameters().get("param").getName(), "param0");
assertEquals(openAPI.getComponents().getParameters().get("param").getDescription(), "parameter description");
assertNotNull(openAPI.getComponents().getExamples());
assertNotNull(openAPI.getComponents().getExamples().get("example"));
assertEquals(openAPI.getComponents().getExamples().get("example").getDescription(), "example description");
assertEquals(openAPI.getComponents().getExamples().get("example").getSummary(), "example summary");
assertEquals(openAPI.getComponents().getExamples().get("example").getValue(), "This is an example");
assertNotNull(openAPI.getComponents().getRequestBodies());
assertNotNull(openAPI.getComponents().getRequestBodies().get("body"));
assertNotNull(openAPI.getComponents().getHeaders());
assertNotNull(openAPI.getComponents().getHeaders().get("test-head"));
assertEquals(openAPI.getComponents().getHeaders().get("test-head").getDescription(), "test header description");
assertNotNull(openAPI.getComponents().getSecuritySchemes());
assertNotNull(openAPI.getComponents().getSecuritySchemes().get("basic"));
assertEquals(openAPI.getComponents().getSecuritySchemes().get("basic").getDescription(), "security description");
assertEquals(openAPI.getComponents().getSecuritySchemes().get("basic").getType().toString(), "http");
assertNotNull(openAPI.getComponents().getLinks());
assertNotNull(openAPI.getComponents().getLinks().get("Link"));
assertEquals(openAPI.getComponents().getLinks().get("Link").getOperationRef(), "#/paths/~12.0~1repositories~1{username}/get");
assertNotNull(openAPI.getComponents().getCallbacks());
assertNotNull(openAPI.getComponents().getCallbacks().get("TestCallback"));
openAPI = Yaml.mapper().readValue(jsonString, OpenAPI.class);
assertNotNull(openAPI);
}
use of io.swagger.v3.jaxrs2.resources.model.Pet in project swagger-core by swagger-api.
the class SchemaDeserializationTest method deserializeRefSchema3_1.
@Test
public void deserializeRefSchema3_1() throws IOException {
final String jsonString = ResourceUtils.loadClassResource(getClass(), "specFiles/3.1.0/petstore-3.1_refs_siblings.yaml");
final OpenAPI openAPI = Yaml31.mapper().readValue(jsonString, OpenAPI.class);
assertNotNull(openAPI);
assertNotNull(openAPI.getComponents());
assertNotNull(openAPI.getComponents().getSchemas());
assertNotNull(openAPI.getComponents().getSchemas().get("AnotherPet"));
assertEquals(openAPI.getComponents().getSchemas().get("AnotherPet").get$ref(), "#/components/schemas/Pet");
assertEquals(openAPI.getComponents().getSchemas().get("AnotherPet").getTitle(), "Another Pet");
assertEquals(openAPI.getComponents().getSchemas().get("AnotherPet").getDescription(), "Another Pet for petstore referencing Pet schema");
assertNotNull(openAPI.getComponents().getSchemas().get("AnotherPet").getProperties());
assertNotNull(openAPI.getComponents().getSchemas().get("AnotherPet").getProperties().get("category"));
assertNotNull(openAPI.getComponents().getSchemas().get("AnotherPet").getProperties().get("photoUrl"));
}
use of io.swagger.v3.jaxrs2.resources.model.Pet in project swagger-core by swagger-api.
the class PatternAndSchemaPropertiesTest method testPatternAndSchemaProperties.
@Test
public void testPatternAndSchemaProperties() throws Exception {
final ModelResolver modelResolver = new ModelResolver(mapper());
ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);
Schema model = context.resolve(new AnnotatedType(AnnotatedPet.class));
assertEquals(((Schema) model.getPatternProperties().get("what.*ever")).getFormat(), "int32");
assertEquals(((Schema) model.getPatternProperties().get("it.*takes")).get$ref(), "#/components/schemas/Category");
assertEquals(((Schema) model.getProperties().get("anotherCategory")).get$ref(), "#/components/schemas/Category");
assertEquals(((Schema) model.getProperties().get("anotherInteger")).getFormat(), "int32");
SerializationMatchers.assertEqualsToYaml(context.getDefinedModels(), "AnnotatedPet:\n" + " type: object\n" + " properties:\n" + " id:\n" + " type: integer\n" + " format: int64\n" + " category:\n" + " $ref: '#/components/schemas/Category'\n" + " name:\n" + " type: string\n" + " photoUrls:\n" + " type: array\n" + " xml:\n" + " wrapped: true\n" + " items:\n" + " type: string\n" + " xml:\n" + " name: photoUrl\n" + " tags:\n" + " type: array\n" + " xml:\n" + " wrapped: true\n" + " items:\n" + " $ref: '#/components/schemas/Tag'\n" + " status:\n" + " type: string\n" + " description: pet status in the store\n" + " enum:\n" + " - available\n" + " - pending\n" + " - sold\n" + " anotherCategory:\n" + " $ref: '#/components/schemas/Category'\n" + " anotherInteger:\n" + " maximum: 10\n" + " type: integer\n" + " description: prop schema 1\n" + " format: int32\n" + " description: Annotated Pet\n" + " nullable: true\n" + "Category:\n" + " type: object\n" + " properties:\n" + " id:\n" + " type: integer\n" + " format: int64\n" + " name:\n" + " type: string\n" + " description: prop schema 2\n" + " xml:\n" + " name: Category\n" + "Tag:\n" + " type: object\n" + " properties:\n" + " id:\n" + " type: integer\n" + " format: int64\n" + " name:\n" + " type: string\n" + " xml:\n" + " name: Tag");
context.getDefinedModels().values().forEach(s -> new OpenAPISchema2JsonSchema().process(s));
SerializationMatchers.assertEqualsToYaml31(context.getDefinedModels(), "AnnotatedPet:\n" + " type:\n" + " - object\n" + " - \"null\"\n" + " properties:\n" + " id:\n" + " type: integer\n" + " format: int64\n" + " category:\n" + " $ref: '#/components/schemas/Category'\n" + " name:\n" + " type: string\n" + " photoUrls:\n" + " type: array\n" + " xml:\n" + " wrapped: true\n" + " items:\n" + " type: string\n" + " xml:\n" + " name: photoUrl\n" + " tags:\n" + " type: array\n" + " xml:\n" + " wrapped: true\n" + " items:\n" + " $ref: '#/components/schemas/Tag'\n" + " status:\n" + " type: string\n" + " description: pet status in the store\n" + " enum:\n" + " - available\n" + " - pending\n" + " - sold\n" + " anotherCategory:\n" + " $ref: '#/components/schemas/Category'\n" + " anotherInteger:\n" + " maximum: 10\n" + " type: integer\n" + " description: prop schema 1\n" + " format: int32\n" + " patternProperties:\n" + " what.*ever:\n" + " maximum: 10\n" + " type: integer\n" + " description: prop schema 1\n" + " format: int32\n" + " it.*takes:\n" + " $ref: '#/components/schemas/Category'\n" + " description: Annotated Pet\n" + "Category:\n" + " type: object\n" + " properties:\n" + " id:\n" + " type: integer\n" + " format: int64\n" + " name:\n" + " type: string\n" + " description: prop schema 2\n" + " xml:\n" + " name: Category\n" + "Tag:\n" + " type: object\n" + " properties:\n" + " id:\n" + " type: integer\n" + " format: int64\n" + " name:\n" + " type: string\n" + " xml:\n" + " name: Tag\n");
}
use of io.swagger.v3.jaxrs2.resources.model.Pet in project swagger-core by swagger-api.
the class ModelSerializerTest method convertModel.
@Test(description = "it should convert a model")
public void convertModel() throws JsonProcessingException {
final Schema pet = new Schema();
final Map<String, Schema> props = new LinkedHashMap<String, Schema>();
props.put("intValue", new IntegerSchema());
props.put("longValue", new IntegerSchema().format("int64"));
props.put("dateValue", new DateSchema());
props.put("dateTimeValue", new DateTimeSchema());
pet.setProperties(props);
pet.setRequired(Arrays.asList("intValue", "name"));
final String json = "{\n" + " \"required\":[\n" + " \"intValue\"\n" + " ],\n" + " \"properties\":{\n" + " \"intValue\":{\n" + " \"type\":\"integer\",\n" + " \"format\":\"int32\"\n" + " },\n" + " \"longValue\":{\n" + " \"type\":\"integer\",\n" + " \"format\":\"int64\"\n" + " },\n" + " \"dateValue\":{\n" + " \"type\":\"string\",\n" + " \"format\":\"date\"\n" + " },\n" + " \"dateTimeValue\":{\n" + " \"type\":\"string\",\n" + " \"format\":\"date-time\"\n" + " }\n" + " }\n" + "}";
SerializationMatchers.assertEqualsToJson(pet, json);
}
Aggregations