use of io.swagger.v3.jaxrs2.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.jaxrs2.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;
}
use of io.swagger.v3.jaxrs2.resources.model.Pet in project swagger-core by swagger-api.
the class PetData method findPetByTags.
public List<Pet> findPetByTags(String tags) {
String[] tagList = tags.split(",");
List<Pet> result = new ArrayList<Pet>();
for (Pet pet : pets) {
if (null != pet.getTags()) {
for (Tag tag : pet.getTags()) {
for (String tagListString : tagList) {
if (tagListString.equals(tag.getName())) {
result.add(pet);
}
}
}
}
}
return result;
}
use of io.swagger.v3.jaxrs2.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;
}
use of io.swagger.v3.jaxrs2.resources.model.Pet in project swagger-core by swagger-api.
the class PetData method findPetByStatus.
public List<Pet> findPetByStatus(String status) {
String[] statues = status.split(",");
List<Pet> result = new ArrayList<Pet>();
for (Pet pet : pets) {
for (String s : statues) {
if (s.equals(pet.getStatus())) {
result.add(pet);
}
}
}
return result;
}
Aggregations