use of io.swagger.v3.plugin.maven.resources.model.Pet in project swagger-core by swagger-api.
the class ModelSerializerTest method deserializeArrayModel.
@Test(description = "it should deserialize an array model")
public void deserializeArrayModel() throws IOException {
final String json = "{\"type\":\"array\",\"items\":{\"$ref\":\"#/definitions/Pet\"}}";
final Schema p = m.readValue(json, Schema.class);
assertTrue(p instanceof ArraySchema);
assertEquals(m.writeValueAsString(p), json);
}
use of io.swagger.v3.plugin.maven.resources.model.Pet in project swagger-core by swagger-api.
the class SchemaSerializationTest method serializeRefSchema3_1.
@Test
public void serializeRefSchema3_1() {
OpenAPI openAPI = new OpenAPI().components(new Components().addSchemas("Pet", new Schema().addProperties("id", new Schema().type("integer")).addProperties("name", new Schema().type("string")).addProperties("tag", new Schema().type("string"))).addSchemas("AnotherPet", new Schema().title("Another Pet").description("Another Pet for petstore referencing Pet schema").$ref("#/components/schemas/Pet").addProperties("category", new Schema().type("string")).addProperties("photoUrl", new Schema().type("string"))));
SerializationMatchers.assertEqualsToYaml31(openAPI, "openapi: 3.0.1\n" + "components:\n" + " schemas:\n" + " Pet:\n" + " properties:\n" + " id: {}\n" + " name: {}\n" + " tag: {}\n" + " AnotherPet:\n" + " title: Another Pet\n" + " properties:\n" + " category: {}\n" + " photoUrl: {}\n" + " description: Another Pet for petstore referencing Pet schema\n" + " $ref: '#/components/schemas/Pet'");
SerializationMatchers.assertEqualsToYaml(openAPI, "openapi: 3.0.1\n" + "components:\n" + " schemas:\n" + " Pet:\n" + " properties:\n" + " id:\n" + " type: integer\n" + " name:\n" + " type: string\n" + " tag:\n" + " type: string\n" + " AnotherPet:\n" + " $ref: '#/components/schemas/Pet'");
}
use of io.swagger.v3.plugin.maven.resources.model.Pet in project swagger-core by swagger-api.
the class OpenAPI3_1SerializationTest method testDiscriminatorSerialization.
@Test
public void testDiscriminatorSerialization() {
Schema<String> propertySchema1 = new StringSchema();
propertySchema1.addType(propertySchema1.getType());
Schema<String> propertySchema2 = new StringSchema();
propertySchema2.addType(propertySchema2.getType());
Discriminator discriminator = new Discriminator().propertyName("type");
discriminator.addExtension("x-otherName", "discriminationType");
Schema schema = new ObjectSchema().addProperties("name", propertySchema1).addProperties("type", propertySchema1).discriminator(discriminator);
schema.addType(schema.getType());
OpenAPI openAPI = new OpenAPI().openapi("3.1.0").components(new Components().addSchemas("pet", schema));
SerializationMatchers.assertEqualsToYaml31(openAPI, "openapi: 3.1.0\n" + "components:\n" + " schemas:\n" + " pet:\n" + " properties:\n" + " name:\n" + " type: string\n" + " type:\n" + " type: string\n" + " discriminator:\n" + " propertyName: type\n" + " x-otherName: discriminationType\n" + " type: object");
SerializationMatchers.assertEqualsToJson31(openAPI, "{\n" + " \"openapi\" : \"3.1.0\",\n" + " \"components\" : {\n" + " \"schemas\" : {\n" + " \"pet\" : {\n" + " \"properties\" : {\n" + " \"name\" : {\n" + " \"type\" : \"string\"\n" + " },\n" + " \"type\" : {\n" + " \"type\" : \"string\"\n" + " }\n" + " },\n" + " \"discriminator\" : {\n" + " \"propertyName\" : \"type\",\n" + " \"x-otherName\" : \"discriminationType\"\n" + " },\n" + " \"type\" : \"object\"\n" + " }\n" + " }\n" + " }\n" + "}");
openAPI.openapi("3.0.3");
SerializationMatchers.assertEqualsToYaml(openAPI, "openapi: 3.0.3\n" + "components:\n" + " schemas:\n" + " pet:\n" + " properties:\n" + " name:\n" + " type: string\n" + " type:\n" + " type: string\n" + " discriminator:\n" + " propertyName: type\n" + " type: object");
SerializationMatchers.assertEqualsToJson(openAPI, "{\n" + " \"openapi\" : \"3.0.3\",\n" + " \"components\" : {\n" + " \"schemas\" : {\n" + " \"pet\" : {\n" + " \"properties\" : {\n" + " \"name\" : {\n" + " \"type\" : \"string\"\n" + " },\n" + " \"type\" : {\n" + " \"type\" : \"string\"\n" + " }\n" + " },\n" + " \"discriminator\" : {\n" + " \"propertyName\" : \"type\"\n" + " },\n" + " \"type\" : \"object\"\n" + " }\n" + " }\n" + " }\n" + "}");
}
use of io.swagger.v3.plugin.maven.resources.model.Pet in project swagger-core by swagger-api.
the class ReaderTest method testAnotherResourceWithSubresources.
@Test(description = "test another resource with subresources")
public void testAnotherResourceWithSubresources() {
Reader reader = new Reader(new OpenAPI());
OpenAPI openAPI = reader.read(TestResource.class);
Paths paths = openAPI.getPaths();
assertEquals(paths.size(), 3);
PathItem pathItem = paths.get("/test/status");
assertNotNull(pathItem);
Operation operation = pathItem.getGet();
assertNotNull(operation);
assertTrue(operation.getResponses().getDefault().getContent().keySet().contains("application/json"));
Schema schema = operation.getResponses().getDefault().getContent().values().iterator().next().getSchema();
assertNotNull(schema);
assertEquals(schema.getType(), "string");
pathItem = paths.get("/test/more/otherStatus");
assertNotNull(pathItem);
operation = pathItem.getGet();
assertNotNull(operation);
assertTrue(operation.getResponses().getDefault().getContent().keySet().contains("application/json"));
assertFalse(operation.getResponses().getDefault().getContent().keySet().contains("application/xml"));
schema = operation.getResponses().getDefault().getContent().values().iterator().next().getSchema();
assertNotNull(schema);
assertEquals(schema.getType(), "string");
pathItem = paths.get("/test/evenmore/otherStatus");
assertNotNull(pathItem);
operation = pathItem.getGet();
assertNotNull(operation);
assertTrue(operation.getResponses().getDefault().getContent().keySet().contains("application/json"));
assertFalse(operation.getResponses().getDefault().getContent().keySet().contains("application/xml"));
schema = operation.getResponses().getDefault().getContent().values().iterator().next().getSchema();
assertNotNull(schema);
assertEquals(schema.getType(), "string");
assertEquals(operation.getRequestBody().getContent().get("application/json").getSchema().get$ref(), "#/components/schemas/Pet");
}
use of io.swagger.v3.plugin.maven.resources.model.Pet in project swagger-core by swagger-api.
the class PetData method createPet.
static Pet createPet(long id, Category cat, String name, String[] urls, String[] tags, String status) {
Pet pet = new Pet();
pet.setId(id);
pet.setCategory(cat);
pet.setName(name);
if (null != urls) {
List<String> urlObjs = new ArrayList<String>();
for (String urlString : urls) {
urlObjs.add(urlString);
}
pet.setPhotoUrls(urlObjs);
}
List<Tag> tagObjs = new ArrayList<Tag>();
int i = 0;
if (null != tags) {
for (String tagString : tags) {
i = i + 1;
Tag tag = new Tag();
tag.setId(i);
tag.setName(tagString);
tagObjs.add(tag);
}
}
pet.setTags(tagObjs);
pet.setStatus(status);
return pet;
}
Aggregations