mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-08 03:18:53 +00:00
Merge pull request #2297 from xhh/object-without-properties
Do not generate models for "object" type with no properties
This commit is contained in:
commit
1f2026576f
@ -48,12 +48,13 @@ public class InlineModelResolver {
|
||||
if(model instanceof ModelImpl) {
|
||||
ModelImpl obj = (ModelImpl) model;
|
||||
if (obj.getType() == null || "object".equals(obj.getType())) {
|
||||
String modelName = uniqueName(bp.getName());
|
||||
flattenProperties(obj.getProperties(), pathname);
|
||||
|
||||
bp.setSchema(new RefModel(modelName));
|
||||
addGenerated(modelName, model);
|
||||
swagger.addDefinition(modelName, model);
|
||||
if (obj.getProperties() != null && obj.getProperties().size() > 0) {
|
||||
flattenProperties(obj.getProperties(), pathname);
|
||||
String modelName = uniqueName(bp.getName());
|
||||
bp.setSchema(new RefModel(modelName));
|
||||
addGenerated(modelName, model);
|
||||
swagger.addDefinition(modelName, model);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (model instanceof ArrayModel) {
|
||||
@ -61,18 +62,19 @@ public class InlineModelResolver {
|
||||
Property inner = am.getItems();
|
||||
|
||||
if(inner instanceof ObjectProperty) {
|
||||
String modelName = uniqueName(bp.getName());
|
||||
ObjectProperty op = (ObjectProperty) inner;
|
||||
flattenProperties(op.getProperties(), pathname);
|
||||
|
||||
Model innerModel = modelFromProperty(op, modelName);
|
||||
String existing = matchGenerated(innerModel);
|
||||
if (existing != null) {
|
||||
am.setItems(new RefProperty(existing));
|
||||
} else {
|
||||
am.setItems(new RefProperty(modelName));
|
||||
addGenerated(modelName, innerModel);
|
||||
swagger.addDefinition(modelName, innerModel);
|
||||
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
||||
flattenProperties(op.getProperties(), pathname);
|
||||
String modelName = uniqueName(bp.getName());
|
||||
Model innerModel = modelFromProperty(op, modelName);
|
||||
String existing = matchGenerated(innerModel);
|
||||
if (existing != null) {
|
||||
am.setItems(new RefProperty(existing));
|
||||
} else {
|
||||
am.setItems(new RefProperty(modelName));
|
||||
addGenerated(modelName, innerModel);
|
||||
swagger.addDefinition(modelName, innerModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -87,34 +89,37 @@ public class InlineModelResolver {
|
||||
if (response.getSchema() != null) {
|
||||
Property property = response.getSchema();
|
||||
if (property instanceof ObjectProperty) {
|
||||
String modelName = uniqueName("inline_response_" + key);
|
||||
ObjectProperty op = (ObjectProperty) property;
|
||||
Model model = modelFromProperty(op, modelName);
|
||||
String existing = matchGenerated(model);
|
||||
if (existing != null) {
|
||||
response.setSchema(new RefProperty(existing));
|
||||
} else {
|
||||
response.setSchema(new RefProperty(modelName));
|
||||
addGenerated(modelName, model);
|
||||
swagger.addDefinition(modelName, model);
|
||||
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
||||
String modelName = uniqueName("inline_response_" + key);
|
||||
Model model = modelFromProperty(op, modelName);
|
||||
String existing = matchGenerated(model);
|
||||
if (existing != null) {
|
||||
response.setSchema(new RefProperty(existing));
|
||||
} else {
|
||||
response.setSchema(new RefProperty(modelName));
|
||||
addGenerated(modelName, model);
|
||||
swagger.addDefinition(modelName, model);
|
||||
}
|
||||
}
|
||||
} else if (property instanceof ArrayProperty) {
|
||||
ArrayProperty ap = (ArrayProperty) property;
|
||||
Property inner = ap.getItems();
|
||||
|
||||
if(inner instanceof ObjectProperty) {
|
||||
String modelName = uniqueName("inline_response_" + key);
|
||||
ObjectProperty op = (ObjectProperty) inner;
|
||||
flattenProperties(op.getProperties(), pathname);
|
||||
|
||||
Model innerModel = modelFromProperty(op, modelName);
|
||||
String existing = matchGenerated(innerModel);
|
||||
if (existing != null) {
|
||||
ap.setItems(new RefProperty(existing));
|
||||
} else {
|
||||
ap.setItems(new RefProperty(modelName));
|
||||
addGenerated(modelName, innerModel);
|
||||
swagger.addDefinition(modelName, innerModel);
|
||||
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
||||
flattenProperties(op.getProperties(), pathname);
|
||||
String modelName = uniqueName("inline_response_" + key);
|
||||
Model innerModel = modelFromProperty(op, modelName);
|
||||
String existing = matchGenerated(innerModel);
|
||||
if (existing != null) {
|
||||
ap.setItems(new RefProperty(existing));
|
||||
} else {
|
||||
ap.setItems(new RefProperty(modelName));
|
||||
addGenerated(modelName, innerModel);
|
||||
swagger.addDefinition(modelName, innerModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (property instanceof MapProperty) {
|
||||
@ -122,18 +127,19 @@ public class InlineModelResolver {
|
||||
|
||||
Property innerProperty = mp.getAdditionalProperties();
|
||||
if(innerProperty instanceof ObjectProperty) {
|
||||
String modelName = uniqueName("inline_response_" + key);
|
||||
ObjectProperty op = (ObjectProperty) innerProperty;
|
||||
flattenProperties(op.getProperties(), pathname);
|
||||
|
||||
Model innerModel = modelFromProperty(op, modelName);
|
||||
String existing = matchGenerated(innerModel);
|
||||
if (existing != null) {
|
||||
mp.setAdditionalProperties(new RefProperty(existing));
|
||||
} else {
|
||||
mp.setAdditionalProperties(new RefProperty(modelName));
|
||||
addGenerated(modelName, innerModel);
|
||||
swagger.addDefinition(modelName, innerModel);
|
||||
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
||||
flattenProperties(op.getProperties(), pathname);
|
||||
String modelName = uniqueName("inline_response_" + key);
|
||||
Model innerModel = modelFromProperty(op, modelName);
|
||||
String existing = matchGenerated(innerModel);
|
||||
if (existing != null) {
|
||||
mp.setAdditionalProperties(new RefProperty(existing));
|
||||
} else {
|
||||
mp.setAdditionalProperties(new RefProperty(modelName));
|
||||
addGenerated(modelName, innerModel);
|
||||
swagger.addDefinition(modelName, innerModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -159,19 +165,21 @@ public class InlineModelResolver {
|
||||
ArrayModel m = (ArrayModel) model;
|
||||
Property inner = m.getItems();
|
||||
if (inner instanceof ObjectProperty) {
|
||||
String innerModelName = uniqueName(modelName + "_inner");
|
||||
Model innerModel = modelFromProperty((ObjectProperty) inner, modelName);
|
||||
|
||||
String existing = matchGenerated(innerModel);
|
||||
if (existing == null) {
|
||||
swagger.addDefinition(innerModelName, innerModel);
|
||||
addGenerated(innerModelName, innerModel);
|
||||
m.setItems(new RefProperty(innerModelName));
|
||||
} else {
|
||||
m.setItems(new RefProperty(existing));
|
||||
ObjectProperty op = (ObjectProperty) inner;
|
||||
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
||||
String innerModelName = uniqueName(modelName + "_inner");
|
||||
Model innerModel = modelFromProperty(op, innerModelName);
|
||||
String existing = matchGenerated(innerModel);
|
||||
if (existing == null) {
|
||||
swagger.addDefinition(innerModelName, innerModel);
|
||||
addGenerated(innerModelName, innerModel);
|
||||
m.setItems(new RefProperty(innerModelName));
|
||||
} else {
|
||||
m.setItems(new RefProperty(existing));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -218,12 +226,9 @@ public class InlineModelResolver {
|
||||
Map<String, Model> modelsToAdd = new HashMap<String, Model>();
|
||||
for (String key : properties.keySet()) {
|
||||
Property property = properties.get(key);
|
||||
if(property instanceof ObjectProperty && ((ObjectProperty)property).getProperties() == null) {
|
||||
MapProperty mp = new MapProperty();
|
||||
mp.setAdditionalProperties(new StringProperty());
|
||||
properties.put(key, mp);
|
||||
}
|
||||
else if (property instanceof ObjectProperty && ((ObjectProperty)property).getProperties().size() > 0) {
|
||||
if (property instanceof ObjectProperty &&
|
||||
((ObjectProperty)property).getProperties() != null &&
|
||||
((ObjectProperty)property).getProperties().size() > 0) {
|
||||
String modelName = uniqueName(path + "_" + key);
|
||||
|
||||
ObjectProperty op = (ObjectProperty) property;
|
||||
@ -244,20 +249,19 @@ public class InlineModelResolver {
|
||||
Property inner = ap.getItems();
|
||||
|
||||
if (inner instanceof ObjectProperty) {
|
||||
String modelName = uniqueName(path + "_" + key);
|
||||
|
||||
ObjectProperty op = (ObjectProperty) inner;
|
||||
flattenProperties(op.getProperties(), path);
|
||||
|
||||
Model innerModel = modelFromProperty(op, modelName);
|
||||
String existing = matchGenerated(innerModel);
|
||||
|
||||
if (existing != null) {
|
||||
ap.setItems(new RefProperty(existing));
|
||||
} else {
|
||||
ap.setItems(new RefProperty(modelName));
|
||||
addGenerated(modelName, innerModel);
|
||||
swagger.addDefinition(modelName, innerModel);
|
||||
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
||||
flattenProperties(op.getProperties(), path);
|
||||
String modelName = uniqueName(path + "_" + key);
|
||||
Model innerModel = modelFromProperty(op, modelName);
|
||||
String existing = matchGenerated(innerModel);
|
||||
if (existing != null) {
|
||||
ap.setItems(new RefProperty(existing));
|
||||
} else {
|
||||
ap.setItems(new RefProperty(modelName));
|
||||
addGenerated(modelName, innerModel);
|
||||
swagger.addDefinition(modelName, innerModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (property instanceof MapProperty) {
|
||||
@ -265,20 +269,19 @@ public class InlineModelResolver {
|
||||
Property inner = mp.getAdditionalProperties();
|
||||
|
||||
if (inner instanceof ObjectProperty) {
|
||||
String modelName = uniqueName(path + "_" + key);
|
||||
|
||||
ObjectProperty op = (ObjectProperty) inner;
|
||||
flattenProperties(op.getProperties(), path);
|
||||
|
||||
Model innerModel = modelFromProperty(op, modelName);
|
||||
String existing = matchGenerated(innerModel);
|
||||
|
||||
if (existing != null) {
|
||||
mp.setAdditionalProperties(new RefProperty(existing));
|
||||
} else {
|
||||
mp.setAdditionalProperties(new RefProperty(modelName));
|
||||
addGenerated(modelName, innerModel);
|
||||
swagger.addDefinition(modelName, innerModel);
|
||||
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
||||
flattenProperties(op.getProperties(), path);
|
||||
String modelName = uniqueName(path + "_" + key);
|
||||
Model innerModel = modelFromProperty(op, modelName);
|
||||
String existing = matchGenerated(innerModel);
|
||||
if (existing != null) {
|
||||
mp.setAdditionalProperties(new RefProperty(existing));
|
||||
} else {
|
||||
mp.setAdditionalProperties(new RefProperty(modelName));
|
||||
addGenerated(modelName, innerModel);
|
||||
swagger.addDefinition(modelName, innerModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -179,7 +179,7 @@ public class InlineModelResolverTest {
|
||||
assertTrue(inner instanceof RefProperty);
|
||||
|
||||
RefProperty rp = (RefProperty) inner;
|
||||
|
||||
|
||||
assertEquals(rp.getType(), "ref");
|
||||
assertEquals(rp.get$ref(), "#/definitions/body");
|
||||
assertEquals(rp.getSimpleRef(), "body");
|
||||
@ -349,4 +349,287 @@ public class InlineModelResolverTest {
|
||||
|
||||
Json.prettyPrint(swagger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArbitraryObjectBodyParam() {
|
||||
Swagger swagger = new Swagger();
|
||||
|
||||
swagger.path("/hello", new Path()
|
||||
.get(new Operation()
|
||||
.parameter(new BodyParameter()
|
||||
.name("body")
|
||||
.schema(new ModelImpl()))));
|
||||
|
||||
new InlineModelResolver().flatten(swagger);
|
||||
|
||||
Operation operation = swagger.getPaths().get("/hello").getGet();
|
||||
BodyParameter bp = (BodyParameter)operation.getParameters().get(0);
|
||||
assertTrue(bp.getSchema() instanceof ModelImpl);
|
||||
ModelImpl m = (ModelImpl) bp.getSchema();
|
||||
assertNull(m.getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArbitraryObjectBodyParamInline() {
|
||||
Swagger swagger = new Swagger();
|
||||
|
||||
swagger.path("/hello", new Path()
|
||||
.get(new Operation()
|
||||
.parameter(new BodyParameter()
|
||||
.name("body")
|
||||
.schema(new ModelImpl()
|
||||
.property("arbitrary", new ObjectProperty())))));
|
||||
|
||||
new InlineModelResolver().flatten(swagger);
|
||||
|
||||
Operation operation = swagger.getPaths().get("/hello").getGet();
|
||||
BodyParameter bp = (BodyParameter)operation.getParameters().get(0);
|
||||
assertTrue(bp.getSchema() instanceof RefModel);
|
||||
|
||||
Model body = swagger.getDefinitions().get("body");
|
||||
assertTrue(body instanceof ModelImpl);
|
||||
|
||||
ModelImpl impl = (ModelImpl) body;
|
||||
Property p = impl.getProperties().get("arbitrary");
|
||||
assertNotNull(p);
|
||||
assertTrue(p instanceof ObjectProperty);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArbitraryObjectBodyParamWithArray() {
|
||||
Swagger swagger = new Swagger();
|
||||
|
||||
swagger.path("/hello", new Path()
|
||||
.get(new Operation()
|
||||
.parameter(new BodyParameter()
|
||||
.name("body")
|
||||
.schema(new ArrayModel()
|
||||
.items(new ObjectProperty())))));
|
||||
|
||||
new InlineModelResolver().flatten(swagger);
|
||||
|
||||
Parameter param = swagger.getPaths().get("/hello").getGet().getParameters().get(0);
|
||||
assertTrue(param instanceof BodyParameter);
|
||||
|
||||
BodyParameter bp = (BodyParameter) param;
|
||||
Model schema = bp.getSchema();
|
||||
|
||||
assertTrue(schema instanceof ArrayModel);
|
||||
|
||||
ArrayModel am = (ArrayModel) schema;
|
||||
Property inner = am.getItems();
|
||||
assertTrue(inner instanceof ObjectProperty);
|
||||
|
||||
ObjectProperty op = (ObjectProperty) inner;
|
||||
assertNotNull(op);
|
||||
assertNull(op.getProperties());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArbitraryObjectBodyParamArrayInline() {
|
||||
Swagger swagger = new Swagger();
|
||||
|
||||
swagger.path("/hello", new Path()
|
||||
.get(new Operation()
|
||||
.parameter(new BodyParameter()
|
||||
.name("body")
|
||||
.schema(new ArrayModel()
|
||||
.items(new ObjectProperty()
|
||||
.property("arbitrary", new ObjectProperty()))))));
|
||||
|
||||
new InlineModelResolver().flatten(swagger);
|
||||
|
||||
Parameter param = swagger.getPaths().get("/hello").getGet().getParameters().get(0);
|
||||
assertTrue(param instanceof BodyParameter);
|
||||
|
||||
BodyParameter bp = (BodyParameter) param;
|
||||
Model schema = bp.getSchema();
|
||||
|
||||
assertTrue(schema instanceof ArrayModel);
|
||||
|
||||
ArrayModel am = (ArrayModel) schema;
|
||||
Property inner = am.getItems();
|
||||
assertTrue(inner instanceof RefProperty);
|
||||
|
||||
RefProperty rp = (RefProperty) inner;
|
||||
|
||||
assertEquals(rp.getType(), "ref");
|
||||
assertEquals(rp.get$ref(), "#/definitions/body");
|
||||
assertEquals(rp.getSimpleRef(), "body");
|
||||
|
||||
Model inline = swagger.getDefinitions().get("body");
|
||||
assertNotNull(inline);
|
||||
assertTrue(inline instanceof ModelImpl);
|
||||
ModelImpl impl = (ModelImpl) inline;
|
||||
Property p = impl.getProperties().get("arbitrary");
|
||||
assertNotNull(p);
|
||||
assertTrue(p instanceof ObjectProperty);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArbitraryObjectResponse() {
|
||||
Swagger swagger = new Swagger();
|
||||
|
||||
swagger.path("/foo/bar", new Path()
|
||||
.get(new Operation()
|
||||
.response(200, new Response()
|
||||
.description("it works!")
|
||||
.schema(new ObjectProperty()))));
|
||||
new InlineModelResolver().flatten(swagger);
|
||||
|
||||
Map<String, Response> responses = swagger.getPaths().get("/foo/bar").getGet().getResponses();
|
||||
|
||||
Response response = responses.get("200");
|
||||
assertNotNull(response);
|
||||
assertTrue(response.getSchema() instanceof ObjectProperty);
|
||||
ObjectProperty op = (ObjectProperty) response.getSchema();
|
||||
assertNull(op.getProperties());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArbitraryObjectResponseArray() {
|
||||
Swagger swagger = new Swagger();
|
||||
|
||||
swagger.path("/foo/baz", new Path()
|
||||
.get(new Operation()
|
||||
.response(200, new Response()
|
||||
.description("it works!")
|
||||
.schema(new ArrayProperty()
|
||||
.items(new ObjectProperty())))));
|
||||
new InlineModelResolver().flatten(swagger);
|
||||
|
||||
Response response = swagger.getPaths().get("/foo/baz").getGet().getResponses().get("200");
|
||||
assertTrue(response.getSchema() instanceof ArrayProperty);
|
||||
|
||||
ArrayProperty am = (ArrayProperty) response.getSchema();
|
||||
Property items = am.getItems();
|
||||
assertTrue(items instanceof ObjectProperty);
|
||||
ObjectProperty op = (ObjectProperty) items;
|
||||
assertNull(op.getProperties());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArbitraryObjectResponseArrayInline() {
|
||||
Swagger swagger = new Swagger();
|
||||
|
||||
swagger.path("/foo/baz", new Path()
|
||||
.get(new Operation()
|
||||
.response(200, new Response()
|
||||
.vendorExtension("x-foo", "bar")
|
||||
.description("it works!")
|
||||
.schema(new ArrayProperty()
|
||||
.items(new ObjectProperty()
|
||||
.property("arbitrary", new ObjectProperty()))))));
|
||||
|
||||
new InlineModelResolver().flatten(swagger);
|
||||
|
||||
Response response = swagger.getPaths().get("/foo/baz").getGet().getResponses().get("200");
|
||||
assertNotNull(response);
|
||||
|
||||
assertNotNull(response.getSchema());
|
||||
Property responseProperty = response.getSchema();
|
||||
assertTrue(responseProperty instanceof ArrayProperty);
|
||||
|
||||
ArrayProperty ap = (ArrayProperty) responseProperty;
|
||||
Property p = ap.getItems();
|
||||
assertNotNull(p);
|
||||
|
||||
RefProperty rp = (RefProperty) p;
|
||||
assertEquals(rp.getType(), "ref");
|
||||
assertEquals(rp.get$ref(), "#/definitions/inline_response_200");
|
||||
assertEquals(rp.getSimpleRef(), "inline_response_200");
|
||||
|
||||
Model inline = swagger.getDefinitions().get("inline_response_200");
|
||||
assertNotNull(inline);
|
||||
assertTrue(inline instanceof ModelImpl);
|
||||
ModelImpl impl = (ModelImpl) inline;
|
||||
Property inlineProp = impl.getProperties().get("arbitrary");
|
||||
assertNotNull(inlineProp);
|
||||
assertTrue(inlineProp instanceof ObjectProperty);
|
||||
ObjectProperty op = (ObjectProperty) inlineProp;
|
||||
assertNull(op.getProperties());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArbitraryObjectResponseMapInline() {
|
||||
Swagger swagger = new Swagger();
|
||||
|
||||
MapProperty schema = new MapProperty();
|
||||
schema.setAdditionalProperties(new ObjectProperty());
|
||||
|
||||
swagger.path("/foo/baz", new Path()
|
||||
.get(new Operation()
|
||||
.response(200, new Response()
|
||||
.description("it works!")
|
||||
.schema(schema))));
|
||||
new InlineModelResolver().flatten(swagger);
|
||||
|
||||
Response response = swagger.getPaths().get("/foo/baz").getGet().getResponses().get("200");
|
||||
|
||||
Property property = response.getSchema();
|
||||
assertTrue(property instanceof MapProperty);
|
||||
assertTrue(swagger.getDefinitions().size() == 0);
|
||||
Property inlineProp = ((MapProperty) property).getAdditionalProperties();
|
||||
assertTrue(inlineProp instanceof ObjectProperty);
|
||||
ObjectProperty op = (ObjectProperty) inlineProp;
|
||||
assertNull(op.getProperties());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArbitraryObjectModelInline() {
|
||||
Swagger swagger = new Swagger();
|
||||
|
||||
swagger.addDefinition("User", new ModelImpl()
|
||||
.name("user")
|
||||
.description("a common user")
|
||||
.property("name", new StringProperty())
|
||||
.property("arbitrary", new ObjectProperty()
|
||||
.title("title")
|
||||
._default("default")
|
||||
.access("access")
|
||||
.readOnly(false)
|
||||
.required(true)
|
||||
.description("description")
|
||||
.name("name")));
|
||||
|
||||
new InlineModelResolver().flatten(swagger);
|
||||
|
||||
ModelImpl user = (ModelImpl)swagger.getDefinitions().get("User");
|
||||
assertNotNull(user);
|
||||
Property inlineProp = user.getProperties().get("arbitrary");
|
||||
assertTrue(inlineProp instanceof ObjectProperty);
|
||||
ObjectProperty op = (ObjectProperty) inlineProp;
|
||||
assertNull(op.getProperties());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArbitraryObjectModelWithArrayInline() {
|
||||
Swagger swagger = new Swagger();
|
||||
|
||||
swagger.addDefinition("User", new ArrayModel()
|
||||
.items(new ObjectProperty()
|
||||
.title("title")
|
||||
._default("default")
|
||||
.access("access")
|
||||
.readOnly(false)
|
||||
.required(true)
|
||||
.description("description")
|
||||
.name("name")
|
||||
.property("arbitrary", new ObjectProperty())));
|
||||
|
||||
new InlineModelResolver().flatten(swagger);
|
||||
|
||||
Model model = swagger.getDefinitions().get("User");
|
||||
assertTrue(model instanceof ArrayModel);
|
||||
ArrayModel am = (ArrayModel) model;
|
||||
Property inner = am.getItems();
|
||||
assertTrue(inner instanceof RefProperty);
|
||||
|
||||
ModelImpl userInner = (ModelImpl)swagger.getDefinitions().get("User_inner");
|
||||
assertNotNull(userInner);
|
||||
Property inlineProp = userInner.getProperties().get("arbitrary");
|
||||
assertTrue(inlineProp instanceof ObjectProperty);
|
||||
ObjectProperty op = (ObjectProperty) inlineProp;
|
||||
assertNull(op.getProperties());
|
||||
}
|
||||
}
|
||||
|
@ -309,6 +309,71 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"/pet/{petId}?response=inline_arbitrary_object": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"pet"
|
||||
],
|
||||
"summary": "Fake endpoint to test inline arbitrary object return by 'Find pet by ID'",
|
||||
"description": "Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions",
|
||||
"operationId": "getPetByIdInObject",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "petId",
|
||||
"in": "path",
|
||||
"description": "ID of pet that needs to be fetched",
|
||||
"required": true,
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"404": {
|
||||
"description": "Pet not found"
|
||||
},
|
||||
"200": {
|
||||
"description": "successful operation",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"id"
|
||||
],
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
},
|
||||
"category": {
|
||||
"type": "object"
|
||||
},
|
||||
"name": {
|
||||
"type": "string",
|
||||
"example": "doggie"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Invalid ID supplied"
|
||||
}
|
||||
},
|
||||
"security": [
|
||||
{
|
||||
"api_key": []
|
||||
},
|
||||
{
|
||||
"petstore_auth": [
|
||||
"write:pets",
|
||||
"read:pets"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"/pet/{petId}": {
|
||||
"get": {
|
||||
"tags": [
|
||||
@ -536,6 +601,33 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"/store/inventory?response=arbitrary_object": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"store"
|
||||
],
|
||||
"summary": "Fake endpoint to test arbitrary object return by 'Get inventory'",
|
||||
"description": "Returns an arbitrary object which is actually a map of status codes to quantities",
|
||||
"operationId": "getInventoryInObject",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "successful operation",
|
||||
"schema": {
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"security": [
|
||||
{
|
||||
"api_key": []
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"/store/order": {
|
||||
"post": {
|
||||
"tags": [
|
||||
|
@ -9,13 +9,14 @@ import io.swagger.client.Pair;
|
||||
|
||||
import io.swagger.client.model.Pet;
|
||||
import java.io.File;
|
||||
import io.swagger.client.model.InlineResponse200;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-02-29T12:55:35.772+08:00")
|
||||
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-03-03T10:59:23.243+08:00")
|
||||
public class PetApi {
|
||||
private ApiClient apiClient;
|
||||
|
||||
@ -405,6 +406,54 @@ public class PetApi {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Fake endpoint to test inline arbitrary object return by 'Find pet by ID'
|
||||
* Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions
|
||||
* @param petId ID of pet that needs to be fetched
|
||||
* @return InlineResponse200
|
||||
* @throws ApiException if fails to make API call
|
||||
*/
|
||||
public InlineResponse200 getPetByIdInObject(Long petId) throws ApiException {
|
||||
Object localVarPostBody = null;
|
||||
|
||||
// verify the required parameter 'petId' is set
|
||||
if (petId == null) {
|
||||
throw new ApiException(400, "Missing the required parameter 'petId' when calling getPetByIdInObject");
|
||||
}
|
||||
|
||||
// create path and map variables
|
||||
String localVarPath = "/pet/{petId}?response=inline_arbitrary_object".replaceAll("\\{format\\}","json")
|
||||
.replaceAll("\\{" + "petId" + "\\}", apiClient.escapeString(petId.toString()));
|
||||
|
||||
// query params
|
||||
List<Pair> localVarQueryParams = new ArrayList<Pair>();
|
||||
Map<String, String> localVarHeaderParams = new HashMap<String, String>();
|
||||
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
final String[] localVarAccepts = {
|
||||
"application/json", "application/xml"
|
||||
};
|
||||
final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
|
||||
|
||||
final String[] localVarContentTypes = {
|
||||
|
||||
};
|
||||
final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
|
||||
|
||||
String[] localVarAuthNames = new String[] { "petstore_auth", "api_key" };
|
||||
|
||||
|
||||
GenericType<InlineResponse200> localVarReturnType = new GenericType<InlineResponse200>() {};
|
||||
return apiClient.invokeAPI(localVarPath, "GET", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAccept, localVarContentType, localVarAuthNames, localVarReturnType);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Fake endpoint to test byte array return by 'Find pet by ID'
|
||||
* Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions
|
||||
|
@ -14,7 +14,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-02-29T12:55:35.772+08:00")
|
||||
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-03-03T11:57:06.886+08:00")
|
||||
public class StoreApi {
|
||||
private ApiClient apiClient;
|
||||
|
||||
@ -120,6 +120,47 @@ public class StoreApi {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Fake endpoint to test arbitrary object return by 'Get inventory'
|
||||
* Returns an arbitrary object which is actually a map of status codes to quantities
|
||||
* @return Object
|
||||
* @throws ApiException if fails to make API call
|
||||
*/
|
||||
public Object getInventoryInObject() throws ApiException {
|
||||
Object localVarPostBody = null;
|
||||
|
||||
// create path and map variables
|
||||
String localVarPath = "/store/inventory?response=arbitrary_object".replaceAll("\\{format\\}","json");
|
||||
|
||||
// query params
|
||||
List<Pair> localVarQueryParams = new ArrayList<Pair>();
|
||||
Map<String, String> localVarHeaderParams = new HashMap<String, String>();
|
||||
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
final String[] localVarAccepts = {
|
||||
"application/json", "application/xml"
|
||||
};
|
||||
final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
|
||||
|
||||
final String[] localVarContentTypes = {
|
||||
|
||||
};
|
||||
final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
|
||||
|
||||
String[] localVarAuthNames = new String[] { "api_key" };
|
||||
|
||||
|
||||
GenericType<Object> localVarReturnType = new GenericType<Object>() {};
|
||||
return apiClient.invokeAPI(localVarPath, "GET", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAccept, localVarContentType, localVarAuthNames, localVarReturnType);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Place an order for a pet
|
||||
*
|
||||
|
@ -0,0 +1,114 @@
|
||||
package io.swagger.client.model;
|
||||
|
||||
import java.util.Objects;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-03-03T10:48:49.300+08:00")
|
||||
public class InlineResponse200 {
|
||||
|
||||
private String name = null;
|
||||
private Long id = null;
|
||||
private Object category = null;
|
||||
|
||||
|
||||
/**
|
||||
**/
|
||||
public InlineResponse200 name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ApiModelProperty(example = "doggie", value = "")
|
||||
@JsonProperty("name")
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
**/
|
||||
public InlineResponse200 id(Long id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ApiModelProperty(example = "null", required = true, value = "")
|
||||
@JsonProperty("id")
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
**/
|
||||
public InlineResponse200 category(Object category) {
|
||||
this.category = category;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ApiModelProperty(example = "null", value = "")
|
||||
@JsonProperty("category")
|
||||
public Object getCategory() {
|
||||
return category;
|
||||
}
|
||||
public void setCategory(Object category) {
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(java.lang.Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
InlineResponse200 inlineResponse200 = (InlineResponse200) o;
|
||||
return Objects.equals(this.name, inlineResponse200.name) &&
|
||||
Objects.equals(this.id, inlineResponse200.id) &&
|
||||
Objects.equals(this.category, inlineResponse200.category);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(name, id, category);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class InlineResponse200 {\n");
|
||||
|
||||
sb.append(" name: ").append(toIndentedString(name)).append("\n");
|
||||
sb.append(" id: ").append(toIndentedString(id)).append("\n");
|
||||
sb.append(" category: ").append(toIndentedString(category)).append("\n");
|
||||
sb.append("}");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the given object to string with each line indented by 4 spaces
|
||||
* (except the first line).
|
||||
*/
|
||||
private String toIndentedString(java.lang.Object o) {
|
||||
if (o == null) {
|
||||
return "null";
|
||||
}
|
||||
return o.toString().replace("\n", "\n ");
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import java.io.FileWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.*;
|
||||
import static org.junit.Assert.*;
|
||||
@ -86,6 +87,39 @@ public class PetApiTest {
|
||||
assertEquals(fetched.getCategory().getName(), pet.getCategory().getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPetByIdInObject() throws Exception {
|
||||
Pet pet = new Pet();
|
||||
pet.setId(TestUtils.nextId());
|
||||
pet.setName("pet " + pet.getId());
|
||||
|
||||
Category category = new Category();
|
||||
category.setId(TestUtils.nextId());
|
||||
category.setName("category " + category.getId());
|
||||
pet.setCategory(category);
|
||||
|
||||
pet.setStatus(Pet.StatusEnum.PENDING);
|
||||
List<String> photos = Arrays.asList(new String[]{"http://foo.bar.com/1"});
|
||||
pet.setPhotoUrls(photos);
|
||||
|
||||
api.addPet(pet);
|
||||
|
||||
InlineResponse200 fetched = api.getPetByIdInObject(pet.getId());
|
||||
assertEquals(pet.getId(), fetched.getId());
|
||||
assertEquals(pet.getName(), fetched.getName());
|
||||
|
||||
Object categoryObj = fetched.getCategory();
|
||||
assertNotNull(categoryObj);
|
||||
assertTrue(categoryObj instanceof Map);
|
||||
|
||||
Map categoryMap = (Map) categoryObj;
|
||||
Object categoryIdObj = categoryMap.get("id");
|
||||
assertTrue(categoryIdObj instanceof Integer);
|
||||
Integer categoryIdInt = (Integer) categoryIdObj;
|
||||
assertEquals(category.getId(), Long.valueOf(categoryIdInt));
|
||||
assertEquals(category.getName(), categoryMap.get("name"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdatePet() throws Exception {
|
||||
Pet pet = createRandomPet();
|
||||
|
@ -35,6 +35,19 @@ public class StoreApiTest {
|
||||
assertTrue(inventory.keySet().size() > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetInventoryInObject() throws Exception {
|
||||
Object inventoryObj = api.getInventoryInObject();
|
||||
assertTrue(inventoryObj instanceof Map);
|
||||
|
||||
Map inventoryMap = (Map) inventoryObj;
|
||||
assertTrue(inventoryMap.keySet().size() > 0);
|
||||
|
||||
Map.Entry firstEntry = (Map.Entry) inventoryMap.entrySet().iterator().next();
|
||||
assertTrue(firstEntry.getKey() instanceof String);
|
||||
assertTrue(firstEntry.getValue() instanceof Integer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPlaceOrder() throws Exception {
|
||||
Order order = createOrder();
|
||||
|
@ -4,6 +4,7 @@ import io.swagger.client.ApiClient;
|
||||
|
||||
import io.swagger.client.model.Pet;
|
||||
import java.io.File;
|
||||
import io.swagger.client.model.InlineResponse200;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@ -11,7 +12,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import feign.*;
|
||||
|
||||
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-02-25T16:20:49.744+08:00")
|
||||
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-03-03T12:04:41.120+08:00")
|
||||
public interface PetApi extends ApiClient.Api {
|
||||
|
||||
|
||||
@ -43,8 +44,8 @@ public interface PetApi extends ApiClient.Api {
|
||||
|
||||
/**
|
||||
* Finds Pets by status
|
||||
* Multiple status values can be provided with comma seperated strings
|
||||
* @param status Status values that need to be considered for filter
|
||||
* Multiple status values can be provided with comma separated strings
|
||||
* @param status Status values that need to be considered for query
|
||||
* @return List<Pet>
|
||||
*/
|
||||
@RequestLine("GET /pet/findByStatus?status={status}")
|
||||
@ -125,6 +126,19 @@ public interface PetApi extends ApiClient.Api {
|
||||
})
|
||||
void uploadFile(@Param("petId") Long petId, @Param("additionalMetadata") String additionalMetadata, @Param("file") File file);
|
||||
|
||||
/**
|
||||
* Fake endpoint to test inline arbitrary object return by 'Find pet by ID'
|
||||
* Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions
|
||||
* @param petId ID of pet that needs to be fetched
|
||||
* @return InlineResponse200
|
||||
*/
|
||||
@RequestLine("GET /pet/{petId}?response=inline_arbitrary_object")
|
||||
@Headers({
|
||||
"Content-type: application/json",
|
||||
"Accepts: application/json",
|
||||
})
|
||||
InlineResponse200 getPetByIdInObject(@Param("petId") Long petId);
|
||||
|
||||
/**
|
||||
* Fake endpoint to test byte array return by 'Find pet by ID'
|
||||
* Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions
|
||||
|
@ -10,10 +10,23 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import feign.*;
|
||||
|
||||
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-01-11T21:48:33.457Z")
|
||||
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-03-03T12:04:41.120+08:00")
|
||||
public interface StoreApi extends ApiClient.Api {
|
||||
|
||||
|
||||
/**
|
||||
* Finds orders by status
|
||||
* A single status value can be provided as a string
|
||||
* @param status Status value that needs to be considered for query
|
||||
* @return List<Order>
|
||||
*/
|
||||
@RequestLine("GET /store/findByStatus?status={status}")
|
||||
@Headers({
|
||||
"Content-type: application/json",
|
||||
"Accepts: application/json",
|
||||
})
|
||||
List<Order> findOrdersByStatus(@Param("status") String status);
|
||||
|
||||
/**
|
||||
* Returns pet inventories by status
|
||||
* Returns a map of status codes to quantities
|
||||
@ -26,6 +39,18 @@ public interface StoreApi extends ApiClient.Api {
|
||||
})
|
||||
Map<String, Integer> getInventory();
|
||||
|
||||
/**
|
||||
* Fake endpoint to test arbitrary object return by 'Get inventory'
|
||||
* Returns an arbitrary object which is actually a map of status codes to quantities
|
||||
* @return Object
|
||||
*/
|
||||
@RequestLine("GET /store/inventory?response=arbitrary_object")
|
||||
@Headers({
|
||||
"Content-type: application/json",
|
||||
"Accepts: application/json",
|
||||
})
|
||||
Object getInventoryInObject();
|
||||
|
||||
/**
|
||||
* Place an order for a pet
|
||||
*
|
||||
|
@ -0,0 +1,114 @@
|
||||
package io.swagger.client.model;
|
||||
|
||||
import java.util.Objects;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-03-03T12:04:41.120+08:00")
|
||||
public class InlineResponse200 {
|
||||
|
||||
private String name = null;
|
||||
private Long id = null;
|
||||
private Object category = null;
|
||||
|
||||
|
||||
/**
|
||||
**/
|
||||
public InlineResponse200 name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ApiModelProperty(example = "doggie", value = "")
|
||||
@JsonProperty("name")
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
**/
|
||||
public InlineResponse200 id(Long id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ApiModelProperty(example = "null", required = true, value = "")
|
||||
@JsonProperty("id")
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
**/
|
||||
public InlineResponse200 category(Object category) {
|
||||
this.category = category;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ApiModelProperty(example = "null", value = "")
|
||||
@JsonProperty("category")
|
||||
public Object getCategory() {
|
||||
return category;
|
||||
}
|
||||
public void setCategory(Object category) {
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(java.lang.Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
InlineResponse200 inlineResponse200 = (InlineResponse200) o;
|
||||
return Objects.equals(this.name, inlineResponse200.name) &&
|
||||
Objects.equals(this.id, inlineResponse200.id) &&
|
||||
Objects.equals(this.category, inlineResponse200.category);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(name, id, category);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class InlineResponse200 {\n");
|
||||
|
||||
sb.append(" name: ").append(toIndentedString(name)).append("\n");
|
||||
sb.append(" id: ").append(toIndentedString(id)).append("\n");
|
||||
sb.append(" category: ").append(toIndentedString(category)).append("\n");
|
||||
sb.append("}");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the given object to string with each line indented by 4 spaces
|
||||
* (except the first line).
|
||||
*/
|
||||
private String toIndentedString(java.lang.Object o) {
|
||||
if (o == null) {
|
||||
return "null";
|
||||
}
|
||||
return o.toString().replace("\n", "\n ");
|
||||
}
|
||||
}
|
||||
|
@ -9,13 +9,14 @@ import javax.ws.rs.core.GenericType;
|
||||
|
||||
import io.swagger.client.model.Pet;
|
||||
import java.io.File;
|
||||
import io.swagger.client.model.InlineResponse200;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-02-29T12:55:37.248+08:00")
|
||||
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-03-03T12:04:39.601+08:00")
|
||||
public class PetApi {
|
||||
private ApiClient apiClient;
|
||||
|
||||
@ -405,6 +406,54 @@ public class PetApi {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Fake endpoint to test inline arbitrary object return by 'Find pet by ID'
|
||||
* Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions
|
||||
* @param petId ID of pet that needs to be fetched
|
||||
* @return InlineResponse200
|
||||
* @throws ApiException if fails to make API call
|
||||
*/
|
||||
public InlineResponse200 getPetByIdInObject(Long petId) throws ApiException {
|
||||
Object localVarPostBody = null;
|
||||
|
||||
// verify the required parameter 'petId' is set
|
||||
if (petId == null) {
|
||||
throw new ApiException(400, "Missing the required parameter 'petId' when calling getPetByIdInObject");
|
||||
}
|
||||
|
||||
// create path and map variables
|
||||
String localVarPath = "/pet/{petId}?response=inline_arbitrary_object".replaceAll("\\{format\\}","json")
|
||||
.replaceAll("\\{" + "petId" + "\\}", apiClient.escapeString(petId.toString()));
|
||||
|
||||
// query params
|
||||
List<Pair> localVarQueryParams = new ArrayList<Pair>();
|
||||
Map<String, String> localVarHeaderParams = new HashMap<String, String>();
|
||||
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
final String[] localVarAccepts = {
|
||||
"application/json", "application/xml"
|
||||
};
|
||||
final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
|
||||
|
||||
final String[] localVarContentTypes = {
|
||||
|
||||
};
|
||||
final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
|
||||
|
||||
String[] localVarAuthNames = new String[] { "petstore_auth", "api_key" };
|
||||
|
||||
|
||||
GenericType<InlineResponse200> localVarReturnType = new GenericType<InlineResponse200>() {};
|
||||
return apiClient.invokeAPI(localVarPath, "GET", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAccept, localVarContentType, localVarAuthNames, localVarReturnType);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Fake endpoint to test byte array return by 'Find pet by ID'
|
||||
* Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions
|
||||
|
@ -14,7 +14,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-02-29T12:55:37.248+08:00")
|
||||
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-03-03T12:04:39.601+08:00")
|
||||
public class StoreApi {
|
||||
private ApiClient apiClient;
|
||||
|
||||
@ -120,6 +120,47 @@ public class StoreApi {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Fake endpoint to test arbitrary object return by 'Get inventory'
|
||||
* Returns an arbitrary object which is actually a map of status codes to quantities
|
||||
* @return Object
|
||||
* @throws ApiException if fails to make API call
|
||||
*/
|
||||
public Object getInventoryInObject() throws ApiException {
|
||||
Object localVarPostBody = null;
|
||||
|
||||
// create path and map variables
|
||||
String localVarPath = "/store/inventory?response=arbitrary_object".replaceAll("\\{format\\}","json");
|
||||
|
||||
// query params
|
||||
List<Pair> localVarQueryParams = new ArrayList<Pair>();
|
||||
Map<String, String> localVarHeaderParams = new HashMap<String, String>();
|
||||
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
final String[] localVarAccepts = {
|
||||
"application/json", "application/xml"
|
||||
};
|
||||
final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
|
||||
|
||||
final String[] localVarContentTypes = {
|
||||
|
||||
};
|
||||
final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
|
||||
|
||||
String[] localVarAuthNames = new String[] { "api_key" };
|
||||
|
||||
|
||||
GenericType<Object> localVarReturnType = new GenericType<Object>() {};
|
||||
return apiClient.invokeAPI(localVarPath, "GET", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAccept, localVarContentType, localVarAuthNames, localVarReturnType);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Place an order for a pet
|
||||
*
|
||||
|
@ -0,0 +1,114 @@
|
||||
package io.swagger.client.model;
|
||||
|
||||
import java.util.Objects;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-03-03T12:04:39.601+08:00")
|
||||
public class InlineResponse200 {
|
||||
|
||||
private String name = null;
|
||||
private Long id = null;
|
||||
private Object category = null;
|
||||
|
||||
|
||||
/**
|
||||
**/
|
||||
public InlineResponse200 name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ApiModelProperty(example = "doggie", value = "")
|
||||
@JsonProperty("name")
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
**/
|
||||
public InlineResponse200 id(Long id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ApiModelProperty(example = "null", required = true, value = "")
|
||||
@JsonProperty("id")
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
**/
|
||||
public InlineResponse200 category(Object category) {
|
||||
this.category = category;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ApiModelProperty(example = "null", value = "")
|
||||
@JsonProperty("category")
|
||||
public Object getCategory() {
|
||||
return category;
|
||||
}
|
||||
public void setCategory(Object category) {
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(java.lang.Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
InlineResponse200 inlineResponse200 = (InlineResponse200) o;
|
||||
return Objects.equals(this.name, inlineResponse200.name) &&
|
||||
Objects.equals(this.id, inlineResponse200.id) &&
|
||||
Objects.equals(this.category, inlineResponse200.category);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(name, id, category);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class InlineResponse200 {\n");
|
||||
|
||||
sb.append(" name: ").append(toIndentedString(name)).append("\n");
|
||||
sb.append(" id: ").append(toIndentedString(id)).append("\n");
|
||||
sb.append(" category: ").append(toIndentedString(category)).append("\n");
|
||||
sb.append("}");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the given object to string with each line indented by 4 spaces
|
||||
* (except the first line).
|
||||
*/
|
||||
private String toIndentedString(java.lang.Object o) {
|
||||
if (o == null) {
|
||||
return "null";
|
||||
}
|
||||
return o.toString().replace("\n", "\n ");
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ import java.io.FileWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.*;
|
||||
import static org.junit.Assert.*;
|
||||
@ -83,6 +84,39 @@ public class PetApiTest {
|
||||
assertEquals(fetched.getCategory().getName(), pet.getCategory().getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPetByIdInObject() throws Exception {
|
||||
Pet pet = new Pet();
|
||||
pet.setId(TestUtils.nextId());
|
||||
pet.setName("pet " + pet.getId());
|
||||
|
||||
Category category = new Category();
|
||||
category.setId(TestUtils.nextId());
|
||||
category.setName("category " + category.getId());
|
||||
pet.setCategory(category);
|
||||
|
||||
pet.setStatus(Pet.StatusEnum.PENDING);
|
||||
List<String> photos = Arrays.asList(new String[]{"http://foo.bar.com/1"});
|
||||
pet.setPhotoUrls(photos);
|
||||
|
||||
api.addPet(pet);
|
||||
|
||||
InlineResponse200 fetched = api.getPetByIdInObject(pet.getId());
|
||||
assertEquals(pet.getId(), fetched.getId());
|
||||
assertEquals(pet.getName(), fetched.getName());
|
||||
|
||||
Object categoryObj = fetched.getCategory();
|
||||
assertNotNull(categoryObj);
|
||||
assertTrue(categoryObj instanceof Map);
|
||||
|
||||
Map categoryMap = (Map) categoryObj;
|
||||
Object categoryIdObj = categoryMap.get("id");
|
||||
assertTrue(categoryIdObj instanceof Integer);
|
||||
Integer categoryIdInt = (Integer) categoryIdObj;
|
||||
assertEquals(category.getId(), Long.valueOf(categoryIdInt));
|
||||
assertEquals(category.getName(), categoryMap.get("name"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdatePet() throws Exception {
|
||||
Pet pet = createRandomPet();
|
||||
|
@ -33,6 +33,19 @@ public class StoreApiTest {
|
||||
assertTrue(inventory.keySet().size() > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetInventoryInObject() throws Exception {
|
||||
Object inventoryObj = api.getInventoryInObject();
|
||||
assertTrue(inventoryObj instanceof Map);
|
||||
|
||||
Map inventoryMap = (Map) inventoryObj;
|
||||
assertTrue(inventoryMap.keySet().size() > 0);
|
||||
|
||||
Map.Entry firstEntry = (Map.Entry) inventoryMap.entrySet().iterator().next();
|
||||
assertTrue(firstEntry.getKey() instanceof String);
|
||||
assertTrue(firstEntry.getValue() instanceof Integer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPlaceOrder() throws Exception {
|
||||
Order order = createOrder();
|
||||
|
@ -19,6 +19,7 @@ import java.io.IOException;
|
||||
|
||||
import io.swagger.client.model.Pet;
|
||||
import java.io.File;
|
||||
import io.swagger.client.model.InlineResponse200;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
@ -895,6 +896,114 @@ public class PetApi {
|
||||
return call;
|
||||
}
|
||||
|
||||
/* Build call for getPetByIdInObject */
|
||||
private Call getPetByIdInObjectCall(Long petId, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
|
||||
Object localVarPostBody = null;
|
||||
|
||||
// verify the required parameter 'petId' is set
|
||||
if (petId == null) {
|
||||
throw new ApiException("Missing the required parameter 'petId' when calling getPetByIdInObject(Async)");
|
||||
}
|
||||
|
||||
|
||||
// create path and map variables
|
||||
String localVarPath = "/pet/{petId}?response=inline_arbitrary_object".replaceAll("\\{format\\}","json")
|
||||
.replaceAll("\\{" + "petId" + "\\}", apiClient.escapeString(petId.toString()));
|
||||
|
||||
List<Pair> localVarQueryParams = new ArrayList<Pair>();
|
||||
|
||||
Map<String, String> localVarHeaderParams = new HashMap<String, String>();
|
||||
|
||||
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
|
||||
|
||||
final String[] localVarAccepts = {
|
||||
"application/json", "application/xml"
|
||||
};
|
||||
final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
|
||||
if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept);
|
||||
|
||||
final String[] localVarContentTypes = {
|
||||
|
||||
};
|
||||
final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
|
||||
localVarHeaderParams.put("Content-Type", localVarContentType);
|
||||
|
||||
if(progressListener != null) {
|
||||
apiClient.getHttpClient().networkInterceptors().add(new Interceptor() {
|
||||
@Override
|
||||
public Response intercept(Interceptor.Chain chain) throws IOException {
|
||||
Response originalResponse = chain.proceed(chain.request());
|
||||
return originalResponse.newBuilder()
|
||||
.body(new ProgressResponseBody(originalResponse.body(), progressListener))
|
||||
.build();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
String[] localVarAuthNames = new String[] { "petstore_auth", "api_key" };
|
||||
return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fake endpoint to test inline arbitrary object return by 'Find pet by ID'
|
||||
* Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions
|
||||
* @param petId ID of pet that needs to be fetched
|
||||
* @return InlineResponse200
|
||||
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
|
||||
*/
|
||||
public InlineResponse200 getPetByIdInObject(Long petId) throws ApiException {
|
||||
ApiResponse<InlineResponse200> resp = getPetByIdInObjectWithHttpInfo(petId);
|
||||
return resp.getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fake endpoint to test inline arbitrary object return by 'Find pet by ID'
|
||||
* Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions
|
||||
* @param petId ID of pet that needs to be fetched
|
||||
* @return ApiResponse<InlineResponse200>
|
||||
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
|
||||
*/
|
||||
public ApiResponse<InlineResponse200> getPetByIdInObjectWithHttpInfo(Long petId) throws ApiException {
|
||||
Call call = getPetByIdInObjectCall(petId, null, null);
|
||||
Type localVarReturnType = new TypeToken<InlineResponse200>(){}.getType();
|
||||
return apiClient.execute(call, localVarReturnType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fake endpoint to test inline arbitrary object return by 'Find pet by ID' (asynchronously)
|
||||
* Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions
|
||||
* @param petId ID of pet that needs to be fetched
|
||||
* @param callback The callback to be executed when the API call finishes
|
||||
* @return The request call
|
||||
* @throws ApiException If fail to process the API call, e.g. serializing the request body object
|
||||
*/
|
||||
public Call getPetByIdInObjectAsync(Long petId, final ApiCallback<InlineResponse200> callback) throws ApiException {
|
||||
|
||||
ProgressResponseBody.ProgressListener progressListener = null;
|
||||
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;
|
||||
|
||||
if (callback != null) {
|
||||
progressListener = new ProgressResponseBody.ProgressListener() {
|
||||
@Override
|
||||
public void update(long bytesRead, long contentLength, boolean done) {
|
||||
callback.onDownloadProgress(bytesRead, contentLength, done);
|
||||
}
|
||||
};
|
||||
|
||||
progressRequestListener = new ProgressRequestBody.ProgressRequestListener() {
|
||||
@Override
|
||||
public void onRequestProgress(long bytesWritten, long contentLength, boolean done) {
|
||||
callback.onUploadProgress(bytesWritten, contentLength, done);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Call call = getPetByIdInObjectCall(petId, progressListener, progressRequestListener);
|
||||
Type localVarReturnType = new TypeToken<InlineResponse200>(){}.getType();
|
||||
apiClient.executeAsync(call, localVarReturnType, callback);
|
||||
return call;
|
||||
}
|
||||
|
||||
/* Build call for petPetIdtestingByteArraytrueGet */
|
||||
private Call petPetIdtestingByteArraytrueGetCall(Long petId, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
|
||||
Object localVarPostBody = null;
|
||||
|
@ -248,6 +248,105 @@ public class StoreApi {
|
||||
return call;
|
||||
}
|
||||
|
||||
/* Build call for getInventoryInObject */
|
||||
private Call getInventoryInObjectCall(final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
|
||||
Object localVarPostBody = null;
|
||||
|
||||
|
||||
// create path and map variables
|
||||
String localVarPath = "/store/inventory?response=arbitrary_object".replaceAll("\\{format\\}","json");
|
||||
|
||||
List<Pair> localVarQueryParams = new ArrayList<Pair>();
|
||||
|
||||
Map<String, String> localVarHeaderParams = new HashMap<String, String>();
|
||||
|
||||
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
|
||||
|
||||
final String[] localVarAccepts = {
|
||||
"application/json", "application/xml"
|
||||
};
|
||||
final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
|
||||
if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept);
|
||||
|
||||
final String[] localVarContentTypes = {
|
||||
|
||||
};
|
||||
final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
|
||||
localVarHeaderParams.put("Content-Type", localVarContentType);
|
||||
|
||||
if(progressListener != null) {
|
||||
apiClient.getHttpClient().networkInterceptors().add(new Interceptor() {
|
||||
@Override
|
||||
public Response intercept(Interceptor.Chain chain) throws IOException {
|
||||
Response originalResponse = chain.proceed(chain.request());
|
||||
return originalResponse.newBuilder()
|
||||
.body(new ProgressResponseBody(originalResponse.body(), progressListener))
|
||||
.build();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
String[] localVarAuthNames = new String[] { "api_key" };
|
||||
return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fake endpoint to test arbitrary object return by 'Get inventory'
|
||||
* Returns an arbitrary object which is actually a map of status codes to quantities
|
||||
* @return Object
|
||||
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
|
||||
*/
|
||||
public Object getInventoryInObject() throws ApiException {
|
||||
ApiResponse<Object> resp = getInventoryInObjectWithHttpInfo();
|
||||
return resp.getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fake endpoint to test arbitrary object return by 'Get inventory'
|
||||
* Returns an arbitrary object which is actually a map of status codes to quantities
|
||||
* @return ApiResponse<Object>
|
||||
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
|
||||
*/
|
||||
public ApiResponse<Object> getInventoryInObjectWithHttpInfo() throws ApiException {
|
||||
Call call = getInventoryInObjectCall(null, null);
|
||||
Type localVarReturnType = new TypeToken<Object>(){}.getType();
|
||||
return apiClient.execute(call, localVarReturnType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fake endpoint to test arbitrary object return by 'Get inventory' (asynchronously)
|
||||
* Returns an arbitrary object which is actually a map of status codes to quantities
|
||||
* @param callback The callback to be executed when the API call finishes
|
||||
* @return The request call
|
||||
* @throws ApiException If fail to process the API call, e.g. serializing the request body object
|
||||
*/
|
||||
public Call getInventoryInObjectAsync(final ApiCallback<Object> callback) throws ApiException {
|
||||
|
||||
ProgressResponseBody.ProgressListener progressListener = null;
|
||||
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;
|
||||
|
||||
if (callback != null) {
|
||||
progressListener = new ProgressResponseBody.ProgressListener() {
|
||||
@Override
|
||||
public void update(long bytesRead, long contentLength, boolean done) {
|
||||
callback.onDownloadProgress(bytesRead, contentLength, done);
|
||||
}
|
||||
};
|
||||
|
||||
progressRequestListener = new ProgressRequestBody.ProgressRequestListener() {
|
||||
@Override
|
||||
public void onRequestProgress(long bytesWritten, long contentLength, boolean done) {
|
||||
callback.onUploadProgress(bytesWritten, contentLength, done);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Call call = getInventoryInObjectCall(progressListener, progressRequestListener);
|
||||
Type localVarReturnType = new TypeToken<Object>(){}.getType();
|
||||
apiClient.executeAsync(call, localVarReturnType, callback);
|
||||
return call;
|
||||
}
|
||||
|
||||
/* Build call for placeOrder */
|
||||
private Call placeOrderCall(Order body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
|
||||
Object localVarPostBody = body;
|
||||
|
@ -0,0 +1,101 @@
|
||||
package io.swagger.client.model;
|
||||
|
||||
import java.util.Objects;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
|
||||
|
||||
|
||||
@ApiModel(description = "")
|
||||
public class InlineResponse200 {
|
||||
|
||||
@SerializedName("name")
|
||||
private String name = null;
|
||||
|
||||
@SerializedName("id")
|
||||
private Long id = null;
|
||||
|
||||
@SerializedName("category")
|
||||
private Object category = null;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
**/
|
||||
@ApiModelProperty(required = true, value = "")
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
public Object getCategory() {
|
||||
return category;
|
||||
}
|
||||
public void setCategory(Object category) {
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
InlineResponse200 inlineResponse200 = (InlineResponse200) o;
|
||||
return Objects.equals(this.name, inlineResponse200.name) &&
|
||||
Objects.equals(this.id, inlineResponse200.id) &&
|
||||
Objects.equals(this.category, inlineResponse200.category);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(name, id, category);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class InlineResponse200 {\n");
|
||||
|
||||
sb.append(" name: ").append(toIndentedString(name)).append("\n");
|
||||
sb.append(" id: ").append(toIndentedString(id)).append("\n");
|
||||
sb.append(" category: ").append(toIndentedString(category)).append("\n");
|
||||
sb.append("}");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the given object to string with each line indented by 4 spaces
|
||||
* (except the first line).
|
||||
*/
|
||||
private String toIndentedString(Object o) {
|
||||
if (o == null) {
|
||||
return "null";
|
||||
}
|
||||
return o.toString().replace("\n", "\n ");
|
||||
}
|
||||
}
|
@ -75,12 +75,10 @@ public class PetApiTest {
|
||||
@Test
|
||||
public void testCreateAndGetPetWithByteArray() throws Exception {
|
||||
Pet pet = createRandomPet();
|
||||
System.out.println(serializeJson(pet, api.getApiClient()));
|
||||
byte[] bytes = serializeJson(pet, api.getApiClient()).getBytes();
|
||||
api.addPetUsingByteArray(bytes);
|
||||
|
||||
byte[] fetchedBytes = api.petPetIdtestingByteArraytrueGet(pet.getId());
|
||||
System.out.println(new String(fetchedBytes));
|
||||
Type type = new TypeToken<Pet>(){}.getType();
|
||||
Pet fetched = deserializeJson(new String(fetchedBytes), type, api.getApiClient());
|
||||
assertNotNull(fetched);
|
||||
@ -199,6 +197,40 @@ public class PetApiTest {
|
||||
assertEquals("application/json", exception.getResponseHeaders().get("Content-Type").get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPetByIdInObject() throws Exception {
|
||||
Pet pet = new Pet();
|
||||
pet.setId(TestUtils.nextId());
|
||||
pet.setName("pet " + pet.getId());
|
||||
|
||||
Category category = new Category();
|
||||
category.setId(TestUtils.nextId());
|
||||
category.setName("category " + category.getId());
|
||||
pet.setCategory(category);
|
||||
|
||||
pet.setStatus(Pet.StatusEnum.PENDING);
|
||||
List<String> photos = Arrays.asList(new String[]{"http://foo.bar.com/1"});
|
||||
pet.setPhotoUrls(photos);
|
||||
|
||||
api.addPet(pet);
|
||||
|
||||
InlineResponse200 fetched = api.getPetByIdInObject(pet.getId());
|
||||
assertEquals(pet.getId(), fetched.getId());
|
||||
assertEquals(pet.getName(), fetched.getName());
|
||||
|
||||
Object categoryObj = fetched.getCategory();
|
||||
assertNotNull(categoryObj);
|
||||
assertTrue(categoryObj instanceof Map);
|
||||
|
||||
Map categoryMap = (Map) categoryObj;
|
||||
Object categoryIdObj = categoryMap.get("id");
|
||||
// NOTE: Gson parses integer value to double.
|
||||
assertTrue(categoryIdObj instanceof Double);
|
||||
Long categoryIdLong = ((Double) categoryIdObj).longValue();
|
||||
assertEquals(category.getId(), categoryIdLong);
|
||||
assertEquals(category.getName(), categoryMap.get("name"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdatePet() throws Exception {
|
||||
Pet pet = createRandomPet();
|
||||
@ -217,11 +249,11 @@ public class PetApiTest {
|
||||
public void testFindPetsByStatus() throws Exception {
|
||||
Pet pet = createRandomPet();
|
||||
pet.setName("programmer");
|
||||
pet.setStatus(Pet.StatusEnum.AVAILABLE);
|
||||
pet.setStatus(Pet.StatusEnum.PENDING);
|
||||
|
||||
api.updatePet(pet);
|
||||
|
||||
List<Pet> pets = api.findPetsByStatus(Arrays.asList(new String[]{"available"}));
|
||||
List<Pet> pets = api.findPetsByStatus(Arrays.asList(new String[]{"pending"}));
|
||||
assertNotNull(pets);
|
||||
|
||||
boolean found = false;
|
||||
@ -233,6 +265,8 @@ public class PetApiTest {
|
||||
}
|
||||
|
||||
assertTrue(found);
|
||||
|
||||
api.deletePet(pet.getId(), null);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -260,6 +294,8 @@ public class PetApiTest {
|
||||
}
|
||||
}
|
||||
assertTrue(found);
|
||||
|
||||
api.deletePet(pet.getId(), null);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -38,6 +38,20 @@ public class StoreApiTest {
|
||||
assertTrue(inventory.keySet().size() > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetInventoryInObject() throws Exception {
|
||||
Object inventoryObj = api.getInventoryInObject();
|
||||
assertTrue(inventoryObj instanceof Map);
|
||||
|
||||
Map inventoryMap = (Map) inventoryObj;
|
||||
assertTrue(inventoryMap.keySet().size() > 0);
|
||||
|
||||
Map.Entry firstEntry = (Map.Entry) inventoryMap.entrySet().iterator().next();
|
||||
assertTrue(firstEntry.getKey() instanceof String);
|
||||
// NOTE: Gson parses integer value to double.
|
||||
assertTrue(firstEntry.getValue() instanceof Double);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPlaceOrder() throws Exception {
|
||||
Order order = createOrder();
|
||||
|
@ -8,6 +8,7 @@ import retrofit.mime.*;
|
||||
|
||||
import io.swagger.client.model.Pet;
|
||||
import java.io.File;
|
||||
import io.swagger.client.model.InlineResponse200;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@ -71,8 +72,8 @@ public interface PetApi {
|
||||
/**
|
||||
* Finds Pets by status
|
||||
* Sync method
|
||||
* Multiple status values can be provided with comma seperated strings
|
||||
* @param status Status values that need to be considered for filter
|
||||
* Multiple status values can be provided with comma separated strings
|
||||
* @param status Status values that need to be considered for query
|
||||
* @return List<Pet>
|
||||
*/
|
||||
|
||||
@ -84,7 +85,7 @@ public interface PetApi {
|
||||
/**
|
||||
* Finds Pets by status
|
||||
* Async method
|
||||
* @param status Status values that need to be considered for filter
|
||||
* @param status Status values that need to be considered for query
|
||||
* @param cb callback method
|
||||
* @return void
|
||||
*/
|
||||
@ -238,6 +239,32 @@ public interface PetApi {
|
||||
@Path("petId") Long petId, @Part("additionalMetadata") String additionalMetadata, @Part("file") TypedFile file, Callback<Void> cb
|
||||
);
|
||||
|
||||
/**
|
||||
* Fake endpoint to test inline arbitrary object return by 'Find pet by ID'
|
||||
* Sync method
|
||||
* Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions
|
||||
* @param petId ID of pet that needs to be fetched
|
||||
* @return InlineResponse200
|
||||
*/
|
||||
|
||||
@GET("/pet/{petId}?response=inline_arbitrary_object")
|
||||
InlineResponse200 getPetByIdInObject(
|
||||
@Path("petId") Long petId
|
||||
);
|
||||
|
||||
/**
|
||||
* Fake endpoint to test inline arbitrary object return by 'Find pet by ID'
|
||||
* Async method
|
||||
* @param petId ID of pet that needs to be fetched
|
||||
* @param cb callback method
|
||||
* @return void
|
||||
*/
|
||||
|
||||
@GET("/pet/{petId}?response=inline_arbitrary_object")
|
||||
void getPetByIdInObject(
|
||||
@Path("petId") Long petId, Callback<InlineResponse200> cb
|
||||
);
|
||||
|
||||
/**
|
||||
* Fake endpoint to test byte array return by 'Find pet by ID'
|
||||
* Sync method
|
||||
|
@ -15,6 +15,32 @@ import java.util.Map;
|
||||
|
||||
public interface StoreApi {
|
||||
|
||||
/**
|
||||
* Finds orders by status
|
||||
* Sync method
|
||||
* A single status value can be provided as a string
|
||||
* @param status Status value that needs to be considered for query
|
||||
* @return List<Order>
|
||||
*/
|
||||
|
||||
@GET("/store/findByStatus")
|
||||
List<Order> findOrdersByStatus(
|
||||
@Query("status") String status
|
||||
);
|
||||
|
||||
/**
|
||||
* Finds orders by status
|
||||
* Async method
|
||||
* @param status Status value that needs to be considered for query
|
||||
* @param cb callback method
|
||||
* @return void
|
||||
*/
|
||||
|
||||
@GET("/store/findByStatus")
|
||||
void findOrdersByStatus(
|
||||
@Query("status") String status, Callback<List<Order>> cb
|
||||
);
|
||||
|
||||
/**
|
||||
* Returns pet inventories by status
|
||||
* Sync method
|
||||
@ -38,6 +64,29 @@ public interface StoreApi {
|
||||
Callback<Map<String, Integer>> cb
|
||||
);
|
||||
|
||||
/**
|
||||
* Fake endpoint to test arbitrary object return by 'Get inventory'
|
||||
* Sync method
|
||||
* Returns an arbitrary object which is actually a map of status codes to quantities
|
||||
* @return Object
|
||||
*/
|
||||
|
||||
@GET("/store/inventory?response=arbitrary_object")
|
||||
Object getInventoryInObject();
|
||||
|
||||
|
||||
/**
|
||||
* Fake endpoint to test arbitrary object return by 'Get inventory'
|
||||
* Async method
|
||||
* @param cb callback method
|
||||
* @return void
|
||||
*/
|
||||
|
||||
@GET("/store/inventory?response=arbitrary_object")
|
||||
void getInventoryInObject(
|
||||
Callback<Object> cb
|
||||
);
|
||||
|
||||
/**
|
||||
* Place an order for a pet
|
||||
* Sync method
|
||||
|
@ -0,0 +1,101 @@
|
||||
package io.swagger.client.model;
|
||||
|
||||
import java.util.Objects;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
|
||||
|
||||
|
||||
@ApiModel(description = "")
|
||||
public class InlineResponse200 {
|
||||
|
||||
@SerializedName("name")
|
||||
private String name = null;
|
||||
|
||||
@SerializedName("id")
|
||||
private Long id = null;
|
||||
|
||||
@SerializedName("category")
|
||||
private Object category = null;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
**/
|
||||
@ApiModelProperty(required = true, value = "")
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
public Object getCategory() {
|
||||
return category;
|
||||
}
|
||||
public void setCategory(Object category) {
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
InlineResponse200 inlineResponse200 = (InlineResponse200) o;
|
||||
return Objects.equals(name, inlineResponse200.name) &&
|
||||
Objects.equals(id, inlineResponse200.id) &&
|
||||
Objects.equals(category, inlineResponse200.category);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(name, id, category);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class InlineResponse200 {\n");
|
||||
|
||||
sb.append(" name: ").append(toIndentedString(name)).append("\n");
|
||||
sb.append(" id: ").append(toIndentedString(id)).append("\n");
|
||||
sb.append(" category: ").append(toIndentedString(category)).append("\n");
|
||||
sb.append("}");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the given object to string with each line indented by 4 spaces
|
||||
* (except the first line).
|
||||
*/
|
||||
private String toIndentedString(Object o) {
|
||||
if (o == null) {
|
||||
return "null";
|
||||
}
|
||||
return o.toString().replace("\n", "\n ");
|
||||
}
|
||||
}
|
@ -10,6 +10,7 @@ import okhttp3.RequestBody;
|
||||
|
||||
import io.swagger.client.model.Pet;
|
||||
import java.io.File;
|
||||
import io.swagger.client.model.InlineResponse200;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@ -46,8 +47,8 @@ public interface PetApi {
|
||||
|
||||
/**
|
||||
* Finds Pets by status
|
||||
* Multiple status values can be provided with comma seperated strings
|
||||
* @param status Status values that need to be considered for filter
|
||||
* Multiple status values can be provided with comma separated strings
|
||||
* @param status Status values that need to be considered for query
|
||||
* @return Call<List<Pet>>
|
||||
*/
|
||||
|
||||
@ -129,6 +130,19 @@ public interface PetApi {
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Fake endpoint to test inline arbitrary object return by 'Find pet by ID'
|
||||
* Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions
|
||||
* @param petId ID of pet that needs to be fetched
|
||||
* @return Call<InlineResponse200>
|
||||
*/
|
||||
|
||||
@GET("pet/{petId}?response=inline_arbitrary_object")
|
||||
Call<InlineResponse200> getPetByIdInObject(
|
||||
@Path("petId") Long petId
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Fake endpoint to test byte array return by 'Find pet by ID'
|
||||
* Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions
|
||||
|
@ -17,6 +17,19 @@ import java.util.Map;
|
||||
|
||||
public interface StoreApi {
|
||||
|
||||
/**
|
||||
* Finds orders by status
|
||||
* A single status value can be provided as a string
|
||||
* @param status Status value that needs to be considered for query
|
||||
* @return Call<List<Order>>
|
||||
*/
|
||||
|
||||
@GET("store/findByStatus")
|
||||
Call<List<Order>> findOrdersByStatus(
|
||||
@Query("status") String status
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Returns pet inventories by status
|
||||
* Returns a map of status codes to quantities
|
||||
@ -28,6 +41,17 @@ public interface StoreApi {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Fake endpoint to test arbitrary object return by 'Get inventory'
|
||||
* Returns an arbitrary object which is actually a map of status codes to quantities
|
||||
* @return Call<Object>
|
||||
*/
|
||||
|
||||
@GET("store/inventory?response=arbitrary_object")
|
||||
Call<Object> getInventoryInObject();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Place an order for a pet
|
||||
*
|
||||
|
@ -0,0 +1,101 @@
|
||||
package io.swagger.client.model;
|
||||
|
||||
import java.util.Objects;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
|
||||
|
||||
|
||||
@ApiModel(description = "")
|
||||
public class InlineResponse200 {
|
||||
|
||||
@SerializedName("name")
|
||||
private String name = null;
|
||||
|
||||
@SerializedName("id")
|
||||
private Long id = null;
|
||||
|
||||
@SerializedName("category")
|
||||
private Object category = null;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
**/
|
||||
@ApiModelProperty(required = true, value = "")
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
public Object getCategory() {
|
||||
return category;
|
||||
}
|
||||
public void setCategory(Object category) {
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
InlineResponse200 inlineResponse200 = (InlineResponse200) o;
|
||||
return Objects.equals(name, inlineResponse200.name) &&
|
||||
Objects.equals(id, inlineResponse200.id) &&
|
||||
Objects.equals(category, inlineResponse200.category);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(name, id, category);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class InlineResponse200 {\n");
|
||||
|
||||
sb.append(" name: ").append(toIndentedString(name)).append("\n");
|
||||
sb.append(" id: ").append(toIndentedString(id)).append("\n");
|
||||
sb.append(" category: ").append(toIndentedString(category)).append("\n");
|
||||
sb.append("}");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the given object to string with each line indented by 4 spaces
|
||||
* (except the first line).
|
||||
*/
|
||||
private String toIndentedString(Object o) {
|
||||
if (o == null) {
|
||||
return "null";
|
||||
}
|
||||
return o.toString().replace("\n", "\n ");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user