From 9311dcaccbfac1d8beda29a6017be217f462b399 Mon Sep 17 00:00:00 2001 From: wing328 Date: Sat, 10 Oct 2015 18:39:54 +0800 Subject: [PATCH 01/17] update codegen to support global consumes and produces --- .../io/swagger/codegen/CodegenConfig.java | 2 + .../io/swagger/codegen/DefaultCodegen.java | 40 +++++++++++++++---- .../io/swagger/codegen/DefaultGenerator.java | 2 +- .../codegen/languages/SwiftCodegen.java | 6 ++- .../petstore/objc/SwaggerClient.podspec | 8 ++-- .../petstore/objc/SwaggerClient/SWGOrder.h | 2 +- .../petstore/objc/SwaggerClient/SWGOrder.m | 4 +- .../petstore/objc/SwaggerClient/SWGPet.h | 2 +- .../petstore/objc/SwaggerClient/SWGPetApi.m | 2 +- .../petstore/objc/SwaggerClient/SWGUserApi.h | 2 +- .../petstore/objc/SwaggerClient/SWGUserApi.m | 2 +- .../php/SwaggerClient-php/lib/Api/PetApi.php | 31 -------------- .../SwaggerClient-php/lib/Api/StoreApi.php | 7 ---- .../lib/ObjectSerializer.php | 2 +- 14 files changed, 52 insertions(+), 60 deletions(-) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConfig.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConfig.java index 10d7363cc35a..b50147a6ff3e 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConfig.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConfig.java @@ -67,6 +67,8 @@ public interface CodegenConfig { CodegenModel fromModel(String name, Model model, Map allDefinitions); + CodegenOperation fromOperation(String resourcePath, String httpMethod, Operation operation, Map definitions, Swagger swagger); + CodegenOperation fromOperation(String resourcePath, String httpMethod, Operation operation, Map definitions); List fromSecurity(Map schemes); diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java index efc0aa31dbc8..d0185c0ad021 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java @@ -861,8 +861,12 @@ public class DefaultCodegen { } return responses.get(code); } - + public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, Map definitions) { + return fromOperation(path, httpMethod, operation, definitions, null); + } + + public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, Map definitions, Swagger swagger) { CodegenOperation op = CodegenModelFactory.newInstance(CodegenModelType.OPERATION); Set imports = new HashSet(); op.vendorExtensions = operation.getVendorExtensions(); @@ -899,14 +903,25 @@ public class DefaultCodegen { op.notes = escapeText(operation.getDescription()); op.tags = operation.getTags(); - if (operation.getConsumes() != null && operation.getConsumes().size() > 0) { + List consumes = new ArrayList(); + if (operation.getConsumes() != null && operation.getConsumes().size() > 0) { + // use consumes defined in the operation + consumes = operation.getConsumes(); + } else if (swagger != null && swagger.getConsumes() != null && swagger.getConsumes().size() > 0) { + // use consumes defined globally + consumes = swagger.getConsumes(); + LOGGER.debug("Using global consumes (" + swagger.getConsumes() + ") for " + op.operationId); + } + + // if "consumes" is defined (per operation or using global definition) + if (consumes != null && consumes.size() > 0) { List> c = new ArrayList>(); int count = 0; - for (String key : operation.getConsumes()) { + for (String key : consumes) { Map mediaType = new HashMap(); mediaType.put("mediaType", key); count += 1; - if (count < operation.getConsumes().size()) { + if (count < consumes.size()) { mediaType.put("hasMore", "true"); } else { mediaType.put("hasMore", null); @@ -917,14 +932,25 @@ public class DefaultCodegen { op.hasConsumes = true; } - if (operation.getProduces() != null && operation.getProduces().size() > 0) { + List produces = new ArrayList(); + if (operation.getProduces() != null && operation.getProduces().size() > 0) { + // use produces defined in the operation + produces = operation.getProduces(); + } else if (swagger != null && swagger.getProduces() != null && swagger.getProduces().size() > 0) { + // use produces defined globally + produces = swagger.getProduces(); + LOGGER.debug("Using global produces (" + swagger.getProduces() + ") for " + op.operationId); + } + + // if "produces" is defined (per operation or using global definition) + if (produces != null && produces.size() > 0) { List> c = new ArrayList>(); int count = 0; - for (String key : operation.getProduces()) { + for (String key : produces) { Map mediaType = new HashMap(); mediaType.put("mediaType", key); count += 1; - if (count < operation.getProduces().size()) { + if (count < produces.size()) { mediaType.put("hasMore", "true"); } else { mediaType.put("hasMore", null); diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java index a785f45bdf21..2b61635e0b9b 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java @@ -470,7 +470,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator { for (String tag : tags) { CodegenOperation co = null; try { - co = config.fromOperation(resourcePath, httpMethod, operation, swagger.getDefinitions()); + co = config.fromOperation(resourcePath, httpMethod, operation, swagger.getDefinitions(), swagger); co.tags = new ArrayList(); co.tags.add(sanitizeTag(tag)); config.addOperationToGroup(sanitizeTag(tag), resourcePath, operation, co, operations); diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/SwiftCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/SwiftCodegen.java index 55c3864adb7d..9bb1dfd61d47 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/SwiftCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/SwiftCodegen.java @@ -1,9 +1,11 @@ package io.swagger.codegen.languages; import com.google.common.base.Predicate; + import com.google.common.collect.Iterators; import com.google.common.collect.Lists; import io.swagger.codegen.*; +import io.swagger.models.Swagger; import io.swagger.models.Model; import io.swagger.models.Operation; import io.swagger.models.parameters.HeaderParameter; @@ -256,7 +258,7 @@ public class SwiftCodegen extends DefaultCodegen implements CodegenConfig { } @Override - public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, Map definitions) { + public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, Map definitions, Swagger swagger) { path = normalizePath(path); List parameters = operation.getParameters(); parameters = Lists.newArrayList(Iterators.filter(parameters.iterator(), new Predicate() { @@ -266,7 +268,7 @@ public class SwiftCodegen extends DefaultCodegen implements CodegenConfig { } })); operation.setParameters(parameters); - return super.fromOperation(path, httpMethod, operation, definitions); + return super.fromOperation(path, httpMethod, operation, definitions, swagger); } private static String normalizePath(String path) { diff --git a/samples/client/petstore/objc/SwaggerClient.podspec b/samples/client/petstore/objc/SwaggerClient.podspec index 4445bc52ad23..0afb511073c3 100644 --- a/samples/client/petstore/objc/SwaggerClient.podspec +++ b/samples/client/petstore/objc/SwaggerClient.podspec @@ -21,10 +21,10 @@ Pod::Spec.new do |s| s.framework = 'SystemConfiguration' - s.homepage = "" - s.license = "" - s.source = { :git => ".git", :tag => "#{s.version}" } - s.author = { "" => "" } + s.homepage = "https://github.com/swagger-api/swagger-codegen" + s.license = "MIT" + s.source = { :git => "https://github.com/swagger-api/swagger-codegen.git", :tag => "#{s.version}" } + s.author = { "Swagger" => "apiteam@swagger.io" } s.source_files = 'SwaggerClient/**/*' s.public_header_files = 'SwaggerClient/**/*.h' diff --git a/samples/client/petstore/objc/SwaggerClient/SWGOrder.h b/samples/client/petstore/objc/SwaggerClient/SWGOrder.h index 48a7cf0d6c1f..4b132c57be50 100644 --- a/samples/client/petstore/objc/SwaggerClient/SWGOrder.h +++ b/samples/client/petstore/objc/SwaggerClient/SWGOrder.h @@ -26,6 +26,6 @@ */ @property(nonatomic) NSString* status; -@property(nonatomic) NSNumber* complete; +@property(nonatomic) NSString* count; @end diff --git a/samples/client/petstore/objc/SwaggerClient/SWGOrder.m b/samples/client/petstore/objc/SwaggerClient/SWGOrder.m index 83fe5741cd7f..8bf5f75c5ad6 100644 --- a/samples/client/petstore/objc/SwaggerClient/SWGOrder.m +++ b/samples/client/petstore/objc/SwaggerClient/SWGOrder.m @@ -8,7 +8,7 @@ */ + (JSONKeyMapper *)keyMapper { - return [[JSONKeyMapper alloc] initWithDictionary:@{ @"id": @"_id", @"petId": @"petId", @"quantity": @"quantity", @"shipDate": @"shipDate", @"status": @"status", @"complete": @"complete" }]; + return [[JSONKeyMapper alloc] initWithDictionary:@{ @"id": @"_id", @"petId": @"petId", @"quantity": @"quantity", @"shipDate": @"shipDate", @"status": @"status", @"count": @"count" }]; } /** @@ -18,7 +18,7 @@ */ + (BOOL)propertyIsOptional:(NSString *)propertyName { - NSArray *optionalProperties = @[@"_id", @"petId", @"quantity", @"shipDate", @"status", @"complete"]; + NSArray *optionalProperties = @[@"_id", @"petId", @"quantity", @"shipDate", @"status", @"count"]; if ([optionalProperties containsObject:propertyName]) { return YES; diff --git a/samples/client/petstore/objc/SwaggerClient/SWGPet.h b/samples/client/petstore/objc/SwaggerClient/SWGPet.h index 84f10969e5be..e340e0e2b86a 100644 --- a/samples/client/petstore/objc/SwaggerClient/SWGPet.h +++ b/samples/client/petstore/objc/SwaggerClient/SWGPet.h @@ -7,8 +7,8 @@ * Do not edit the class manually. */ -#import "SWGCategory.h" #import "SWGTag.h" +#import "SWGCategory.h" @protocol SWGPet diff --git a/samples/client/petstore/objc/SwaggerClient/SWGPetApi.m b/samples/client/petstore/objc/SwaggerClient/SWGPetApi.m index b890e03570fb..156700c9a769 100644 --- a/samples/client/petstore/objc/SwaggerClient/SWGPetApi.m +++ b/samples/client/petstore/objc/SwaggerClient/SWGPetApi.m @@ -450,7 +450,7 @@ static SWGPetApi* singletonAPI = nil; NSString *requestContentType = [SWGApiClient selectHeaderContentType:@[]]; // Authentication setting - NSArray *authSettings = @[@"petstore_auth", @"api_key"]; + NSArray *authSettings = @[@"api_key", @"petstore_auth"]; id bodyParam = nil; NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init]; diff --git a/samples/client/petstore/objc/SwaggerClient/SWGUserApi.h b/samples/client/petstore/objc/SwaggerClient/SWGUserApi.h index ec41ecd99078..21f314684fd7 100644 --- a/samples/client/petstore/objc/SwaggerClient/SWGUserApi.h +++ b/samples/client/petstore/objc/SwaggerClient/SWGUserApi.h @@ -99,7 +99,7 @@ /// Get user by user name /// /// -/// @param username The name that needs to be fetched. Use user1 for testing. +/// @param username The name that needs to be fetched. Use user1 for testing. /// /// /// @return SWGUser* diff --git a/samples/client/petstore/objc/SwaggerClient/SWGUserApi.m b/samples/client/petstore/objc/SwaggerClient/SWGUserApi.m index 5c3c313b2e23..75cf8d51b0ea 100644 --- a/samples/client/petstore/objc/SwaggerClient/SWGUserApi.m +++ b/samples/client/petstore/objc/SwaggerClient/SWGUserApi.m @@ -470,7 +470,7 @@ static SWGUserApi* singletonAPI = nil; /// /// Get user by user name /// -/// @param username The name that needs to be fetched. Use user1 for testing. +/// @param username The name that needs to be fetched. Use user1 for testing. /// /// @returns SWGUser* /// diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php index e8dea97be931..57af48845e18 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php @@ -135,9 +135,6 @@ class PetApi $httpBody = $formParams; // for HTTP post (form) } - - //TODO support oauth - // make the API Call try { @@ -200,9 +197,6 @@ class PetApi $httpBody = $formParams; // for HTTP post (form) } - - //TODO support oauth - // make the API Call try { @@ -264,9 +258,6 @@ class PetApi $httpBody = $formParams; // for HTTP post (form) } - - //TODO support oauth - // make the API Call try { @@ -340,9 +331,6 @@ class PetApi $httpBody = $formParams; // for HTTP post (form) } - - //TODO support oauth - // make the API Call try { @@ -424,16 +412,6 @@ class PetApi $httpBody = $formParams; // for HTTP post (form) } - - //TODO support oauth - - $apiKey = $this->apiClient->getApiKeyWithPrefix('api_key'); - if (isset($apiKey)) { - $headerParams['api_key'] = $apiKey; - } - - - // make the API Call try { @@ -523,9 +501,6 @@ class PetApi $httpBody = $formParams; // for HTTP post (form) } - - //TODO support oauth - // make the API Call try { @@ -599,9 +574,6 @@ class PetApi $httpBody = $formParams; // for HTTP post (form) } - - //TODO support oauth - // make the API Call try { @@ -679,9 +651,6 @@ class PetApi $httpBody = $formParams; // for HTTP post (form) } - - //TODO support oauth - // make the API Call try { diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php index b64b52d22252..1b0f9558695c 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php @@ -130,13 +130,6 @@ class StoreApi $httpBody = $formParams; // for HTTP post (form) } - $apiKey = $this->apiClient->getApiKeyWithPrefix('api_key'); - if (isset($apiKey)) { - $headerParams['api_key'] = $apiKey; - } - - - // make the API Call try { diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php b/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php index efdc1c896ab4..0d281b9d1fa3 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php @@ -193,7 +193,7 @@ class ObjectSerializer $deserialized = $values; } elseif ($class === '\DateTime') { $deserialized = new \DateTime($data); - } elseif (in_array($class, array('void', 'bool', 'string', 'double', 'byte', 'mixed', 'integer', 'float', 'int', 'DateTime', 'number', 'boolean', 'object'))) { + } elseif (in_array($class, array('integer', 'int', 'void', 'number', 'object', 'double', 'float', 'byte', 'DateTime', 'string', 'mixed', 'boolean', 'bool'))) { settype($data, $class); $deserialized = $data; } elseif ($class === '\SplFileObject') { From 5144c54895c04a0c58a5d25521721507c36bc2fd Mon Sep 17 00:00:00 2001 From: wing328 Date: Sat, 10 Oct 2015 22:47:24 +0800 Subject: [PATCH 02/17] add test case for global consumes and produces --- .../io/swagger/codegen/DefaultCodegen.java | 26 ++++++---- .../java/io/swagger/codegen/CodegenTest.java | 48 +++++++++++++++++++ 2 files changed, 66 insertions(+), 8 deletions(-) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java index d0185c0ad021..558f22bc0a09 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java @@ -902,15 +902,21 @@ public class DefaultCodegen { op.summary = escapeText(operation.getSummary()); op.notes = escapeText(operation.getDescription()); op.tags = operation.getTags(); + op.hasConsumes = false; + op.hasProduces = false; List consumes = new ArrayList(); - if (operation.getConsumes() != null && operation.getConsumes().size() > 0) { - // use consumes defined in the operation - consumes = operation.getConsumes(); + if (operation.getConsumes() != null) { + if (operation.getConsumes().size() > 0) { + // use consumes defined in the operation + consumes = operation.getConsumes(); + } else { + // empty list, do nothing to override global setting + } } else if (swagger != null && swagger.getConsumes() != null && swagger.getConsumes().size() > 0) { // use consumes defined globally consumes = swagger.getConsumes(); - LOGGER.debug("Using global consumes (" + swagger.getConsumes() + ") for " + op.operationId); + LOGGER.debug("No consumes defined in operation. Using global consumes (" + swagger.getConsumes() + ") for " + op.operationId); } // if "consumes" is defined (per operation or using global definition) @@ -933,13 +939,17 @@ public class DefaultCodegen { } List produces = new ArrayList(); - if (operation.getProduces() != null && operation.getProduces().size() > 0) { - // use produces defined in the operation - produces = operation.getProduces(); + if (operation.getProduces() != null) { + if (operation.getProduces().size() > 0) { + // use produces defined in the operation + produces = operation.getProduces(); + } else { + // empty list, do nothing to override global setting + } } else if (swagger != null && swagger.getProduces() != null && swagger.getProduces().size() > 0) { // use produces defined globally produces = swagger.getProduces(); - LOGGER.debug("Using global produces (" + swagger.getProduces() + ") for " + op.operationId); + LOGGER.debug("No produces defined in operation. Using global produces (" + swagger.getProduces() + ") for " + op.operationId); } // if "produces" is defined (per operation or using global definition) diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/CodegenTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/CodegenTest.java index ee70b427bfdf..68ebb349e6cf 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/CodegenTest.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/CodegenTest.java @@ -139,4 +139,52 @@ public class CodegenTest { Assert.assertTrue(op.bodyParam.isBinary); Assert.assertTrue(op.responses.get(0).isBinary); } + + @Test(description = "use operation consumes and producus") + public void localConsumesAndProducesTest() { + final Swagger model = new SwaggerParser().read("src/test/resources/2_0/globalConsumesAndProduces.json"); + final DefaultCodegen codegen = new DefaultCodegen(); + final String path = "/tests/localConsumesAndProduces"; + final Operation p = model.getPaths().get(path).getGet(); + CodegenOperation op = codegen.fromOperation(path, "get", p, model.getDefinitions(), model); + + Assert.assertTrue(op.hasConsumes); + Assert.assertEquals(op.consumes.size(), 1); + Assert.assertEquals(op.consumes.get(0).get("mediaType"), "application/json"); + Assert.assertTrue(op.hasProduces); + Assert.assertEquals(op.produces.size(), 1); + Assert.assertEquals(op.produces.get(0).get("mediaType"), "application/json"); + } + + @Test(description = "use spec consumes and producus") + public void globalConsumesAndProducesTest() { + final Swagger model = new SwaggerParser().read("src/test/resources/2_0/globalConsumesAndProduces.json"); + final DefaultCodegen codegen = new DefaultCodegen(); + final String path = "/tests/globalConsumesAndProduces"; + final Operation p = model.getPaths().get(path).getGet(); + CodegenOperation op = codegen.fromOperation(path, "get", p, model.getDefinitions(), model); + + Assert.assertTrue(op.hasConsumes); + Assert.assertEquals(op.consumes.size(), 1); + Assert.assertEquals(op.consumes.get(0).get("mediaType"), "application/global_consumes"); + Assert.assertTrue(op.hasProduces); + Assert.assertEquals(op.produces.size(), 1); + Assert.assertEquals(op.produces.get(0).get("mediaType"), "application/global_produces"); + } + + @Test(description = "use spec consumes and producus (reset in operation with empty array)") + public void localResetConsumesAndProducesTest() { + final Swagger model = new SwaggerParser().read("src/test/resources/2_0/globalConsumesAndProduces.json"); + final DefaultCodegen codegen = new DefaultCodegen(); + final String path = "/tests/localResetConsumesAndProduces"; + final Operation p = model.getPaths().get(path).getGet(); + CodegenOperation op = codegen.fromOperation(path, "get", p, model.getDefinitions(), model); + + Assert.assertNotNull(op); + Assert.assertFalse(op.hasConsumes); + Assert.assertNull(op.consumes); + Assert.assertFalse(op.hasProduces); + Assert.assertNull(op.produces); + + } } From 64fd94262f1b36a98e60328b4453290e4a370bb1 Mon Sep 17 00:00:00 2001 From: wing328 Date: Sat, 10 Oct 2015 22:54:13 +0800 Subject: [PATCH 03/17] add globalConsumesAndProduces.json --- .../2_0/globalConsumesAndProduces.json | 149 ++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 modules/swagger-codegen/src/test/resources/2_0/globalConsumesAndProduces.json diff --git a/modules/swagger-codegen/src/test/resources/2_0/globalConsumesAndProduces.json b/modules/swagger-codegen/src/test/resources/2_0/globalConsumesAndProduces.json new file mode 100644 index 000000000000..221d00b6dad9 --- /dev/null +++ b/modules/swagger-codegen/src/test/resources/2_0/globalConsumesAndProduces.json @@ -0,0 +1,149 @@ +{ + "swagger": "2.0", + "info": { + "description": "Spec for testing global consumes and produces", + "version": "1.0.0", + "title": "Swagger Petstore", + "termsOfService": "http://swagger.io/terms/", + "contact": { + "email": "apiteam@swagger.io" + }, + "license": { + "name": "Apache 2.0", + "url": "http://www.apache.org/licenses/LICENSE-2.0.html" + } + }, + "host": "petstore.swagger.io", + "basePath": "/v2", + "consumes": ["application/global_consumes"], + "produces": ["application/global_produces"], + "schemes": [ + "http" + ], + "paths": { + "/tests/localConsumesAndProduces": { + "get": { + "tags": [ + "tests" + ], + "summary": "Operation with local consumes and produces", + "description": "", + "operationId": "localConsumesAndProduces", + "produces": [ + "application/json" + ], + "consumes": [ + "application/json" + ], + "parameters": [ + ], + "responses": { + "200": { + "description": "successful operation. Returning a simple int.", + "schema": { + "type": "integer", + "format": "int64" + } + } + } + }, + "post": { + "tags": [ + "tests" + ], + "summary": "Operation with global consumes and produces", + "description": "", + "operationId": "globalConsumesAndProduces", + "parameters": [ + ], + "responses": { + "200": { + "description": "successful operation. Returning a simple int.", + "schema": { + "type": "integer", + "format": "int64" + } + } + } + } + }, + "/tests/globalConsumesAndProduces": { + "get": { + "tags": [ + "tests" + ], + "summary": "Operation with global consumes and produces", + "description": "", + "operationId": "globalConsumesAndProduces", + "parameters": [ + ], + "responses": { + "200": { + "description": "successful operation. Returning a simple int.", + "schema": { + "type": "integer", + "format": "int64" + } + } + } + } + }, + "/tests/localResetConsumesAndProduces": { + "get": { + "tags": [ + "tests" + ], + "summary": "Operation with local consumes and produces set to empty (reset)", + "description": "", + "operationId": "localResetConsumesAndProduces", + "parameters": [ + ], + "consumes": [], + "produces": [], + "responses": { + "200": { + "description": "successful operation. Returning a simple int.", + "schema": { + "type": "integer", + "format": "int64" + } + } + } + } + } + + }, + "securityDefinitions": { + "api_key": { + "type": "apiKey", + "name": "api_key", + "in": "header" + }, + "petstore_auth": { + "type": "oauth2", + "authorizationUrl": "http://petstore.swagger.io/api/oauth/dialog", + "flow": "implicit", + "scopes": { + "write:pets": "modify pets in your account", + "read:pets": "read your pets" + } + } + }, + "definitions": { + "CustomModel": { + "required": [ + "id" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string", + "example": "doggie" + } + } + } + } +} \ No newline at end of file From 6cc5a32d4013cd405aa83cfd377302273e3cbbbd Mon Sep 17 00:00:00 2001 From: wing328 Date: Sat, 10 Oct 2015 23:09:41 +0800 Subject: [PATCH 04/17] update objc sample --- .../petstore/objc/SwaggerClient/SWGApiClient.m | 15 ++++++++++----- .../objc/SwaggerClient/SWGConfiguration.m | 7 ------- .../petstore/objc/SwaggerClient/SWGOrder.h | 2 +- .../petstore/objc/SwaggerClient/SWGOrder.m | 4 ++-- .../petstore/objc/SwaggerClient/SWGPetApi.m | 16 ++++++++-------- .../petstore/objc/SwaggerClient/SWGStoreApi.m | 2 +- samples/client/petstore/ruby/lib/petstore.rb | 2 +- .../petstore/ruby/lib/petstore/api/pet_api.rb | 16 ++++++++-------- .../petstore/ruby/lib/petstore/api/store_api.rb | 2 +- .../petstore/ruby/lib/petstore/api/user_api.rb | 2 +- .../petstore/ruby/lib/petstore/api_client.rb | 2 -- .../petstore/ruby/lib/petstore/configuration.rb | 7 ------- 12 files changed, 33 insertions(+), 44 deletions(-) diff --git a/samples/client/petstore/objc/SwaggerClient/SWGApiClient.m b/samples/client/petstore/objc/SwaggerClient/SWGApiClient.m index fc3c79078625..dcd33575fc6f 100644 --- a/samples/client/petstore/objc/SwaggerClient/SWGApiClient.m +++ b/samples/client/petstore/objc/SwaggerClient/SWGApiClient.m @@ -311,9 +311,10 @@ static void (^reachabilityChangeBlock)(int); range:NSMakeRange(0, [class length])]; if (match) { + NSArray *dataArray = data; innerType = [class substringWithRange:[match rangeAtIndex:1]]; - resultArray = [NSMutableArray arrayWithCapacity:[data count]]; + resultArray = [NSMutableArray arrayWithCapacity:[dataArray count]]; [data enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { [resultArray addObject:[self deserialize:obj class:innerType]]; } @@ -332,9 +333,10 @@ static void (^reachabilityChangeBlock)(int); range:NSMakeRange(0, [class length])]; if (match) { + NSArray *dataArray = data; innerType = [class substringWithRange:[match rangeAtIndex:1]]; - resultArray = [NSMutableArray arrayWithCapacity:[data count]]; + resultArray = [NSMutableArray arrayWithCapacity:[dataArray count]]; [data enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { [resultArray addObject:[self deserialize:obj class:innerType]]; }]; @@ -352,9 +354,10 @@ static void (^reachabilityChangeBlock)(int); range:NSMakeRange(0, [class length])]; if (match) { + NSDictionary *dataDict = data; NSString *valueType = [class substringWithRange:[match rangeAtIndex:2]]; - resultDict = [NSMutableDictionary dictionaryWithCapacity:[data count]]; + resultDict = [NSMutableDictionary dictionaryWithCapacity:[dataDict count]]; [data enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { [resultDict setValue:[self deserialize:obj class:valueType] forKey:key]; }]; @@ -728,7 +731,8 @@ static void (^reachabilityChangeBlock)(int); return [object ISO8601String]; } else if ([object isKindOfClass:[NSArray class]]) { - NSMutableArray *sanitizedObjs = [NSMutableArray arrayWithCapacity:[object count]]; + NSArray *objectArray = object; + NSMutableArray *sanitizedObjs = [NSMutableArray arrayWithCapacity:[objectArray count]]; [object enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { if (obj) { [sanitizedObjs addObject:[self sanitizeForSerialization:obj]]; @@ -737,7 +741,8 @@ static void (^reachabilityChangeBlock)(int); return sanitizedObjs; } else if ([object isKindOfClass:[NSDictionary class]]) { - NSMutableDictionary *sanitizedObjs = [NSMutableDictionary dictionaryWithCapacity:[object count]]; + NSDictionary *objectDict = object; + NSMutableDictionary *sanitizedObjs = [NSMutableDictionary dictionaryWithCapacity:[objectDict count]]; [object enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { if (obj) { [sanitizedObjs setValue:[self sanitizeForSerialization:obj] forKey:key]; diff --git a/samples/client/petstore/objc/SwaggerClient/SWGConfiguration.m b/samples/client/petstore/objc/SwaggerClient/SWGConfiguration.m index 16ce311c59ed..3f1f926b3312 100644 --- a/samples/client/petstore/objc/SwaggerClient/SWGConfiguration.m +++ b/samples/client/petstore/objc/SwaggerClient/SWGConfiguration.m @@ -107,13 +107,6 @@ - (NSDictionary *) authSettings { return @{ - @"api_key": - @{ - @"type": @"api_key", - @"in": @"header", - @"key": @"api_key", - @"value": [self getApiKeyWithPrefix:@"api_key"] - }, }; } diff --git a/samples/client/petstore/objc/SwaggerClient/SWGOrder.h b/samples/client/petstore/objc/SwaggerClient/SWGOrder.h index 4b132c57be50..48a7cf0d6c1f 100644 --- a/samples/client/petstore/objc/SwaggerClient/SWGOrder.h +++ b/samples/client/petstore/objc/SwaggerClient/SWGOrder.h @@ -26,6 +26,6 @@ */ @property(nonatomic) NSString* status; -@property(nonatomic) NSString* count; +@property(nonatomic) NSNumber* complete; @end diff --git a/samples/client/petstore/objc/SwaggerClient/SWGOrder.m b/samples/client/petstore/objc/SwaggerClient/SWGOrder.m index 8bf5f75c5ad6..83fe5741cd7f 100644 --- a/samples/client/petstore/objc/SwaggerClient/SWGOrder.m +++ b/samples/client/petstore/objc/SwaggerClient/SWGOrder.m @@ -8,7 +8,7 @@ */ + (JSONKeyMapper *)keyMapper { - return [[JSONKeyMapper alloc] initWithDictionary:@{ @"id": @"_id", @"petId": @"petId", @"quantity": @"quantity", @"shipDate": @"shipDate", @"status": @"status", @"count": @"count" }]; + return [[JSONKeyMapper alloc] initWithDictionary:@{ @"id": @"_id", @"petId": @"petId", @"quantity": @"quantity", @"shipDate": @"shipDate", @"status": @"status", @"complete": @"complete" }]; } /** @@ -18,7 +18,7 @@ */ + (BOOL)propertyIsOptional:(NSString *)propertyName { - NSArray *optionalProperties = @[@"_id", @"petId", @"quantity", @"shipDate", @"status", @"count"]; + NSArray *optionalProperties = @[@"_id", @"petId", @"quantity", @"shipDate", @"status", @"complete"]; if ([optionalProperties containsObject:propertyName]) { return YES; diff --git a/samples/client/petstore/objc/SwaggerClient/SWGPetApi.m b/samples/client/petstore/objc/SwaggerClient/SWGPetApi.m index 156700c9a769..64ff58e31e6b 100644 --- a/samples/client/petstore/objc/SwaggerClient/SWGPetApi.m +++ b/samples/client/petstore/objc/SwaggerClient/SWGPetApi.m @@ -118,7 +118,7 @@ static SWGPetApi* singletonAPI = nil; NSString *requestContentType = [SWGApiClient selectHeaderContentType:@[@"application/json", @"application/xml"]]; // Authentication setting - NSArray *authSettings = @[@"petstore_auth"]; + NSArray *authSettings = @[]; id bodyParam = nil; NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init]; @@ -196,7 +196,7 @@ static SWGPetApi* singletonAPI = nil; NSString *requestContentType = [SWGApiClient selectHeaderContentType:@[@"application/json", @"application/xml"]]; // Authentication setting - NSArray *authSettings = @[@"petstore_auth"]; + NSArray *authSettings = @[]; id bodyParam = nil; NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init]; @@ -280,7 +280,7 @@ static SWGPetApi* singletonAPI = nil; NSString *requestContentType = [SWGApiClient selectHeaderContentType:@[]]; // Authentication setting - NSArray *authSettings = @[@"petstore_auth"]; + NSArray *authSettings = @[]; id bodyParam = nil; NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init]; @@ -364,7 +364,7 @@ static SWGPetApi* singletonAPI = nil; NSString *requestContentType = [SWGApiClient selectHeaderContentType:@[]]; // Authentication setting - NSArray *authSettings = @[@"petstore_auth"]; + NSArray *authSettings = @[]; id bodyParam = nil; NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init]; @@ -450,7 +450,7 @@ static SWGPetApi* singletonAPI = nil; NSString *requestContentType = [SWGApiClient selectHeaderContentType:@[]]; // Authentication setting - NSArray *authSettings = @[@"api_key", @"petstore_auth"]; + NSArray *authSettings = @[]; id bodyParam = nil; NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init]; @@ -542,7 +542,7 @@ static SWGPetApi* singletonAPI = nil; NSString *requestContentType = [SWGApiClient selectHeaderContentType:@[@"application/x-www-form-urlencoded"]]; // Authentication setting - NSArray *authSettings = @[@"petstore_auth"]; + NSArray *authSettings = @[]; id bodyParam = nil; NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init]; @@ -646,7 +646,7 @@ static SWGPetApi* singletonAPI = nil; NSString *requestContentType = [SWGApiClient selectHeaderContentType:@[]]; // Authentication setting - NSArray *authSettings = @[@"petstore_auth"]; + NSArray *authSettings = @[]; id bodyParam = nil; NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init]; @@ -738,7 +738,7 @@ static SWGPetApi* singletonAPI = nil; NSString *requestContentType = [SWGApiClient selectHeaderContentType:@[@"multipart/form-data"]]; // Authentication setting - NSArray *authSettings = @[@"petstore_auth"]; + NSArray *authSettings = @[]; id bodyParam = nil; NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init]; diff --git a/samples/client/petstore/objc/SwaggerClient/SWGStoreApi.m b/samples/client/petstore/objc/SwaggerClient/SWGStoreApi.m index 5fdf86b43aff..8450022164ce 100644 --- a/samples/client/petstore/objc/SwaggerClient/SWGStoreApi.m +++ b/samples/client/petstore/objc/SwaggerClient/SWGStoreApi.m @@ -115,7 +115,7 @@ static SWGStoreApi* singletonAPI = nil; NSString *requestContentType = [SWGApiClient selectHeaderContentType:@[]]; // Authentication setting - NSArray *authSettings = @[@"api_key"]; + NSArray *authSettings = @[]; id bodyParam = nil; NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init]; diff --git a/samples/client/petstore/ruby/lib/petstore.rb b/samples/client/petstore/ruby/lib/petstore.rb index c13e99f29fc4..61640d687ac7 100644 --- a/samples/client/petstore/ruby/lib/petstore.rb +++ b/samples/client/petstore/ruby/lib/petstore.rb @@ -14,8 +14,8 @@ require 'petstore/models/order' # APIs require 'petstore/api/user_api' -require 'petstore/api/store_api' require 'petstore/api/pet_api' +require 'petstore/api/store_api' module Petstore class << self diff --git a/samples/client/petstore/ruby/lib/petstore/api/pet_api.rb b/samples/client/petstore/ruby/lib/petstore/api/pet_api.rb index a9d30a00147c..bb1b66c19a40 100644 --- a/samples/client/petstore/ruby/lib/petstore/api/pet_api.rb +++ b/samples/client/petstore/ruby/lib/petstore/api/pet_api.rb @@ -42,7 +42,7 @@ module Petstore post_body = @api_client.object_to_http_body(opts[:'body']) - auth_names = ['petstore_auth'] + auth_names = [] @api_client.call_api(:PUT, path, :header_params => header_params, :query_params => query_params, @@ -89,7 +89,7 @@ module Petstore post_body = @api_client.object_to_http_body(opts[:'body']) - auth_names = ['petstore_auth'] + auth_names = [] @api_client.call_api(:POST, path, :header_params => header_params, :query_params => query_params, @@ -137,7 +137,7 @@ module Petstore post_body = nil - auth_names = ['petstore_auth'] + auth_names = [] result = @api_client.call_api(:GET, path, :header_params => header_params, :query_params => query_params, @@ -186,7 +186,7 @@ module Petstore post_body = nil - auth_names = ['petstore_auth'] + auth_names = [] result = @api_client.call_api(:GET, path, :header_params => header_params, :query_params => query_params, @@ -237,7 +237,7 @@ module Petstore post_body = nil - auth_names = ['petstore_auth', 'api_key'] + auth_names = [] result = @api_client.call_api(:GET, path, :header_params => header_params, :query_params => query_params, @@ -292,7 +292,7 @@ module Petstore post_body = nil - auth_names = ['petstore_auth'] + auth_names = [] @api_client.call_api(:POST, path, :header_params => header_params, :query_params => query_params, @@ -344,7 +344,7 @@ module Petstore post_body = nil - auth_names = ['petstore_auth'] + auth_names = [] @api_client.call_api(:DELETE, path, :header_params => header_params, :query_params => query_params, @@ -398,7 +398,7 @@ module Petstore post_body = nil - auth_names = ['petstore_auth'] + auth_names = [] @api_client.call_api(:POST, path, :header_params => header_params, :query_params => query_params, diff --git a/samples/client/petstore/ruby/lib/petstore/api/store_api.rb b/samples/client/petstore/ruby/lib/petstore/api/store_api.rb index 235ff1c41060..b33aa87a505b 100644 --- a/samples/client/petstore/ruby/lib/petstore/api/store_api.rb +++ b/samples/client/petstore/ruby/lib/petstore/api/store_api.rb @@ -41,7 +41,7 @@ module Petstore post_body = nil - auth_names = ['api_key'] + auth_names = [] result = @api_client.call_api(:GET, path, :header_params => header_params, :query_params => query_params, diff --git a/samples/client/petstore/ruby/lib/petstore/api/user_api.rb b/samples/client/petstore/ruby/lib/petstore/api/user_api.rb index f4672e2a3585..7f546330f3aa 100644 --- a/samples/client/petstore/ruby/lib/petstore/api/user_api.rb +++ b/samples/client/petstore/ruby/lib/petstore/api/user_api.rb @@ -248,7 +248,7 @@ module Petstore # Get user by user name # - # @param username The name that needs to be fetched. Use user1 for testing. + # @param username The name that needs to be fetched. Use user1 for testing. # @param [Hash] opts the optional parameters # @return [User] def get_user_by_name(username, opts = {}) diff --git a/samples/client/petstore/ruby/lib/petstore/api_client.rb b/samples/client/petstore/ruby/lib/petstore/api_client.rb index 4f747bcd6a11..77e9c4487183 100644 --- a/samples/client/petstore/ruby/lib/petstore/api_client.rb +++ b/samples/client/petstore/ruby/lib/petstore/api_client.rb @@ -62,8 +62,6 @@ module Petstore form_params = opts[:form_params] || {} - update_params_for_auth! header_params, query_params, opts[:auth_names] - req_opts = { :method => http_method, diff --git a/samples/client/petstore/ruby/lib/petstore/configuration.rb b/samples/client/petstore/ruby/lib/petstore/configuration.rb index 008be48ee4da..5e333ee79efe 100644 --- a/samples/client/petstore/ruby/lib/petstore/configuration.rb +++ b/samples/client/petstore/ruby/lib/petstore/configuration.rb @@ -160,13 +160,6 @@ module Petstore # Returns Auth Settings hash for api client. def auth_settings { - 'api_key' => - { - type: 'api_key', - in: 'header', - key: 'api_key', - value: api_key_with_prefix('api_key') - }, } end end From 9ecb2e92ae83e05eac75552ae3844faf056f335a Mon Sep 17 00:00:00 2001 From: wing328 Date: Sat, 10 Oct 2015 23:13:26 +0800 Subject: [PATCH 05/17] restore sample files for objc, php and ruby --- .../petstore/objc/SwaggerClient.podspec | 8 ++--- .../objc/SwaggerClient/SWGApiClient.m | 15 +++------ .../objc/SwaggerClient/SWGConfiguration.m | 7 +++++ .../petstore/objc/SwaggerClient/SWGPet.h | 2 +- .../petstore/objc/SwaggerClient/SWGPetApi.m | 16 +++++----- .../petstore/objc/SwaggerClient/SWGStoreApi.m | 2 +- .../petstore/objc/SwaggerClient/SWGUserApi.h | 2 +- .../petstore/objc/SwaggerClient/SWGUserApi.m | 2 +- .../php/SwaggerClient-php/lib/Api/PetApi.php | 31 +++++++++++++++++++ .../SwaggerClient-php/lib/Api/StoreApi.php | 7 +++++ .../lib/ObjectSerializer.php | 2 +- samples/client/petstore/ruby/lib/petstore.rb | 2 +- .../petstore/ruby/lib/petstore/api/pet_api.rb | 16 +++++----- .../ruby/lib/petstore/api/store_api.rb | 2 +- .../ruby/lib/petstore/api/user_api.rb | 2 +- .../petstore/ruby/lib/petstore/api_client.rb | 2 ++ .../ruby/lib/petstore/configuration.rb | 7 +++++ 17 files changed, 87 insertions(+), 38 deletions(-) diff --git a/samples/client/petstore/objc/SwaggerClient.podspec b/samples/client/petstore/objc/SwaggerClient.podspec index 0afb511073c3..4445bc52ad23 100644 --- a/samples/client/petstore/objc/SwaggerClient.podspec +++ b/samples/client/petstore/objc/SwaggerClient.podspec @@ -21,10 +21,10 @@ Pod::Spec.new do |s| s.framework = 'SystemConfiguration' - s.homepage = "https://github.com/swagger-api/swagger-codegen" - s.license = "MIT" - s.source = { :git => "https://github.com/swagger-api/swagger-codegen.git", :tag => "#{s.version}" } - s.author = { "Swagger" => "apiteam@swagger.io" } + s.homepage = "" + s.license = "" + s.source = { :git => ".git", :tag => "#{s.version}" } + s.author = { "" => "" } s.source_files = 'SwaggerClient/**/*' s.public_header_files = 'SwaggerClient/**/*.h' diff --git a/samples/client/petstore/objc/SwaggerClient/SWGApiClient.m b/samples/client/petstore/objc/SwaggerClient/SWGApiClient.m index dcd33575fc6f..fc3c79078625 100644 --- a/samples/client/petstore/objc/SwaggerClient/SWGApiClient.m +++ b/samples/client/petstore/objc/SwaggerClient/SWGApiClient.m @@ -311,10 +311,9 @@ static void (^reachabilityChangeBlock)(int); range:NSMakeRange(0, [class length])]; if (match) { - NSArray *dataArray = data; innerType = [class substringWithRange:[match rangeAtIndex:1]]; - resultArray = [NSMutableArray arrayWithCapacity:[dataArray count]]; + resultArray = [NSMutableArray arrayWithCapacity:[data count]]; [data enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { [resultArray addObject:[self deserialize:obj class:innerType]]; } @@ -333,10 +332,9 @@ static void (^reachabilityChangeBlock)(int); range:NSMakeRange(0, [class length])]; if (match) { - NSArray *dataArray = data; innerType = [class substringWithRange:[match rangeAtIndex:1]]; - resultArray = [NSMutableArray arrayWithCapacity:[dataArray count]]; + resultArray = [NSMutableArray arrayWithCapacity:[data count]]; [data enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { [resultArray addObject:[self deserialize:obj class:innerType]]; }]; @@ -354,10 +352,9 @@ static void (^reachabilityChangeBlock)(int); range:NSMakeRange(0, [class length])]; if (match) { - NSDictionary *dataDict = data; NSString *valueType = [class substringWithRange:[match rangeAtIndex:2]]; - resultDict = [NSMutableDictionary dictionaryWithCapacity:[dataDict count]]; + resultDict = [NSMutableDictionary dictionaryWithCapacity:[data count]]; [data enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { [resultDict setValue:[self deserialize:obj class:valueType] forKey:key]; }]; @@ -731,8 +728,7 @@ static void (^reachabilityChangeBlock)(int); return [object ISO8601String]; } else if ([object isKindOfClass:[NSArray class]]) { - NSArray *objectArray = object; - NSMutableArray *sanitizedObjs = [NSMutableArray arrayWithCapacity:[objectArray count]]; + NSMutableArray *sanitizedObjs = [NSMutableArray arrayWithCapacity:[object count]]; [object enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { if (obj) { [sanitizedObjs addObject:[self sanitizeForSerialization:obj]]; @@ -741,8 +737,7 @@ static void (^reachabilityChangeBlock)(int); return sanitizedObjs; } else if ([object isKindOfClass:[NSDictionary class]]) { - NSDictionary *objectDict = object; - NSMutableDictionary *sanitizedObjs = [NSMutableDictionary dictionaryWithCapacity:[objectDict count]]; + NSMutableDictionary *sanitizedObjs = [NSMutableDictionary dictionaryWithCapacity:[object count]]; [object enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { if (obj) { [sanitizedObjs setValue:[self sanitizeForSerialization:obj] forKey:key]; diff --git a/samples/client/petstore/objc/SwaggerClient/SWGConfiguration.m b/samples/client/petstore/objc/SwaggerClient/SWGConfiguration.m index 3f1f926b3312..16ce311c59ed 100644 --- a/samples/client/petstore/objc/SwaggerClient/SWGConfiguration.m +++ b/samples/client/petstore/objc/SwaggerClient/SWGConfiguration.m @@ -107,6 +107,13 @@ - (NSDictionary *) authSettings { return @{ + @"api_key": + @{ + @"type": @"api_key", + @"in": @"header", + @"key": @"api_key", + @"value": [self getApiKeyWithPrefix:@"api_key"] + }, }; } diff --git a/samples/client/petstore/objc/SwaggerClient/SWGPet.h b/samples/client/petstore/objc/SwaggerClient/SWGPet.h index e340e0e2b86a..84f10969e5be 100644 --- a/samples/client/petstore/objc/SwaggerClient/SWGPet.h +++ b/samples/client/petstore/objc/SwaggerClient/SWGPet.h @@ -7,8 +7,8 @@ * Do not edit the class manually. */ -#import "SWGTag.h" #import "SWGCategory.h" +#import "SWGTag.h" @protocol SWGPet diff --git a/samples/client/petstore/objc/SwaggerClient/SWGPetApi.m b/samples/client/petstore/objc/SwaggerClient/SWGPetApi.m index 64ff58e31e6b..b890e03570fb 100644 --- a/samples/client/petstore/objc/SwaggerClient/SWGPetApi.m +++ b/samples/client/petstore/objc/SwaggerClient/SWGPetApi.m @@ -118,7 +118,7 @@ static SWGPetApi* singletonAPI = nil; NSString *requestContentType = [SWGApiClient selectHeaderContentType:@[@"application/json", @"application/xml"]]; // Authentication setting - NSArray *authSettings = @[]; + NSArray *authSettings = @[@"petstore_auth"]; id bodyParam = nil; NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init]; @@ -196,7 +196,7 @@ static SWGPetApi* singletonAPI = nil; NSString *requestContentType = [SWGApiClient selectHeaderContentType:@[@"application/json", @"application/xml"]]; // Authentication setting - NSArray *authSettings = @[]; + NSArray *authSettings = @[@"petstore_auth"]; id bodyParam = nil; NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init]; @@ -280,7 +280,7 @@ static SWGPetApi* singletonAPI = nil; NSString *requestContentType = [SWGApiClient selectHeaderContentType:@[]]; // Authentication setting - NSArray *authSettings = @[]; + NSArray *authSettings = @[@"petstore_auth"]; id bodyParam = nil; NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init]; @@ -364,7 +364,7 @@ static SWGPetApi* singletonAPI = nil; NSString *requestContentType = [SWGApiClient selectHeaderContentType:@[]]; // Authentication setting - NSArray *authSettings = @[]; + NSArray *authSettings = @[@"petstore_auth"]; id bodyParam = nil; NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init]; @@ -450,7 +450,7 @@ static SWGPetApi* singletonAPI = nil; NSString *requestContentType = [SWGApiClient selectHeaderContentType:@[]]; // Authentication setting - NSArray *authSettings = @[]; + NSArray *authSettings = @[@"petstore_auth", @"api_key"]; id bodyParam = nil; NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init]; @@ -542,7 +542,7 @@ static SWGPetApi* singletonAPI = nil; NSString *requestContentType = [SWGApiClient selectHeaderContentType:@[@"application/x-www-form-urlencoded"]]; // Authentication setting - NSArray *authSettings = @[]; + NSArray *authSettings = @[@"petstore_auth"]; id bodyParam = nil; NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init]; @@ -646,7 +646,7 @@ static SWGPetApi* singletonAPI = nil; NSString *requestContentType = [SWGApiClient selectHeaderContentType:@[]]; // Authentication setting - NSArray *authSettings = @[]; + NSArray *authSettings = @[@"petstore_auth"]; id bodyParam = nil; NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init]; @@ -738,7 +738,7 @@ static SWGPetApi* singletonAPI = nil; NSString *requestContentType = [SWGApiClient selectHeaderContentType:@[@"multipart/form-data"]]; // Authentication setting - NSArray *authSettings = @[]; + NSArray *authSettings = @[@"petstore_auth"]; id bodyParam = nil; NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init]; diff --git a/samples/client/petstore/objc/SwaggerClient/SWGStoreApi.m b/samples/client/petstore/objc/SwaggerClient/SWGStoreApi.m index 8450022164ce..5fdf86b43aff 100644 --- a/samples/client/petstore/objc/SwaggerClient/SWGStoreApi.m +++ b/samples/client/petstore/objc/SwaggerClient/SWGStoreApi.m @@ -115,7 +115,7 @@ static SWGStoreApi* singletonAPI = nil; NSString *requestContentType = [SWGApiClient selectHeaderContentType:@[]]; // Authentication setting - NSArray *authSettings = @[]; + NSArray *authSettings = @[@"api_key"]; id bodyParam = nil; NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init]; diff --git a/samples/client/petstore/objc/SwaggerClient/SWGUserApi.h b/samples/client/petstore/objc/SwaggerClient/SWGUserApi.h index 21f314684fd7..ec41ecd99078 100644 --- a/samples/client/petstore/objc/SwaggerClient/SWGUserApi.h +++ b/samples/client/petstore/objc/SwaggerClient/SWGUserApi.h @@ -99,7 +99,7 @@ /// Get user by user name /// /// -/// @param username The name that needs to be fetched. Use user1 for testing. +/// @param username The name that needs to be fetched. Use user1 for testing. /// /// /// @return SWGUser* diff --git a/samples/client/petstore/objc/SwaggerClient/SWGUserApi.m b/samples/client/petstore/objc/SwaggerClient/SWGUserApi.m index 75cf8d51b0ea..5c3c313b2e23 100644 --- a/samples/client/petstore/objc/SwaggerClient/SWGUserApi.m +++ b/samples/client/petstore/objc/SwaggerClient/SWGUserApi.m @@ -470,7 +470,7 @@ static SWGUserApi* singletonAPI = nil; /// /// Get user by user name /// -/// @param username The name that needs to be fetched. Use user1 for testing. +/// @param username The name that needs to be fetched. Use user1 for testing. /// /// @returns SWGUser* /// diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php index 57af48845e18..e8dea97be931 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php @@ -135,6 +135,9 @@ class PetApi $httpBody = $formParams; // for HTTP post (form) } + + //TODO support oauth + // make the API Call try { @@ -197,6 +200,9 @@ class PetApi $httpBody = $formParams; // for HTTP post (form) } + + //TODO support oauth + // make the API Call try { @@ -258,6 +264,9 @@ class PetApi $httpBody = $formParams; // for HTTP post (form) } + + //TODO support oauth + // make the API Call try { @@ -331,6 +340,9 @@ class PetApi $httpBody = $formParams; // for HTTP post (form) } + + //TODO support oauth + // make the API Call try { @@ -412,6 +424,16 @@ class PetApi $httpBody = $formParams; // for HTTP post (form) } + + //TODO support oauth + + $apiKey = $this->apiClient->getApiKeyWithPrefix('api_key'); + if (isset($apiKey)) { + $headerParams['api_key'] = $apiKey; + } + + + // make the API Call try { @@ -501,6 +523,9 @@ class PetApi $httpBody = $formParams; // for HTTP post (form) } + + //TODO support oauth + // make the API Call try { @@ -574,6 +599,9 @@ class PetApi $httpBody = $formParams; // for HTTP post (form) } + + //TODO support oauth + // make the API Call try { @@ -651,6 +679,9 @@ class PetApi $httpBody = $formParams; // for HTTP post (form) } + + //TODO support oauth + // make the API Call try { diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php index 1b0f9558695c..b64b52d22252 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php @@ -130,6 +130,13 @@ class StoreApi $httpBody = $formParams; // for HTTP post (form) } + $apiKey = $this->apiClient->getApiKeyWithPrefix('api_key'); + if (isset($apiKey)) { + $headerParams['api_key'] = $apiKey; + } + + + // make the API Call try { diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php b/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php index 0d281b9d1fa3..efdc1c896ab4 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php @@ -193,7 +193,7 @@ class ObjectSerializer $deserialized = $values; } elseif ($class === '\DateTime') { $deserialized = new \DateTime($data); - } elseif (in_array($class, array('integer', 'int', 'void', 'number', 'object', 'double', 'float', 'byte', 'DateTime', 'string', 'mixed', 'boolean', 'bool'))) { + } elseif (in_array($class, array('void', 'bool', 'string', 'double', 'byte', 'mixed', 'integer', 'float', 'int', 'DateTime', 'number', 'boolean', 'object'))) { settype($data, $class); $deserialized = $data; } elseif ($class === '\SplFileObject') { diff --git a/samples/client/petstore/ruby/lib/petstore.rb b/samples/client/petstore/ruby/lib/petstore.rb index 61640d687ac7..c13e99f29fc4 100644 --- a/samples/client/petstore/ruby/lib/petstore.rb +++ b/samples/client/petstore/ruby/lib/petstore.rb @@ -14,8 +14,8 @@ require 'petstore/models/order' # APIs require 'petstore/api/user_api' -require 'petstore/api/pet_api' require 'petstore/api/store_api' +require 'petstore/api/pet_api' module Petstore class << self diff --git a/samples/client/petstore/ruby/lib/petstore/api/pet_api.rb b/samples/client/petstore/ruby/lib/petstore/api/pet_api.rb index bb1b66c19a40..a9d30a00147c 100644 --- a/samples/client/petstore/ruby/lib/petstore/api/pet_api.rb +++ b/samples/client/petstore/ruby/lib/petstore/api/pet_api.rb @@ -42,7 +42,7 @@ module Petstore post_body = @api_client.object_to_http_body(opts[:'body']) - auth_names = [] + auth_names = ['petstore_auth'] @api_client.call_api(:PUT, path, :header_params => header_params, :query_params => query_params, @@ -89,7 +89,7 @@ module Petstore post_body = @api_client.object_to_http_body(opts[:'body']) - auth_names = [] + auth_names = ['petstore_auth'] @api_client.call_api(:POST, path, :header_params => header_params, :query_params => query_params, @@ -137,7 +137,7 @@ module Petstore post_body = nil - auth_names = [] + auth_names = ['petstore_auth'] result = @api_client.call_api(:GET, path, :header_params => header_params, :query_params => query_params, @@ -186,7 +186,7 @@ module Petstore post_body = nil - auth_names = [] + auth_names = ['petstore_auth'] result = @api_client.call_api(:GET, path, :header_params => header_params, :query_params => query_params, @@ -237,7 +237,7 @@ module Petstore post_body = nil - auth_names = [] + auth_names = ['petstore_auth', 'api_key'] result = @api_client.call_api(:GET, path, :header_params => header_params, :query_params => query_params, @@ -292,7 +292,7 @@ module Petstore post_body = nil - auth_names = [] + auth_names = ['petstore_auth'] @api_client.call_api(:POST, path, :header_params => header_params, :query_params => query_params, @@ -344,7 +344,7 @@ module Petstore post_body = nil - auth_names = [] + auth_names = ['petstore_auth'] @api_client.call_api(:DELETE, path, :header_params => header_params, :query_params => query_params, @@ -398,7 +398,7 @@ module Petstore post_body = nil - auth_names = [] + auth_names = ['petstore_auth'] @api_client.call_api(:POST, path, :header_params => header_params, :query_params => query_params, diff --git a/samples/client/petstore/ruby/lib/petstore/api/store_api.rb b/samples/client/petstore/ruby/lib/petstore/api/store_api.rb index b33aa87a505b..235ff1c41060 100644 --- a/samples/client/petstore/ruby/lib/petstore/api/store_api.rb +++ b/samples/client/petstore/ruby/lib/petstore/api/store_api.rb @@ -41,7 +41,7 @@ module Petstore post_body = nil - auth_names = [] + auth_names = ['api_key'] result = @api_client.call_api(:GET, path, :header_params => header_params, :query_params => query_params, diff --git a/samples/client/petstore/ruby/lib/petstore/api/user_api.rb b/samples/client/petstore/ruby/lib/petstore/api/user_api.rb index 7f546330f3aa..f4672e2a3585 100644 --- a/samples/client/petstore/ruby/lib/petstore/api/user_api.rb +++ b/samples/client/petstore/ruby/lib/petstore/api/user_api.rb @@ -248,7 +248,7 @@ module Petstore # Get user by user name # - # @param username The name that needs to be fetched. Use user1 for testing. + # @param username The name that needs to be fetched. Use user1 for testing. # @param [Hash] opts the optional parameters # @return [User] def get_user_by_name(username, opts = {}) diff --git a/samples/client/petstore/ruby/lib/petstore/api_client.rb b/samples/client/petstore/ruby/lib/petstore/api_client.rb index 77e9c4487183..4f747bcd6a11 100644 --- a/samples/client/petstore/ruby/lib/petstore/api_client.rb +++ b/samples/client/petstore/ruby/lib/petstore/api_client.rb @@ -62,6 +62,8 @@ module Petstore form_params = opts[:form_params] || {} + update_params_for_auth! header_params, query_params, opts[:auth_names] + req_opts = { :method => http_method, diff --git a/samples/client/petstore/ruby/lib/petstore/configuration.rb b/samples/client/petstore/ruby/lib/petstore/configuration.rb index 5e333ee79efe..008be48ee4da 100644 --- a/samples/client/petstore/ruby/lib/petstore/configuration.rb +++ b/samples/client/petstore/ruby/lib/petstore/configuration.rb @@ -160,6 +160,13 @@ module Petstore # Returns Auth Settings hash for api client. def auth_settings { + 'api_key' => + { + type: 'api_key', + in: 'header', + key: 'api_key', + value: api_key_with_prefix('api_key') + }, } end end From 5cd01af35059c4424040aa5c558e2f58dbdaaa31 Mon Sep 17 00:00:00 2001 From: wing328 Date: Sat, 10 Oct 2015 23:22:42 +0800 Subject: [PATCH 06/17] fix typo in test cases --- .../src/test/java/io/swagger/codegen/CodegenTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/CodegenTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/CodegenTest.java index 68ebb349e6cf..0fa8953e7bf5 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/CodegenTest.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/CodegenTest.java @@ -140,7 +140,7 @@ public class CodegenTest { Assert.assertTrue(op.responses.get(0).isBinary); } - @Test(description = "use operation consumes and producus") + @Test(description = "use operation consumes and produces") public void localConsumesAndProducesTest() { final Swagger model = new SwaggerParser().read("src/test/resources/2_0/globalConsumesAndProduces.json"); final DefaultCodegen codegen = new DefaultCodegen(); @@ -156,7 +156,7 @@ public class CodegenTest { Assert.assertEquals(op.produces.get(0).get("mediaType"), "application/json"); } - @Test(description = "use spec consumes and producus") + @Test(description = "use spec consumes and produces") public void globalConsumesAndProducesTest() { final Swagger model = new SwaggerParser().read("src/test/resources/2_0/globalConsumesAndProduces.json"); final DefaultCodegen codegen = new DefaultCodegen(); @@ -172,7 +172,7 @@ public class CodegenTest { Assert.assertEquals(op.produces.get(0).get("mediaType"), "application/global_produces"); } - @Test(description = "use spec consumes and producus (reset in operation with empty array)") + @Test(description = "use operation consumes and produces (reset in operation with empty array)") public void localResetConsumesAndProducesTest() { final Swagger model = new SwaggerParser().read("src/test/resources/2_0/globalConsumesAndProduces.json"); final DefaultCodegen codegen = new DefaultCodegen(); From 00517a1ad3a5f98e513064f9186197b5628b6b57 Mon Sep 17 00:00:00 2001 From: wing328 Date: Sat, 10 Oct 2015 23:27:21 +0800 Subject: [PATCH 07/17] remove unused operation in test json file --- .../2_0/globalConsumesAndProduces.json | 23 ++----------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/modules/swagger-codegen/src/test/resources/2_0/globalConsumesAndProduces.json b/modules/swagger-codegen/src/test/resources/2_0/globalConsumesAndProduces.json index 221d00b6dad9..520218ed707e 100644 --- a/modules/swagger-codegen/src/test/resources/2_0/globalConsumesAndProduces.json +++ b/modules/swagger-codegen/src/test/resources/2_0/globalConsumesAndProduces.json @@ -46,26 +46,7 @@ } } } - }, - "post": { - "tags": [ - "tests" - ], - "summary": "Operation with global consumes and produces", - "description": "", - "operationId": "globalConsumesAndProduces", - "parameters": [ - ], - "responses": { - "200": { - "description": "successful operation. Returning a simple int.", - "schema": { - "type": "integer", - "format": "int64" - } - } - } - } + } }, "/tests/globalConsumesAndProduces": { "get": { @@ -146,4 +127,4 @@ } } } -} \ No newline at end of file +} From 6fd54d52858142071c5fd5c77e1524aa147a2848 Mon Sep 17 00:00:00 2001 From: Eran Stiller Date: Mon, 12 Oct 2015 08:51:00 +0300 Subject: [PATCH 08/17] Fix bug in handling 204 responses --- .../src/main/resources/android-java/apiInvoker.mustache | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/swagger-codegen/src/main/resources/android-java/apiInvoker.mustache b/modules/swagger-codegen/src/main/resources/android-java/apiInvoker.mustache index ac24335df186..b5f0ae7a6623 100644 --- a/modules/swagger-codegen/src/main/resources/android-java/apiInvoker.mustache +++ b/modules/swagger-codegen/src/main/resources/android-java/apiInvoker.mustache @@ -365,8 +365,10 @@ public class ApiInvoker { int code = response.getStatusLine().getStatusCode(); String responseString = null; - if(code == 204) + if(code == 204) { responseString = ""; + return responseString; + } else if(code >= 200 && code < 300) { if(response.getEntity() != null) { HttpEntity resEntity = response.getEntity(); From 15f5eae2a80da4c658b466da04d11d5d51532cee Mon Sep 17 00:00:00 2001 From: Eran Stiller Date: Mon, 12 Oct 2015 08:51:48 +0300 Subject: [PATCH 09/17] Regenerate Android-Java sample --- .../client/petstore/android-java/build.gradle | 6 ++ .../java/io/swagger/client/ApiInvoker.java | 4 +- .../main/java/io/swagger/client/JsonUtil.java | 32 +++++---- .../java/io/swagger/client/api/PetApi.java | 42 +++++++++--- .../java/io/swagger/client/api/StoreApi.java | 10 ++- .../java/io/swagger/client/api/UserApi.java | 35 +++++++++- .../io/swagger/client/model/ApiResponse.java | 68 +++++++++++++++++++ .../io/swagger/client/model/Category.java | 4 ++ .../java/io/swagger/client/model/Order.java | 4 ++ .../java/io/swagger/client/model/Pet.java | 10 ++- .../java/io/swagger/client/model/Tag.java | 4 ++ .../java/io/swagger/client/model/User.java | 4 ++ 12 files changed, 196 insertions(+), 27 deletions(-) create mode 100644 samples/client/petstore/android-java/src/main/java/io/swagger/client/model/ApiResponse.java diff --git a/samples/client/petstore/android-java/build.gradle b/samples/client/petstore/android-java/build.gradle index 417503cb51ea..c5f4edf79cb0 100644 --- a/samples/client/petstore/android-java/build.gradle +++ b/samples/client/petstore/android-java/build.gradle @@ -1,6 +1,8 @@ + group = 'io.swagger' project.version = '1.0.0' + buildscript { repositories { jcenter() @@ -21,8 +23,10 @@ allprojects { apply plugin: 'com.android.library' + apply plugin: 'com.github.dcendents.android-maven' + android { compileSdkVersion 22 buildToolsVersion '22.0.0' @@ -81,6 +85,7 @@ afterEvaluate { } } + task sourcesJar(type: Jar) { from android.sourceSets.main.java.srcDirs classifier = 'sources' @@ -89,3 +94,4 @@ task sourcesJar(type: Jar) { artifacts { archives sourcesJar } + diff --git a/samples/client/petstore/android-java/src/main/java/io/swagger/client/ApiInvoker.java b/samples/client/petstore/android-java/src/main/java/io/swagger/client/ApiInvoker.java index eabb47e818d4..aa786ff5b31d 100644 --- a/samples/client/petstore/android-java/src/main/java/io/swagger/client/ApiInvoker.java +++ b/samples/client/petstore/android-java/src/main/java/io/swagger/client/ApiInvoker.java @@ -365,8 +365,10 @@ public class ApiInvoker { int code = response.getStatusLine().getStatusCode(); String responseString = null; - if(code == 204) + if(code == 204) { responseString = ""; + return responseString; + } else if(code >= 200 && code < 300) { if(response.getEntity() != null) { HttpEntity resEntity = response.getEntity(); diff --git a/samples/client/petstore/android-java/src/main/java/io/swagger/client/JsonUtil.java b/samples/client/petstore/android-java/src/main/java/io/swagger/client/JsonUtil.java index 5aa10d3ea825..93a59d71b5e7 100644 --- a/samples/client/petstore/android-java/src/main/java/io/swagger/client/JsonUtil.java +++ b/samples/client/petstore/android-java/src/main/java/io/swagger/client/JsonUtil.java @@ -35,6 +35,10 @@ public class JsonUtil { public static Type getListTypeForDeserialization(Class cls) { String className = cls.getSimpleName(); + if ("Order".equalsIgnoreCase(className)) { + return new TypeToken>(){}.getType(); + } + if ("User".equalsIgnoreCase(className)) { return new TypeToken>(){}.getType(); } @@ -43,16 +47,16 @@ public class JsonUtil { return new TypeToken>(){}.getType(); } - if ("Pet".equalsIgnoreCase(className)) { - return new TypeToken>(){}.getType(); - } - if ("Tag".equalsIgnoreCase(className)) { return new TypeToken>(){}.getType(); } - if ("Order".equalsIgnoreCase(className)) { - return new TypeToken>(){}.getType(); + if ("Pet".equalsIgnoreCase(className)) { + return new TypeToken>(){}.getType(); + } + + if ("ApiResponse".equalsIgnoreCase(className)) { + return new TypeToken>(){}.getType(); } return new TypeToken>(){}.getType(); @@ -61,6 +65,10 @@ public class JsonUtil { public static Type getTypeForDeserialization(Class cls) { String className = cls.getSimpleName(); + if ("Order".equalsIgnoreCase(className)) { + return new TypeToken(){}.getType(); + } + if ("User".equalsIgnoreCase(className)) { return new TypeToken(){}.getType(); } @@ -69,16 +77,16 @@ public class JsonUtil { return new TypeToken(){}.getType(); } - if ("Pet".equalsIgnoreCase(className)) { - return new TypeToken(){}.getType(); - } - if ("Tag".equalsIgnoreCase(className)) { return new TypeToken(){}.getType(); } - if ("Order".equalsIgnoreCase(className)) { - return new TypeToken(){}.getType(); + if ("Pet".equalsIgnoreCase(className)) { + return new TypeToken(){}.getType(); + } + + if ("ApiResponse".equalsIgnoreCase(className)) { + return new TypeToken(){}.getType(); } return new TypeToken(){}.getType(); diff --git a/samples/client/petstore/android-java/src/main/java/io/swagger/client/api/PetApi.java b/samples/client/petstore/android-java/src/main/java/io/swagger/client/api/PetApi.java index f6b6403a3424..5a607ba393fb 100644 --- a/samples/client/petstore/android-java/src/main/java/io/swagger/client/api/PetApi.java +++ b/samples/client/petstore/android-java/src/main/java/io/swagger/client/api/PetApi.java @@ -10,6 +10,8 @@ import java.util.*; import io.swagger.client.model.Pet; import java.io.File; +import io.swagger.client.model.ApiResponse; + import org.apache.http.HttpEntity; import org.apache.http.entity.mime.MultipartEntityBuilder; @@ -18,6 +20,7 @@ import java.util.Map; import java.util.HashMap; import java.io.File; + public class PetApi { String basePath = "http://petstore.swagger.io/v2"; ApiInvoker apiInvoker = ApiInvoker.getInstance(); @@ -48,6 +51,11 @@ public class PetApi { public void updatePet (Pet body) throws ApiException { Object postBody = body; + // verify the required parameter 'body' is set + if (body == null) { + throw new ApiException(400, "Missing the required parameter 'body' when calling updatePet"); + } + // create path and map variables String path = "/pet".replaceAll("\\{format\\}","json"); @@ -102,6 +110,11 @@ public class PetApi { public void addPet (Pet body) throws ApiException { Object postBody = body; + // verify the required parameter 'body' is set + if (body == null) { + throw new ApiException(400, "Missing the required parameter 'body' when calling addPet"); + } + // create path and map variables String path = "/pet".replaceAll("\\{format\\}","json"); @@ -156,6 +169,11 @@ public class PetApi { public List findPetsByStatus (List status) throws ApiException { Object postBody = null; + // verify the required parameter 'status' is set + if (status == null) { + throw new ApiException(400, "Missing the required parameter 'status' when calling findPetsByStatus"); + } + // create path and map variables String path = "/pet/findByStatus".replaceAll("\\{format\\}","json"); @@ -168,7 +186,7 @@ public class PetApi { Map formParams = new HashMap(); - queryParams.addAll(ApiInvoker.parameterToPairs("multi", "status", status)); + queryParams.addAll(ApiInvoker.parameterToPairs("csv", "status", status)); @@ -212,6 +230,11 @@ public class PetApi { public List findPetsByTags (List tags) throws ApiException { Object postBody = null; + // verify the required parameter 'tags' is set + if (tags == null) { + throw new ApiException(400, "Missing the required parameter 'tags' when calling findPetsByTags"); + } + // create path and map variables String path = "/pet/findByTags".replaceAll("\\{format\\}","json"); @@ -224,7 +247,7 @@ public class PetApi { Map formParams = new HashMap(); - queryParams.addAll(ApiInvoker.parameterToPairs("multi", "tags", tags)); + queryParams.addAll(ApiInvoker.parameterToPairs("csv", "tags", tags)); @@ -261,8 +284,8 @@ public class PetApi { /** * 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 + * Returns a single pet + * @param petId ID of pet to return * @return Pet */ public Pet getPetById (Long petId) throws ApiException { @@ -326,7 +349,7 @@ public class PetApi { * @param status Updated status of the pet * @return void */ - public void updatePetWithForm (String petId, String name, String status) throws ApiException { + public void updatePetWithForm (Long petId, String name, String status) throws ApiException { Object postBody = null; // verify the required parameter 'petId' is set @@ -457,9 +480,9 @@ public class PetApi { * @param petId ID of pet to update * @param additionalMetadata Additional data to pass to server * @param file file to upload - * @return void + * @return ApiResponse */ - public void uploadFile (Long petId, String additionalMetadata, File file) throws ApiException { + public ApiResponse uploadFile (Long petId, String additionalMetadata, File file) throws ApiException { Object postBody = null; // verify the required parameter 'petId' is set @@ -512,10 +535,10 @@ public class PetApi { try { String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, postBody, headerParams, formParams, contentType); if(response != null){ - return ; + return (ApiResponse) ApiInvoker.deserialize(response, "", ApiResponse.class); } else { - return ; + return null; } } catch (ApiException ex) { throw ex; @@ -523,3 +546,4 @@ public class PetApi { } } + diff --git a/samples/client/petstore/android-java/src/main/java/io/swagger/client/api/StoreApi.java b/samples/client/petstore/android-java/src/main/java/io/swagger/client/api/StoreApi.java index 49a3ac4aa9a1..b89a0ddbd473 100644 --- a/samples/client/petstore/android-java/src/main/java/io/swagger/client/api/StoreApi.java +++ b/samples/client/petstore/android-java/src/main/java/io/swagger/client/api/StoreApi.java @@ -11,6 +11,7 @@ import java.util.*; import java.util.Map; import io.swagger.client.model.Order; + import org.apache.http.HttpEntity; import org.apache.http.entity.mime.MultipartEntityBuilder; @@ -18,6 +19,7 @@ import java.util.Map; import java.util.HashMap; import java.io.File; + public class StoreApi { String basePath = "http://petstore.swagger.io/v2"; ApiInvoker apiInvoker = ApiInvoker.getInstance(); @@ -101,6 +103,11 @@ public class StoreApi { public Order placeOrder (Order body) throws ApiException { Object postBody = body; + // verify the required parameter 'body' is set + if (body == null) { + throw new ApiException(400, "Missing the required parameter 'body' when calling placeOrder"); + } + // create path and map variables String path = "/store/order".replaceAll("\\{format\\}","json"); @@ -152,7 +159,7 @@ public class StoreApi { * @param orderId ID of pet that needs to be fetched * @return Order */ - public Order getOrderById (String orderId) throws ApiException { + public Order getOrderById (Long orderId) throws ApiException { Object postBody = null; // verify the required parameter 'orderId' is set @@ -265,3 +272,4 @@ public class StoreApi { } } + diff --git a/samples/client/petstore/android-java/src/main/java/io/swagger/client/api/UserApi.java b/samples/client/petstore/android-java/src/main/java/io/swagger/client/api/UserApi.java index a16a745c7f8a..6703b54f7581 100644 --- a/samples/client/petstore/android-java/src/main/java/io/swagger/client/api/UserApi.java +++ b/samples/client/petstore/android-java/src/main/java/io/swagger/client/api/UserApi.java @@ -11,6 +11,7 @@ import java.util.*; import io.swagger.client.model.User; import java.util.*; + import org.apache.http.HttpEntity; import org.apache.http.entity.mime.MultipartEntityBuilder; @@ -18,6 +19,7 @@ import java.util.Map; import java.util.HashMap; import java.io.File; + public class UserApi { String basePath = "http://petstore.swagger.io/v2"; ApiInvoker apiInvoker = ApiInvoker.getInstance(); @@ -48,6 +50,11 @@ public class UserApi { public void createUser (User body) throws ApiException { Object postBody = body; + // verify the required parameter 'body' is set + if (body == null) { + throw new ApiException(400, "Missing the required parameter 'body' when calling createUser"); + } + // create path and map variables String path = "/user".replaceAll("\\{format\\}","json"); @@ -102,6 +109,11 @@ public class UserApi { public void createUsersWithArrayInput (List body) throws ApiException { Object postBody = body; + // verify the required parameter 'body' is set + if (body == null) { + throw new ApiException(400, "Missing the required parameter 'body' when calling createUsersWithArrayInput"); + } + // create path and map variables String path = "/user/createWithArray".replaceAll("\\{format\\}","json"); @@ -156,6 +168,11 @@ public class UserApi { public void createUsersWithListInput (List body) throws ApiException { Object postBody = body; + // verify the required parameter 'body' is set + if (body == null) { + throw new ApiException(400, "Missing the required parameter 'body' when calling createUsersWithListInput"); + } + // create path and map variables String path = "/user/createWithList".replaceAll("\\{format\\}","json"); @@ -211,6 +228,16 @@ public class UserApi { public String loginUser (String username, String password) throws ApiException { Object postBody = null; + // verify the required parameter 'username' is set + if (username == null) { + throw new ApiException(400, "Missing the required parameter 'username' when calling loginUser"); + } + + // verify the required parameter 'password' is set + if (password == null) { + throw new ApiException(400, "Missing the required parameter 'password' when calling loginUser"); + } + // create path and map variables String path = "/user/login".replaceAll("\\{format\\}","json"); @@ -316,7 +343,7 @@ public class UserApi { /** * Get user by user name * - * @param username The name that needs to be fetched. Use user1 for testing. + * @param username The name that needs to be fetched. Use user1 for testing. * @return User */ public User getUserByName (String username) throws ApiException { @@ -387,6 +414,11 @@ public class UserApi { throw new ApiException(400, "Missing the required parameter 'username' when calling updateUser"); } + // verify the required parameter 'body' is set + if (body == null) { + throw new ApiException(400, "Missing the required parameter 'body' when calling updateUser"); + } + // create path and map variables String path = "/user/{username}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "username" + "\\}", apiInvoker.escapeString(username.toString())); @@ -492,3 +524,4 @@ public class UserApi { } } + diff --git a/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/ApiResponse.java b/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/ApiResponse.java new file mode 100644 index 000000000000..6dd0a9c2fc21 --- /dev/null +++ b/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/ApiResponse.java @@ -0,0 +1,68 @@ +package io.swagger.client.model; + + + +import io.swagger.annotations.*; +import com.google.gson.annotations.SerializedName; + + + +@ApiModel(description = "") +public class ApiResponse { + + @SerializedName("code") + private Integer code = null; + @SerializedName("type") + private String type = null; + @SerializedName("message") + private String message = null; + + + /** + **/ + @ApiModelProperty(value = "") + public Integer getCode() { + return code; + } + public void setCode(Integer code) { + this.code = code; + } + + + /** + **/ + @ApiModelProperty(value = "") + public String getType() { + return type; + } + public void setType(String type) { + this.type = type; + } + + + /** + **/ + @ApiModelProperty(value = "") + public String getMessage() { + return message; + } + public void setMessage(String message) { + this.message = message; + } + + + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class ApiResponse {\n"); + + sb.append(" code: ").append(code).append("\n"); + sb.append(" type: ").append(type).append("\n"); + sb.append(" message: ").append(message).append("\n"); + sb.append("}\n"); + return sb.toString(); + } +} + + diff --git a/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Category.java b/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Category.java index 44c71e8a6208..98e5c25c80f9 100644 --- a/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Category.java +++ b/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Category.java @@ -1,10 +1,12 @@ package io.swagger.client.model; + import io.swagger.annotations.*; import com.google.gson.annotations.SerializedName; + @ApiModel(description = "") public class Category { @@ -48,3 +50,5 @@ public class Category { return sb.toString(); } } + + diff --git a/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Order.java b/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Order.java index f3f42db615c5..4ef664deba2d 100644 --- a/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Order.java +++ b/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Order.java @@ -2,10 +2,12 @@ package io.swagger.client.model; import java.util.Date; + import io.swagger.annotations.*; import com.google.gson.annotations.SerializedName; + @ApiModel(description = "") public class Order { @@ -109,3 +111,5 @@ public class Order { return sb.toString(); } } + + diff --git a/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Pet.java b/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Pet.java index 90a840e6e422..cf7eb877b2ab 100644 --- a/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Pet.java +++ b/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Pet.java @@ -1,13 +1,15 @@ package io.swagger.client.model; import io.swagger.client.model.Category; -import io.swagger.client.model.Tag; import java.util.*; +import io.swagger.client.model.Tag; + import io.swagger.annotations.*; import com.google.gson.annotations.SerializedName; + @ApiModel(description = "") public class Pet { @@ -18,9 +20,9 @@ public class Pet { @SerializedName("name") private String name = null; @SerializedName("photoUrls") - private List photoUrls = new ArrayList() ; + private List photoUrls = null; @SerializedName("tags") - private List tags = new ArrayList() ; + private List tags = null; public enum StatusEnum { available, pending, sold, }; @@ -111,3 +113,5 @@ public class Pet { return sb.toString(); } } + + diff --git a/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Tag.java b/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Tag.java index 7c9651b1ba8e..e87a002a1447 100644 --- a/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Tag.java +++ b/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Tag.java @@ -1,10 +1,12 @@ package io.swagger.client.model; + import io.swagger.annotations.*; import com.google.gson.annotations.SerializedName; + @ApiModel(description = "") public class Tag { @@ -48,3 +50,5 @@ public class Tag { return sb.toString(); } } + + diff --git a/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/User.java b/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/User.java index dc022697eb0f..fabdab0b4e37 100644 --- a/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/User.java +++ b/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/User.java @@ -1,10 +1,12 @@ package io.swagger.client.model; + import io.swagger.annotations.*; import com.google.gson.annotations.SerializedName; + @ApiModel(description = "") public class User { @@ -133,3 +135,5 @@ public class User { return sb.toString(); } } + + From 1fb2a97497a15c6b61de66ba3e721a2810e038d7 Mon Sep 17 00:00:00 2001 From: Eran Stiller Date: Mon, 12 Oct 2015 09:22:36 +0300 Subject: [PATCH 10/17] Revert "Regenerate Android-Java sample" This reverts commit 15f5eae2a80da4c658b466da04d11d5d51532cee. --- .../client/petstore/android-java/build.gradle | 6 -- .../java/io/swagger/client/ApiInvoker.java | 4 +- .../main/java/io/swagger/client/JsonUtil.java | 32 ++++----- .../java/io/swagger/client/api/PetApi.java | 42 +++--------- .../java/io/swagger/client/api/StoreApi.java | 10 +-- .../java/io/swagger/client/api/UserApi.java | 35 +--------- .../io/swagger/client/model/ApiResponse.java | 68 ------------------- .../io/swagger/client/model/Category.java | 4 -- .../java/io/swagger/client/model/Order.java | 4 -- .../java/io/swagger/client/model/Pet.java | 10 +-- .../java/io/swagger/client/model/Tag.java | 4 -- .../java/io/swagger/client/model/User.java | 4 -- 12 files changed, 27 insertions(+), 196 deletions(-) delete mode 100644 samples/client/petstore/android-java/src/main/java/io/swagger/client/model/ApiResponse.java diff --git a/samples/client/petstore/android-java/build.gradle b/samples/client/petstore/android-java/build.gradle index c5f4edf79cb0..417503cb51ea 100644 --- a/samples/client/petstore/android-java/build.gradle +++ b/samples/client/petstore/android-java/build.gradle @@ -1,8 +1,6 @@ - group = 'io.swagger' project.version = '1.0.0' - buildscript { repositories { jcenter() @@ -23,10 +21,8 @@ allprojects { apply plugin: 'com.android.library' - apply plugin: 'com.github.dcendents.android-maven' - android { compileSdkVersion 22 buildToolsVersion '22.0.0' @@ -85,7 +81,6 @@ afterEvaluate { } } - task sourcesJar(type: Jar) { from android.sourceSets.main.java.srcDirs classifier = 'sources' @@ -94,4 +89,3 @@ task sourcesJar(type: Jar) { artifacts { archives sourcesJar } - diff --git a/samples/client/petstore/android-java/src/main/java/io/swagger/client/ApiInvoker.java b/samples/client/petstore/android-java/src/main/java/io/swagger/client/ApiInvoker.java index aa786ff5b31d..eabb47e818d4 100644 --- a/samples/client/petstore/android-java/src/main/java/io/swagger/client/ApiInvoker.java +++ b/samples/client/petstore/android-java/src/main/java/io/swagger/client/ApiInvoker.java @@ -365,10 +365,8 @@ public class ApiInvoker { int code = response.getStatusLine().getStatusCode(); String responseString = null; - if(code == 204) { + if(code == 204) responseString = ""; - return responseString; - } else if(code >= 200 && code < 300) { if(response.getEntity() != null) { HttpEntity resEntity = response.getEntity(); diff --git a/samples/client/petstore/android-java/src/main/java/io/swagger/client/JsonUtil.java b/samples/client/petstore/android-java/src/main/java/io/swagger/client/JsonUtil.java index 93a59d71b5e7..5aa10d3ea825 100644 --- a/samples/client/petstore/android-java/src/main/java/io/swagger/client/JsonUtil.java +++ b/samples/client/petstore/android-java/src/main/java/io/swagger/client/JsonUtil.java @@ -35,10 +35,6 @@ public class JsonUtil { public static Type getListTypeForDeserialization(Class cls) { String className = cls.getSimpleName(); - if ("Order".equalsIgnoreCase(className)) { - return new TypeToken>(){}.getType(); - } - if ("User".equalsIgnoreCase(className)) { return new TypeToken>(){}.getType(); } @@ -47,16 +43,16 @@ public class JsonUtil { return new TypeToken>(){}.getType(); } - if ("Tag".equalsIgnoreCase(className)) { - return new TypeToken>(){}.getType(); - } - if ("Pet".equalsIgnoreCase(className)) { return new TypeToken>(){}.getType(); } - if ("ApiResponse".equalsIgnoreCase(className)) { - return new TypeToken>(){}.getType(); + if ("Tag".equalsIgnoreCase(className)) { + return new TypeToken>(){}.getType(); + } + + if ("Order".equalsIgnoreCase(className)) { + return new TypeToken>(){}.getType(); } return new TypeToken>(){}.getType(); @@ -65,10 +61,6 @@ public class JsonUtil { public static Type getTypeForDeserialization(Class cls) { String className = cls.getSimpleName(); - if ("Order".equalsIgnoreCase(className)) { - return new TypeToken(){}.getType(); - } - if ("User".equalsIgnoreCase(className)) { return new TypeToken(){}.getType(); } @@ -77,16 +69,16 @@ public class JsonUtil { return new TypeToken(){}.getType(); } - if ("Tag".equalsIgnoreCase(className)) { - return new TypeToken(){}.getType(); - } - if ("Pet".equalsIgnoreCase(className)) { return new TypeToken(){}.getType(); } - if ("ApiResponse".equalsIgnoreCase(className)) { - return new TypeToken(){}.getType(); + if ("Tag".equalsIgnoreCase(className)) { + return new TypeToken(){}.getType(); + } + + if ("Order".equalsIgnoreCase(className)) { + return new TypeToken(){}.getType(); } return new TypeToken(){}.getType(); diff --git a/samples/client/petstore/android-java/src/main/java/io/swagger/client/api/PetApi.java b/samples/client/petstore/android-java/src/main/java/io/swagger/client/api/PetApi.java index 5a607ba393fb..f6b6403a3424 100644 --- a/samples/client/petstore/android-java/src/main/java/io/swagger/client/api/PetApi.java +++ b/samples/client/petstore/android-java/src/main/java/io/swagger/client/api/PetApi.java @@ -10,8 +10,6 @@ import java.util.*; import io.swagger.client.model.Pet; import java.io.File; -import io.swagger.client.model.ApiResponse; - import org.apache.http.HttpEntity; import org.apache.http.entity.mime.MultipartEntityBuilder; @@ -20,7 +18,6 @@ import java.util.Map; import java.util.HashMap; import java.io.File; - public class PetApi { String basePath = "http://petstore.swagger.io/v2"; ApiInvoker apiInvoker = ApiInvoker.getInstance(); @@ -51,11 +48,6 @@ public class PetApi { public void updatePet (Pet body) throws ApiException { Object postBody = body; - // verify the required parameter 'body' is set - if (body == null) { - throw new ApiException(400, "Missing the required parameter 'body' when calling updatePet"); - } - // create path and map variables String path = "/pet".replaceAll("\\{format\\}","json"); @@ -110,11 +102,6 @@ public class PetApi { public void addPet (Pet body) throws ApiException { Object postBody = body; - // verify the required parameter 'body' is set - if (body == null) { - throw new ApiException(400, "Missing the required parameter 'body' when calling addPet"); - } - // create path and map variables String path = "/pet".replaceAll("\\{format\\}","json"); @@ -169,11 +156,6 @@ public class PetApi { public List findPetsByStatus (List status) throws ApiException { Object postBody = null; - // verify the required parameter 'status' is set - if (status == null) { - throw new ApiException(400, "Missing the required parameter 'status' when calling findPetsByStatus"); - } - // create path and map variables String path = "/pet/findByStatus".replaceAll("\\{format\\}","json"); @@ -186,7 +168,7 @@ public class PetApi { Map formParams = new HashMap(); - queryParams.addAll(ApiInvoker.parameterToPairs("csv", "status", status)); + queryParams.addAll(ApiInvoker.parameterToPairs("multi", "status", status)); @@ -230,11 +212,6 @@ public class PetApi { public List findPetsByTags (List tags) throws ApiException { Object postBody = null; - // verify the required parameter 'tags' is set - if (tags == null) { - throw new ApiException(400, "Missing the required parameter 'tags' when calling findPetsByTags"); - } - // create path and map variables String path = "/pet/findByTags".replaceAll("\\{format\\}","json"); @@ -247,7 +224,7 @@ public class PetApi { Map formParams = new HashMap(); - queryParams.addAll(ApiInvoker.parameterToPairs("csv", "tags", tags)); + queryParams.addAll(ApiInvoker.parameterToPairs("multi", "tags", tags)); @@ -284,8 +261,8 @@ public class PetApi { /** * Find pet by ID - * Returns a single pet - * @param petId ID of pet to return + * 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 Pet */ public Pet getPetById (Long petId) throws ApiException { @@ -349,7 +326,7 @@ public class PetApi { * @param status Updated status of the pet * @return void */ - public void updatePetWithForm (Long petId, String name, String status) throws ApiException { + public void updatePetWithForm (String petId, String name, String status) throws ApiException { Object postBody = null; // verify the required parameter 'petId' is set @@ -480,9 +457,9 @@ public class PetApi { * @param petId ID of pet to update * @param additionalMetadata Additional data to pass to server * @param file file to upload - * @return ApiResponse + * @return void */ - public ApiResponse uploadFile (Long petId, String additionalMetadata, File file) throws ApiException { + public void uploadFile (Long petId, String additionalMetadata, File file) throws ApiException { Object postBody = null; // verify the required parameter 'petId' is set @@ -535,10 +512,10 @@ public class PetApi { try { String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, postBody, headerParams, formParams, contentType); if(response != null){ - return (ApiResponse) ApiInvoker.deserialize(response, "", ApiResponse.class); + return ; } else { - return null; + return ; } } catch (ApiException ex) { throw ex; @@ -546,4 +523,3 @@ public class PetApi { } } - diff --git a/samples/client/petstore/android-java/src/main/java/io/swagger/client/api/StoreApi.java b/samples/client/petstore/android-java/src/main/java/io/swagger/client/api/StoreApi.java index b89a0ddbd473..49a3ac4aa9a1 100644 --- a/samples/client/petstore/android-java/src/main/java/io/swagger/client/api/StoreApi.java +++ b/samples/client/petstore/android-java/src/main/java/io/swagger/client/api/StoreApi.java @@ -11,7 +11,6 @@ import java.util.*; import java.util.Map; import io.swagger.client.model.Order; - import org.apache.http.HttpEntity; import org.apache.http.entity.mime.MultipartEntityBuilder; @@ -19,7 +18,6 @@ import java.util.Map; import java.util.HashMap; import java.io.File; - public class StoreApi { String basePath = "http://petstore.swagger.io/v2"; ApiInvoker apiInvoker = ApiInvoker.getInstance(); @@ -103,11 +101,6 @@ public class StoreApi { public Order placeOrder (Order body) throws ApiException { Object postBody = body; - // verify the required parameter 'body' is set - if (body == null) { - throw new ApiException(400, "Missing the required parameter 'body' when calling placeOrder"); - } - // create path and map variables String path = "/store/order".replaceAll("\\{format\\}","json"); @@ -159,7 +152,7 @@ public class StoreApi { * @param orderId ID of pet that needs to be fetched * @return Order */ - public Order getOrderById (Long orderId) throws ApiException { + public Order getOrderById (String orderId) throws ApiException { Object postBody = null; // verify the required parameter 'orderId' is set @@ -272,4 +265,3 @@ public class StoreApi { } } - diff --git a/samples/client/petstore/android-java/src/main/java/io/swagger/client/api/UserApi.java b/samples/client/petstore/android-java/src/main/java/io/swagger/client/api/UserApi.java index 6703b54f7581..a16a745c7f8a 100644 --- a/samples/client/petstore/android-java/src/main/java/io/swagger/client/api/UserApi.java +++ b/samples/client/petstore/android-java/src/main/java/io/swagger/client/api/UserApi.java @@ -11,7 +11,6 @@ import java.util.*; import io.swagger.client.model.User; import java.util.*; - import org.apache.http.HttpEntity; import org.apache.http.entity.mime.MultipartEntityBuilder; @@ -19,7 +18,6 @@ import java.util.Map; import java.util.HashMap; import java.io.File; - public class UserApi { String basePath = "http://petstore.swagger.io/v2"; ApiInvoker apiInvoker = ApiInvoker.getInstance(); @@ -50,11 +48,6 @@ public class UserApi { public void createUser (User body) throws ApiException { Object postBody = body; - // verify the required parameter 'body' is set - if (body == null) { - throw new ApiException(400, "Missing the required parameter 'body' when calling createUser"); - } - // create path and map variables String path = "/user".replaceAll("\\{format\\}","json"); @@ -109,11 +102,6 @@ public class UserApi { public void createUsersWithArrayInput (List body) throws ApiException { Object postBody = body; - // verify the required parameter 'body' is set - if (body == null) { - throw new ApiException(400, "Missing the required parameter 'body' when calling createUsersWithArrayInput"); - } - // create path and map variables String path = "/user/createWithArray".replaceAll("\\{format\\}","json"); @@ -168,11 +156,6 @@ public class UserApi { public void createUsersWithListInput (List body) throws ApiException { Object postBody = body; - // verify the required parameter 'body' is set - if (body == null) { - throw new ApiException(400, "Missing the required parameter 'body' when calling createUsersWithListInput"); - } - // create path and map variables String path = "/user/createWithList".replaceAll("\\{format\\}","json"); @@ -228,16 +211,6 @@ public class UserApi { public String loginUser (String username, String password) throws ApiException { Object postBody = null; - // verify the required parameter 'username' is set - if (username == null) { - throw new ApiException(400, "Missing the required parameter 'username' when calling loginUser"); - } - - // verify the required parameter 'password' is set - if (password == null) { - throw new ApiException(400, "Missing the required parameter 'password' when calling loginUser"); - } - // create path and map variables String path = "/user/login".replaceAll("\\{format\\}","json"); @@ -343,7 +316,7 @@ public class UserApi { /** * Get user by user name * - * @param username The name that needs to be fetched. Use user1 for testing. + * @param username The name that needs to be fetched. Use user1 for testing. * @return User */ public User getUserByName (String username) throws ApiException { @@ -414,11 +387,6 @@ public class UserApi { throw new ApiException(400, "Missing the required parameter 'username' when calling updateUser"); } - // verify the required parameter 'body' is set - if (body == null) { - throw new ApiException(400, "Missing the required parameter 'body' when calling updateUser"); - } - // create path and map variables String path = "/user/{username}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "username" + "\\}", apiInvoker.escapeString(username.toString())); @@ -524,4 +492,3 @@ public class UserApi { } } - diff --git a/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/ApiResponse.java b/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/ApiResponse.java deleted file mode 100644 index 6dd0a9c2fc21..000000000000 --- a/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/ApiResponse.java +++ /dev/null @@ -1,68 +0,0 @@ -package io.swagger.client.model; - - - -import io.swagger.annotations.*; -import com.google.gson.annotations.SerializedName; - - - -@ApiModel(description = "") -public class ApiResponse { - - @SerializedName("code") - private Integer code = null; - @SerializedName("type") - private String type = null; - @SerializedName("message") - private String message = null; - - - /** - **/ - @ApiModelProperty(value = "") - public Integer getCode() { - return code; - } - public void setCode(Integer code) { - this.code = code; - } - - - /** - **/ - @ApiModelProperty(value = "") - public String getType() { - return type; - } - public void setType(String type) { - this.type = type; - } - - - /** - **/ - @ApiModelProperty(value = "") - public String getMessage() { - return message; - } - public void setMessage(String message) { - this.message = message; - } - - - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("class ApiResponse {\n"); - - sb.append(" code: ").append(code).append("\n"); - sb.append(" type: ").append(type).append("\n"); - sb.append(" message: ").append(message).append("\n"); - sb.append("}\n"); - return sb.toString(); - } -} - - diff --git a/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Category.java b/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Category.java index 98e5c25c80f9..44c71e8a6208 100644 --- a/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Category.java +++ b/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Category.java @@ -1,12 +1,10 @@ package io.swagger.client.model; - import io.swagger.annotations.*; import com.google.gson.annotations.SerializedName; - @ApiModel(description = "") public class Category { @@ -50,5 +48,3 @@ public class Category { return sb.toString(); } } - - diff --git a/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Order.java b/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Order.java index 4ef664deba2d..f3f42db615c5 100644 --- a/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Order.java +++ b/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Order.java @@ -2,12 +2,10 @@ package io.swagger.client.model; import java.util.Date; - import io.swagger.annotations.*; import com.google.gson.annotations.SerializedName; - @ApiModel(description = "") public class Order { @@ -111,5 +109,3 @@ public class Order { return sb.toString(); } } - - diff --git a/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Pet.java b/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Pet.java index cf7eb877b2ab..90a840e6e422 100644 --- a/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Pet.java +++ b/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Pet.java @@ -1,15 +1,13 @@ package io.swagger.client.model; import io.swagger.client.model.Category; -import java.util.*; import io.swagger.client.model.Tag; - +import java.util.*; import io.swagger.annotations.*; import com.google.gson.annotations.SerializedName; - @ApiModel(description = "") public class Pet { @@ -20,9 +18,9 @@ public class Pet { @SerializedName("name") private String name = null; @SerializedName("photoUrls") - private List photoUrls = null; + private List photoUrls = new ArrayList() ; @SerializedName("tags") - private List tags = null; + private List tags = new ArrayList() ; public enum StatusEnum { available, pending, sold, }; @@ -113,5 +111,3 @@ public class Pet { return sb.toString(); } } - - diff --git a/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Tag.java b/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Tag.java index e87a002a1447..7c9651b1ba8e 100644 --- a/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Tag.java +++ b/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/Tag.java @@ -1,12 +1,10 @@ package io.swagger.client.model; - import io.swagger.annotations.*; import com.google.gson.annotations.SerializedName; - @ApiModel(description = "") public class Tag { @@ -50,5 +48,3 @@ public class Tag { return sb.toString(); } } - - diff --git a/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/User.java b/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/User.java index fabdab0b4e37..dc022697eb0f 100644 --- a/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/User.java +++ b/samples/client/petstore/android-java/src/main/java/io/swagger/client/model/User.java @@ -1,12 +1,10 @@ package io.swagger.client.model; - import io.swagger.annotations.*; import com.google.gson.annotations.SerializedName; - @ApiModel(description = "") public class User { @@ -135,5 +133,3 @@ public class User { return sb.toString(); } } - - From 748460488aa6477f406cb3e5d15eb9334ba34192 Mon Sep 17 00:00:00 2001 From: Eran Stiller Date: Mon, 12 Oct 2015 09:25:24 +0300 Subject: [PATCH 11/17] Regenerate only the ApiInvoker.java file in the sample --- .../src/main/java/io/swagger/client/ApiInvoker.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/samples/client/petstore/android-java/src/main/java/io/swagger/client/ApiInvoker.java b/samples/client/petstore/android-java/src/main/java/io/swagger/client/ApiInvoker.java index eabb47e818d4..aa786ff5b31d 100644 --- a/samples/client/petstore/android-java/src/main/java/io/swagger/client/ApiInvoker.java +++ b/samples/client/petstore/android-java/src/main/java/io/swagger/client/ApiInvoker.java @@ -365,8 +365,10 @@ public class ApiInvoker { int code = response.getStatusLine().getStatusCode(); String responseString = null; - if(code == 204) + if(code == 204) { responseString = ""; + return responseString; + } else if(code >= 200 && code < 300) { if(response.getEntity() != null) { HttpEntity resEntity = response.getEntity(); From e562b0ae34f7161ca4fb629cb22b5e2967d16dfd Mon Sep 17 00:00:00 2001 From: Eran Stiller Date: Mon, 12 Oct 2015 09:52:20 +0300 Subject: [PATCH 12/17] Fix indentation --- .../src/main/resources/android-java/apiInvoker.mustache | 4 ++-- .../src/main/java/io/swagger/client/ApiInvoker.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/android-java/apiInvoker.mustache b/modules/swagger-codegen/src/main/resources/android-java/apiInvoker.mustache index b5f0ae7a6623..1f6d77a071ce 100644 --- a/modules/swagger-codegen/src/main/resources/android-java/apiInvoker.mustache +++ b/modules/swagger-codegen/src/main/resources/android-java/apiInvoker.mustache @@ -367,8 +367,8 @@ public class ApiInvoker { String responseString = null; if(code == 204) { responseString = ""; - return responseString; - } + return responseString; + } else if(code >= 200 && code < 300) { if(response.getEntity() != null) { HttpEntity resEntity = response.getEntity(); diff --git a/samples/client/petstore/android-java/src/main/java/io/swagger/client/ApiInvoker.java b/samples/client/petstore/android-java/src/main/java/io/swagger/client/ApiInvoker.java index aa786ff5b31d..5eddeb6b9e96 100644 --- a/samples/client/petstore/android-java/src/main/java/io/swagger/client/ApiInvoker.java +++ b/samples/client/petstore/android-java/src/main/java/io/swagger/client/ApiInvoker.java @@ -367,8 +367,8 @@ public class ApiInvoker { String responseString = null; if(code == 204) { responseString = ""; - return responseString; - } + return responseString; + } else if(code >= 200 && code < 300) { if(response.getEntity() != null) { HttpEntity resEntity = response.getEntity(); From 6ce09ee77924cae5c77c341b266ad93623988069 Mon Sep 17 00:00:00 2001 From: wing328 Date: Mon, 12 Oct 2015 17:34:07 +0800 Subject: [PATCH 13/17] Update config option --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 0577dceb8e8a..7b130b4b8ab7 100644 --- a/README.md +++ b/README.md @@ -276,6 +276,9 @@ CONFIG OPTIONS apiPackage package for generated api classes + sortParamsByRequiredFlag + Sort method arguments to place required parameters before optional parameters. Default: true + invokerPackage root package for generated code @@ -291,6 +294,12 @@ CONFIG OPTIONS sourceFolder source folder for generated code + localVariablePrefix + prefix for generated code members and local variables + + serializableModel + boolean - toggle "implements Serializable" for generated models + library library template (sub-template) to use: - HTTP client: Jersey client 1.18. JSON processing: Jackson 2.4.2 From 5ed52b3e1d2b04d3d55a3f18280dabee9f7215c3 Mon Sep 17 00:00:00 2001 From: cbornet Date: Mon, 12 Oct 2015 16:16:38 +0200 Subject: [PATCH 14/17] add gradle files with android support --- .../codegen/languages/JavaClientCodegen.java | 5 +- .../main/resources/Java/build.gradle.mustache | 107 ++++++++++++++++++ .../resources/Java/gradle.properties.mustache | 2 + .../libraries/jersey2/build.gradle.mustache | 107 ++++++++++++++++++ .../okhttp-gson/build.gradle.mustache | 102 +++++++++++++---- .../libraries/retrofit/build.gradle.mustache | 103 +++++++++++++++++ .../resources/Java/settings.gradle.mustache | 1 + .../client/petstore/java/default/build.gradle | 107 ++++++++++++++++++ .../petstore/java/default/gradle.properties | 2 + .../petstore/java/default/settings.gradle | 1 + .../client/petstore/java/jersey2/build.gradle | 107 ++++++++++++++++++ .../petstore/java/jersey2/gradle.properties | 2 + .../petstore/java/jersey2/settings.gradle | 1 + .../petstore/java/okhttp-gson/build.gradle | 102 +++++++++++++---- .../java/okhttp-gson/gradle.properties | 2 + .../petstore/java/okhttp-gson/settings.gradle | 1 + .../petstore/java/retrofit/build.gradle | 103 +++++++++++++++++ .../petstore/java/retrofit/gradle.properties | 2 + .../petstore/java/retrofit/settings.gradle | 1 + 19 files changed, 818 insertions(+), 40 deletions(-) create mode 100644 modules/swagger-codegen/src/main/resources/Java/build.gradle.mustache create mode 100644 modules/swagger-codegen/src/main/resources/Java/gradle.properties.mustache create mode 100644 modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/build.gradle.mustache create mode 100644 modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/build.gradle.mustache create mode 100644 modules/swagger-codegen/src/main/resources/Java/settings.gradle.mustache create mode 100644 samples/client/petstore/java/default/build.gradle create mode 100644 samples/client/petstore/java/default/gradle.properties create mode 100644 samples/client/petstore/java/default/settings.gradle create mode 100644 samples/client/petstore/java/jersey2/build.gradle create mode 100644 samples/client/petstore/java/jersey2/gradle.properties create mode 100644 samples/client/petstore/java/jersey2/settings.gradle create mode 100644 samples/client/petstore/java/okhttp-gson/gradle.properties create mode 100644 samples/client/petstore/java/okhttp-gson/settings.gradle create mode 100644 samples/client/petstore/java/retrofit/build.gradle create mode 100644 samples/client/petstore/java/retrofit/gradle.properties create mode 100644 samples/client/petstore/java/retrofit/settings.gradle diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java index 360dc9c0f2f0..1d56c340dea4 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java @@ -156,6 +156,9 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig { final String invokerFolder = (sourceFolder + File.separator + invokerPackage).replace(".", File.separator); supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml")); + supportingFiles.add(new SupportingFile("build.gradle.mustache", "", "build.gradle")); + supportingFiles.add(new SupportingFile("settings.gradle.mustache", "", "settings.gradle")); + supportingFiles.add(new SupportingFile("gradle.properties.mustache", "", "gradle.properties")); supportingFiles.add(new SupportingFile("ApiClient.mustache", invokerFolder, "ApiClient.java")); supportingFiles.add(new SupportingFile("StringUtil.mustache", invokerFolder, "StringUtil.java")); @@ -177,8 +180,6 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig { if ("okhttp-gson".equals(getLibrary())) { // the "okhttp-gson" library template requires "ApiCallback.mustache" for async call supportingFiles.add(new SupportingFile("ApiCallback.mustache", invokerFolder, "ApiCallback.java")); - // "build.gradle" is for development with Gradle - supportingFiles.add(new SupportingFile("build.gradle.mustache", "", "build.gradle")); // "build.sbt" is for development with SBT supportingFiles.add(new SupportingFile("build.sbt.mustache", "", "build.sbt")); } else if ("retrofit".equals(getLibrary())) { diff --git a/modules/swagger-codegen/src/main/resources/Java/build.gradle.mustache b/modules/swagger-codegen/src/main/resources/Java/build.gradle.mustache new file mode 100644 index 000000000000..971dcd816a49 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/Java/build.gradle.mustache @@ -0,0 +1,107 @@ +group = '{{groupId}}' +version = '{{artifactVersion}}' + +buildscript { + repositories { + jcenter() + } + dependencies { + classpath 'com.android.tools.build:gradle:1.2.2' + classpath 'com.github.dcendents:android-maven-plugin:1.2' + } +} + +repositories { + jcenter() +} + + +if(hasProperty('target') && target == 'android') { + + apply plugin: 'com.android.library' + apply plugin: 'com.github.dcendents.android-maven' + + android { + compileSdkVersion 22 + buildToolsVersion '22.0.0' + defaultConfig { + minSdkVersion 14 + targetSdkVersion 22 + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_7 + targetCompatibility JavaVersion.VERSION_1_7 + } + + // Rename the aar correctly + libraryVariants.all { variant -> + variant.outputs.each { output -> + def outputFile = output.outputFile + if (outputFile != null && outputFile.name.endsWith('.aar')) { + def fileName = "${project.name}-${variant.baseName}-${version}.aar" + output.outputFile = new File(outputFile.parent, fileName) + } + } + } + } + + afterEvaluate { + android.libraryVariants.all { variant -> + def task = project.tasks.create "jar${variant.name.capitalize()}", Jar + task.description = "Create jar artifact for ${variant.name}" + task.dependsOn variant.javaCompile + task.from variant.javaCompile.destinationDir + task.destinationDir = project.file("${project.buildDir}/outputs/jar") + task.archiveName = "${project.name}-${variant.baseName}-${version}.jar" + artifacts.add('archives', task); + } + } + + task sourcesJar(type: Jar) { + from android.sourceSets.main.java.srcDirs + classifier = 'sources' + } + + artifacts { + archives sourcesJar + } + +} else { + + apply plugin: 'java' + apply plugin: 'maven' + + sourceCompatibility = JavaVersion.VERSION_1_7 + targetCompatibility = JavaVersion.VERSION_1_7 + + install { + repositories.mavenInstaller { + pom.artifactId = '{{artifactId}}' + } + } + + task execute(type:JavaExec) { + main = System.getProperty('mainClass') + classpath = sourceSets.main.runtimeClasspath + } +} + +ext { + swagger_annotations_version = "1.5.0" + jackson_version = "2.4.2" + jersey_version = "1.18" + jodatime_version = "2.3" + junit_version = "4.8.1" +} + +dependencies { + compile "io.swagger:swagger-annotations:$swagger_annotations_version" + compile "com.sun.jersey:jersey-client:$jersey_version" + compile "com.sun.jersey.contribs:jersey-multipart:$jersey_version" + compile "com.fasterxml.jackson.core:jackson-core:$jackson_version" + compile "com.fasterxml.jackson.core:jackson-annotations:$jackson_version" + compile "com.fasterxml.jackson.core:jackson-databind:$jackson_version" + compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:2.1.5" + compile "joda-time:joda-time:$jodatime_version" + testCompile "junit:junit:$junit_version" +} diff --git a/modules/swagger-codegen/src/main/resources/Java/gradle.properties.mustache b/modules/swagger-codegen/src/main/resources/Java/gradle.properties.mustache new file mode 100644 index 000000000000..05644f0754af --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/Java/gradle.properties.mustache @@ -0,0 +1,2 @@ +# Uncomment to build for Android +#target = android \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/build.gradle.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/build.gradle.mustache new file mode 100644 index 000000000000..548c1854e5e1 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/build.gradle.mustache @@ -0,0 +1,107 @@ +group = '{{groupId}}' +version = '{{artifactVersion}}' + +buildscript { + repositories { + jcenter() + } + dependencies { + classpath 'com.android.tools.build:gradle:1.2.2' + classpath 'com.github.dcendents:android-maven-plugin:1.2' + } +} + +repositories { + jcenter() +} + + +if(hasProperty('target') && target == 'android') { + + apply plugin: 'com.android.library' + apply plugin: 'com.github.dcendents.android-maven' + + android { + compileSdkVersion 22 + buildToolsVersion '22.0.0' + defaultConfig { + minSdkVersion 14 + targetSdkVersion 22 + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_7 + targetCompatibility JavaVersion.VERSION_1_7 + } + + // Rename the aar correctly + libraryVariants.all { variant -> + variant.outputs.each { output -> + def outputFile = output.outputFile + if (outputFile != null && outputFile.name.endsWith('.aar')) { + def fileName = "${project.name}-${variant.baseName}-${version}.aar" + output.outputFile = new File(outputFile.parent, fileName) + } + } + } + } + + afterEvaluate { + android.libraryVariants.all { variant -> + def task = project.tasks.create "jar${variant.name.capitalize()}", Jar + task.description = "Create jar artifact for ${variant.name}" + task.dependsOn variant.javaCompile + task.from variant.javaCompile.destinationDir + task.destinationDir = project.file("${project.buildDir}/outputs/jar") + task.archiveName = "${project.name}-${variant.baseName}-${version}.jar" + artifacts.add('archives', task); + } + } + + task sourcesJar(type: Jar) { + from android.sourceSets.main.java.srcDirs + classifier = 'sources' + } + + artifacts { + archives sourcesJar + } + +} else { + + apply plugin: 'java' + apply plugin: 'maven' + + sourceCompatibility = JavaVersion.VERSION_1_7 + targetCompatibility = JavaVersion.VERSION_1_7 + + install { + repositories.mavenInstaller { + pom.artifactId = '{{artifactId}}' + } + } + + task execute(type:JavaExec) { + main = System.getProperty('mainClass') + classpath = sourceSets.main.runtimeClasspath + } +} + +ext { + swagger_annotations_version = "1.5.0" + jackson_version = "2.4.2" + jersey_version = "2.6" + jodatime_version = "2.3" + junit_version = "4.8.1" +} + +dependencies { + compile "io.swagger:swagger-annotations:$swagger_annotations_version" + compile "org.glassfish.jersey.core:jersey-client:$jersey_version" + compile "org.glassfish.jersey.media:jersey-media-multipart:$jersey_version" + compile "com.fasterxml.jackson.core:jackson-core:$jackson_version" + compile "com.fasterxml.jackson.core:jackson-annotations:$jackson_version" + compile "com.fasterxml.jackson.core:jackson-databind:$jackson_version" + compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:2.1.5" + compile "joda-time:joda-time:$jodatime_version" + testCompile "junit:junit:$junit_version" +} diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/build.gradle.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/build.gradle.mustache index 02e1caa673af..289f9a6df722 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/build.gradle.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/build.gradle.mustache @@ -1,11 +1,89 @@ -apply plugin: 'java' -apply plugin: 'maven' +group = '{{groupId}}' +version = '{{artifactVersion}}' -sourceCompatibility = JavaVersion.VERSION_1_7 -targetCompatibility = JavaVersion.VERSION_1_7 +buildscript { + repositories { + jcenter() + } + dependencies { + classpath 'com.android.tools.build:gradle:1.2.2' + classpath 'com.github.dcendents:android-maven-plugin:1.2' + } +} repositories { - mavenCentral() + jcenter() +} + + +if(hasProperty('target') && target == 'android') { + + apply plugin: 'com.android.library' + apply plugin: 'com.github.dcendents.android-maven' + + android { + compileSdkVersion 22 + buildToolsVersion '22.0.0' + defaultConfig { + minSdkVersion 14 + targetSdkVersion 22 + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_7 + targetCompatibility JavaVersion.VERSION_1_7 + } + + // Rename the aar correctly + libraryVariants.all { variant -> + variant.outputs.each { output -> + def outputFile = output.outputFile + if (outputFile != null && outputFile.name.endsWith('.aar')) { + def fileName = "${project.name}-${variant.baseName}-${version}.aar" + output.outputFile = new File(outputFile.parent, fileName) + } + } + } + } + + afterEvaluate { + android.libraryVariants.all { variant -> + def task = project.tasks.create "jar${variant.name.capitalize()}", Jar + task.description = "Create jar artifact for ${variant.name}" + task.dependsOn variant.javaCompile + task.from variant.javaCompile.destinationDir + task.destinationDir = project.file("${project.buildDir}/outputs/jar") + task.archiveName = "${project.name}-${variant.baseName}-${version}.jar" + artifacts.add('archives', task); + } + } + + task sourcesJar(type: Jar) { + from android.sourceSets.main.java.srcDirs + classifier = 'sources' + } + + artifacts { + archives sourcesJar + } + +} else { + + apply plugin: 'java' + apply plugin: 'maven' + + sourceCompatibility = JavaVersion.VERSION_1_7 + targetCompatibility = JavaVersion.VERSION_1_7 + + install { + repositories.mavenInstaller { + pom.artifactId = '{{artifactId}}' + } + } + + task execute(type:JavaExec) { + main = System.getProperty('mainClass') + classpath = sourceSets.main.runtimeClasspath + } } dependencies { @@ -15,17 +93,3 @@ dependencies { compile 'com.brsanthu:migbase64:2.2' testCompile 'junit:junit:4.8.1' } - -group = '{{groupId}}' -version = '{{artifactVersion}}' - -install { - repositories.mavenInstaller { - pom.artifactId = '{{artifactId}}' - } -} - -task execute(type:JavaExec) { - main = System.getProperty('mainClass') - classpath = sourceSets.main.runtimeClasspath -} diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/build.gradle.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/build.gradle.mustache new file mode 100644 index 000000000000..a285745505ac --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/build.gradle.mustache @@ -0,0 +1,103 @@ +group = '{{groupId}}' +version = '{{artifactVersion}}' + +buildscript { + repositories { + jcenter() + } + dependencies { + classpath 'com.android.tools.build:gradle:1.2.2' + classpath 'com.github.dcendents:android-maven-plugin:1.2' + } +} + +repositories { + jcenter() +} + + +if(hasProperty('target') && target == 'android') { + + apply plugin: 'com.android.library' + apply plugin: 'com.github.dcendents.android-maven' + + android { + compileSdkVersion 22 + buildToolsVersion '22.0.0' + defaultConfig { + minSdkVersion 14 + targetSdkVersion 22 + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_7 + targetCompatibility JavaVersion.VERSION_1_7 + } + + // Rename the aar correctly + libraryVariants.all { variant -> + variant.outputs.each { output -> + def outputFile = output.outputFile + if (outputFile != null && outputFile.name.endsWith('.aar')) { + def fileName = "${project.name}-${variant.baseName}-${version}.aar" + output.outputFile = new File(outputFile.parent, fileName) + } + } + } + } + + afterEvaluate { + android.libraryVariants.all { variant -> + def task = project.tasks.create "jar${variant.name.capitalize()}", Jar + task.description = "Create jar artifact for ${variant.name}" + task.dependsOn variant.javaCompile + task.from variant.javaCompile.destinationDir + task.destinationDir = project.file("${project.buildDir}/outputs/jar") + task.archiveName = "${project.name}-${variant.baseName}-${version}.jar" + artifacts.add('archives', task); + } + } + + task sourcesJar(type: Jar) { + from android.sourceSets.main.java.srcDirs + classifier = 'sources' + } + + artifacts { + archives sourcesJar + } + +} else { + + apply plugin: 'java' + apply plugin: 'maven' + + sourceCompatibility = JavaVersion.VERSION_1_7 + targetCompatibility = JavaVersion.VERSION_1_7 + + install { + repositories.mavenInstaller { + pom.artifactId = '{{artifactId}}' + } + } + + task execute(type:JavaExec) { + main = System.getProperty('mainClass') + classpath = sourceSets.main.runtimeClasspath + } +} + +ext { + okhttp_version = "2.3.0" + oltu_version = "1.0.0" + retrofit_version = "1.9.0" + swagger_annotations_version = "1.5.0" + junit_version = "4.12" +} + +dependencies { + compile "com.squareup.okhttp:okhttp:$okhttp_version" + compile "com.squareup.retrofit:retrofit:$retrofit_version" + compile "io.swagger:swagger-annotations:$swagger_annotations_version" + compile "org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:$oltu_version" + testCompile "junit:junit:$junit_version" +} diff --git a/modules/swagger-codegen/src/main/resources/Java/settings.gradle.mustache b/modules/swagger-codegen/src/main/resources/Java/settings.gradle.mustache new file mode 100644 index 000000000000..b8fd6c4c41f9 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/Java/settings.gradle.mustache @@ -0,0 +1 @@ +rootProject.name = "{{artifactId}}" \ No newline at end of file diff --git a/samples/client/petstore/java/default/build.gradle b/samples/client/petstore/java/default/build.gradle new file mode 100644 index 000000000000..baa5ce97b015 --- /dev/null +++ b/samples/client/petstore/java/default/build.gradle @@ -0,0 +1,107 @@ +group = 'io.swagger' +version = '1.0.0' + +buildscript { + repositories { + jcenter() + } + dependencies { + classpath 'com.android.tools.build:gradle:1.2.2' + classpath 'com.github.dcendents:android-maven-plugin:1.2' + } +} + +repositories { + jcenter() +} + + +if(hasProperty('target') && target == 'android') { + + apply plugin: 'com.android.library' + apply plugin: 'com.github.dcendents.android-maven' + + android { + compileSdkVersion 22 + buildToolsVersion '22.0.0' + defaultConfig { + minSdkVersion 14 + targetSdkVersion 22 + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_7 + targetCompatibility JavaVersion.VERSION_1_7 + } + + // Rename the aar correctly + libraryVariants.all { variant -> + variant.outputs.each { output -> + def outputFile = output.outputFile + if (outputFile != null && outputFile.name.endsWith('.aar')) { + def fileName = "${project.name}-${variant.baseName}-${version}.aar" + output.outputFile = new File(outputFile.parent, fileName) + } + } + } + } + + afterEvaluate { + android.libraryVariants.all { variant -> + def task = project.tasks.create "jar${variant.name.capitalize()}", Jar + task.description = "Create jar artifact for ${variant.name}" + task.dependsOn variant.javaCompile + task.from variant.javaCompile.destinationDir + task.destinationDir = project.file("${project.buildDir}/outputs/jar") + task.archiveName = "${project.name}-${variant.baseName}-${version}.jar" + artifacts.add('archives', task); + } + } + + task sourcesJar(type: Jar) { + from android.sourceSets.main.java.srcDirs + classifier = 'sources' + } + + artifacts { + archives sourcesJar + } + +} else { + + apply plugin: 'java' + apply plugin: 'maven' + + sourceCompatibility = JavaVersion.VERSION_1_7 + targetCompatibility = JavaVersion.VERSION_1_7 + + install { + repositories.mavenInstaller { + pom.artifactId = 'swagger-java-client' + } + } + + task execute(type:JavaExec) { + main = System.getProperty('mainClass') + classpath = sourceSets.main.runtimeClasspath + } +} + +ext { + swagger_annotations_version = "1.5.0" + jackson_version = "2.4.2" + jersey_version = "1.18" + jodatime_version = "2.3" + junit_version = "4.8.1" +} + +dependencies { + compile "io.swagger:swagger-annotations:$swagger_annotations_version" + compile "com.sun.jersey:jersey-client:$jersey_version" + compile "com.sun.jersey.contribs:jersey-multipart:$jersey_version" + compile "com.fasterxml.jackson.core:jackson-core:$jackson_version" + compile "com.fasterxml.jackson.core:jackson-annotations:$jackson_version" + compile "com.fasterxml.jackson.core:jackson-databind:$jackson_version" + compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:2.1.5" + compile "joda-time:joda-time:$jodatime_version" + testCompile "junit:junit:$junit_version" +} diff --git a/samples/client/petstore/java/default/gradle.properties b/samples/client/petstore/java/default/gradle.properties new file mode 100644 index 000000000000..05644f0754af --- /dev/null +++ b/samples/client/petstore/java/default/gradle.properties @@ -0,0 +1,2 @@ +# Uncomment to build for Android +#target = android \ No newline at end of file diff --git a/samples/client/petstore/java/default/settings.gradle b/samples/client/petstore/java/default/settings.gradle new file mode 100644 index 000000000000..55640f75122e --- /dev/null +++ b/samples/client/petstore/java/default/settings.gradle @@ -0,0 +1 @@ +rootProject.name = "swagger-java-client" \ No newline at end of file diff --git a/samples/client/petstore/java/jersey2/build.gradle b/samples/client/petstore/java/jersey2/build.gradle new file mode 100644 index 000000000000..9727e5693e6d --- /dev/null +++ b/samples/client/petstore/java/jersey2/build.gradle @@ -0,0 +1,107 @@ +group = 'io.swagger' +version = '1.0.0' + +buildscript { + repositories { + jcenter() + } + dependencies { + classpath 'com.android.tools.build:gradle:1.2.2' + classpath 'com.github.dcendents:android-maven-plugin:1.2' + } +} + +repositories { + jcenter() +} + + +if(hasProperty('target') && target == 'android') { + + apply plugin: 'com.android.library' + apply plugin: 'com.github.dcendents.android-maven' + + android { + compileSdkVersion 22 + buildToolsVersion '22.0.0' + defaultConfig { + minSdkVersion 14 + targetSdkVersion 22 + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_7 + targetCompatibility JavaVersion.VERSION_1_7 + } + + // Rename the aar correctly + libraryVariants.all { variant -> + variant.outputs.each { output -> + def outputFile = output.outputFile + if (outputFile != null && outputFile.name.endsWith('.aar')) { + def fileName = "${project.name}-${variant.baseName}-${version}.aar" + output.outputFile = new File(outputFile.parent, fileName) + } + } + } + } + + afterEvaluate { + android.libraryVariants.all { variant -> + def task = project.tasks.create "jar${variant.name.capitalize()}", Jar + task.description = "Create jar artifact for ${variant.name}" + task.dependsOn variant.javaCompile + task.from variant.javaCompile.destinationDir + task.destinationDir = project.file("${project.buildDir}/outputs/jar") + task.archiveName = "${project.name}-${variant.baseName}-${version}.jar" + artifacts.add('archives', task); + } + } + + task sourcesJar(type: Jar) { + from android.sourceSets.main.java.srcDirs + classifier = 'sources' + } + + artifacts { + archives sourcesJar + } + +} else { + + apply plugin: 'java' + apply plugin: 'maven' + + sourceCompatibility = JavaVersion.VERSION_1_7 + targetCompatibility = JavaVersion.VERSION_1_7 + + install { + repositories.mavenInstaller { + pom.artifactId = 'swagger-petstore-jersey2' + } + } + + task execute(type:JavaExec) { + main = System.getProperty('mainClass') + classpath = sourceSets.main.runtimeClasspath + } +} + +ext { + swagger_annotations_version = "1.5.0" + jackson_version = "2.4.2" + jersey_version = "2.6" + jodatime_version = "2.3" + junit_version = "4.8.1" +} + +dependencies { + compile "io.swagger:swagger-annotations:$swagger_annotations_version" + compile "org.glassfish.jersey.core:jersey-client:$jersey_version" + compile "org.glassfish.jersey.media:jersey-media-multipart:$jersey_version" + compile "com.fasterxml.jackson.core:jackson-core:$jackson_version" + compile "com.fasterxml.jackson.core:jackson-annotations:$jackson_version" + compile "com.fasterxml.jackson.core:jackson-databind:$jackson_version" + compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:2.1.5" + compile "joda-time:joda-time:$jodatime_version" + testCompile "junit:junit:$junit_version" +} diff --git a/samples/client/petstore/java/jersey2/gradle.properties b/samples/client/petstore/java/jersey2/gradle.properties new file mode 100644 index 000000000000..05644f0754af --- /dev/null +++ b/samples/client/petstore/java/jersey2/gradle.properties @@ -0,0 +1,2 @@ +# Uncomment to build for Android +#target = android \ No newline at end of file diff --git a/samples/client/petstore/java/jersey2/settings.gradle b/samples/client/petstore/java/jersey2/settings.gradle new file mode 100644 index 000000000000..498d426abeeb --- /dev/null +++ b/samples/client/petstore/java/jersey2/settings.gradle @@ -0,0 +1 @@ +rootProject.name = "swagger-petstore-jersey2" \ No newline at end of file diff --git a/samples/client/petstore/java/okhttp-gson/build.gradle b/samples/client/petstore/java/okhttp-gson/build.gradle index ada6a992573a..eea46b819d02 100644 --- a/samples/client/petstore/java/okhttp-gson/build.gradle +++ b/samples/client/petstore/java/okhttp-gson/build.gradle @@ -1,11 +1,89 @@ -apply plugin: 'java' -apply plugin: 'maven' +group = 'io.swagger' +version = '1.0.0' -sourceCompatibility = JavaVersion.VERSION_1_7 -targetCompatibility = JavaVersion.VERSION_1_7 +buildscript { + repositories { + jcenter() + } + dependencies { + classpath 'com.android.tools.build:gradle:1.2.2' + classpath 'com.github.dcendents:android-maven-plugin:1.2' + } +} repositories { - mavenCentral() + jcenter() +} + + +if(hasProperty('target') && target == 'android') { + + apply plugin: 'com.android.library' + apply plugin: 'com.github.dcendents.android-maven' + + android { + compileSdkVersion 22 + buildToolsVersion '22.0.0' + defaultConfig { + minSdkVersion 14 + targetSdkVersion 22 + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_7 + targetCompatibility JavaVersion.VERSION_1_7 + } + + // Rename the aar correctly + libraryVariants.all { variant -> + variant.outputs.each { output -> + def outputFile = output.outputFile + if (outputFile != null && outputFile.name.endsWith('.aar')) { + def fileName = "${project.name}-${variant.baseName}-${version}.aar" + output.outputFile = new File(outputFile.parent, fileName) + } + } + } + } + + afterEvaluate { + android.libraryVariants.all { variant -> + def task = project.tasks.create "jar${variant.name.capitalize()}", Jar + task.description = "Create jar artifact for ${variant.name}" + task.dependsOn variant.javaCompile + task.from variant.javaCompile.destinationDir + task.destinationDir = project.file("${project.buildDir}/outputs/jar") + task.archiveName = "${project.name}-${variant.baseName}-${version}.jar" + artifacts.add('archives', task); + } + } + + task sourcesJar(type: Jar) { + from android.sourceSets.main.java.srcDirs + classifier = 'sources' + } + + artifacts { + archives sourcesJar + } + +} else { + + apply plugin: 'java' + apply plugin: 'maven' + + sourceCompatibility = JavaVersion.VERSION_1_7 + targetCompatibility = JavaVersion.VERSION_1_7 + + install { + repositories.mavenInstaller { + pom.artifactId = 'swagger-petstore-okhttp-gson' + } + } + + task execute(type:JavaExec) { + main = System.getProperty('mainClass') + classpath = sourceSets.main.runtimeClasspath + } } dependencies { @@ -15,17 +93,3 @@ dependencies { compile 'com.brsanthu:migbase64:2.2' testCompile 'junit:junit:4.8.1' } - -group = 'io.swagger' -version = '1.0.0' - -install { - repositories.mavenInstaller { - pom.artifactId = 'swagger-petstore-okhttp-gson' - } -} - -task execute(type:JavaExec) { - main = System.getProperty('mainClass') - classpath = sourceSets.main.runtimeClasspath -} diff --git a/samples/client/petstore/java/okhttp-gson/gradle.properties b/samples/client/petstore/java/okhttp-gson/gradle.properties new file mode 100644 index 000000000000..05644f0754af --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson/gradle.properties @@ -0,0 +1,2 @@ +# Uncomment to build for Android +#target = android \ No newline at end of file diff --git a/samples/client/petstore/java/okhttp-gson/settings.gradle b/samples/client/petstore/java/okhttp-gson/settings.gradle new file mode 100644 index 000000000000..b73eec845910 --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson/settings.gradle @@ -0,0 +1 @@ +rootProject.name = "swagger-petstore-okhttp-gson" \ No newline at end of file diff --git a/samples/client/petstore/java/retrofit/build.gradle b/samples/client/petstore/java/retrofit/build.gradle new file mode 100644 index 000000000000..710d9da9a54c --- /dev/null +++ b/samples/client/petstore/java/retrofit/build.gradle @@ -0,0 +1,103 @@ +group = 'io.swagger' +version = '1.0.0' + +buildscript { + repositories { + jcenter() + } + dependencies { + classpath 'com.android.tools.build:gradle:1.2.2' + classpath 'com.github.dcendents:android-maven-plugin:1.2' + } +} + +repositories { + jcenter() +} + + +if(hasProperty('target') && target == 'android') { + + apply plugin: 'com.android.library' + apply plugin: 'com.github.dcendents.android-maven' + + android { + compileSdkVersion 22 + buildToolsVersion '22.0.0' + defaultConfig { + minSdkVersion 14 + targetSdkVersion 22 + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_7 + targetCompatibility JavaVersion.VERSION_1_7 + } + + // Rename the aar correctly + libraryVariants.all { variant -> + variant.outputs.each { output -> + def outputFile = output.outputFile + if (outputFile != null && outputFile.name.endsWith('.aar')) { + def fileName = "${project.name}-${variant.baseName}-${version}.aar" + output.outputFile = new File(outputFile.parent, fileName) + } + } + } + } + + afterEvaluate { + android.libraryVariants.all { variant -> + def task = project.tasks.create "jar${variant.name.capitalize()}", Jar + task.description = "Create jar artifact for ${variant.name}" + task.dependsOn variant.javaCompile + task.from variant.javaCompile.destinationDir + task.destinationDir = project.file("${project.buildDir}/outputs/jar") + task.archiveName = "${project.name}-${variant.baseName}-${version}.jar" + artifacts.add('archives', task); + } + } + + task sourcesJar(type: Jar) { + from android.sourceSets.main.java.srcDirs + classifier = 'sources' + } + + artifacts { + archives sourcesJar + } + +} else { + + apply plugin: 'java' + apply plugin: 'maven' + + sourceCompatibility = JavaVersion.VERSION_1_7 + targetCompatibility = JavaVersion.VERSION_1_7 + + install { + repositories.mavenInstaller { + pom.artifactId = 'swagger-petstore-retrofit' + } + } + + task execute(type:JavaExec) { + main = System.getProperty('mainClass') + classpath = sourceSets.main.runtimeClasspath + } +} + +ext { + okhttp_version = "2.3.0" + oltu_version = "1.0.0" + retrofit_version = "1.9.0" + swagger_annotations_version = "1.5.0" + junit_version = "4.12" +} + +dependencies { + compile "com.squareup.okhttp:okhttp:$okhttp_version" + compile "com.squareup.retrofit:retrofit:$retrofit_version" + compile "io.swagger:swagger-annotations:$swagger_annotations_version" + compile "org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:$oltu_version" + testCompile "junit:junit:$junit_version" +} diff --git a/samples/client/petstore/java/retrofit/gradle.properties b/samples/client/petstore/java/retrofit/gradle.properties new file mode 100644 index 000000000000..05644f0754af --- /dev/null +++ b/samples/client/petstore/java/retrofit/gradle.properties @@ -0,0 +1,2 @@ +# Uncomment to build for Android +#target = android \ No newline at end of file diff --git a/samples/client/petstore/java/retrofit/settings.gradle b/samples/client/petstore/java/retrofit/settings.gradle new file mode 100644 index 000000000000..7e540c099de9 --- /dev/null +++ b/samples/client/petstore/java/retrofit/settings.gradle @@ -0,0 +1 @@ +rootProject.name = "swagger-petstore-retrofit" \ No newline at end of file From 4e7d893a8e637d1072791a8422d4465412fce657 Mon Sep 17 00:00:00 2001 From: aersamkull Date: Tue, 13 Oct 2015 12:01:34 +0200 Subject: [PATCH 15/17] Updates to TypeScript Templates --- .../resources/TypeScript-Angular/api.mustache | 14 +++++++------- .../resources/TypeScript-Angular/model.mustache | 6 +++--- .../main/resources/TypeScript-node/api.mustache | 16 ++++++++-------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/TypeScript-Angular/api.mustache b/modules/swagger-codegen/src/main/resources/TypeScript-Angular/api.mustache index 233ead8bee48..2045dd353826 100644 --- a/modules/swagger-codegen/src/main/resources/TypeScript-Angular/api.mustache +++ b/modules/swagger-codegen/src/main/resources/TypeScript-Angular/api.mustache @@ -3,7 +3,7 @@ /* tslint:disable:no-unused-variable member-ordering */ {{#operations}} -module {{package}} { +namespace {{package}} { 'use strict'; {{#description}} @@ -24,16 +24,16 @@ module {{package}} { {{#operation}} public {{nickname}} ({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}extraHttpRequestParams?: any ) : ng.IHttpPromise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}{}{{/returnType}}> { - var path = this.basePath + '{{path}}'; + let path = this.basePath + '{{path}}'; {{#pathParams}} path = path.replace('{' + '{{baseName}}' + '}', String({{paramName}})); {{/pathParams}} - var queryParameters: any = {}; - var headerParams: any = {}; + let queryParameters: any = {}; + let headerParams: any = {}; {{#hasFormParams}} - var formParams: any = {}; + let formParams: any = {}; {{/hasFormParams}} {{#allParams}} @@ -63,7 +63,7 @@ module {{package}} { formParams['{{baseName}}'] = {{paramName}}; {{/formParams}} - var httpRequestParams: any = { + let httpRequestParams: any = { method: '{{httpMethod}}', url: path, json: {{#hasFormParams}}false{{/hasFormParams}}{{^hasFormParams}}true{{/hasFormParams}}, @@ -76,7 +76,7 @@ module {{package}} { }; if (extraHttpRequestParams) { - for (var k in extraHttpRequestParams) { + for (let k in extraHttpRequestParams) { if (extraHttpRequestParams.hasOwnProperty(k)) { httpRequestParams[k] = extraHttpRequestParams[k]; } diff --git a/modules/swagger-codegen/src/main/resources/TypeScript-Angular/model.mustache b/modules/swagger-codegen/src/main/resources/TypeScript-Angular/model.mustache index b425d14d5e43..5b57ed4dc94f 100644 --- a/modules/swagger-codegen/src/main/resources/TypeScript-Angular/model.mustache +++ b/modules/swagger-codegen/src/main/resources/TypeScript-Angular/model.mustache @@ -1,6 +1,6 @@ /// -module {{package}} { +namespace {{package}} { 'use strict'; {{#models}} @@ -10,7 +10,7 @@ module {{package}} { * {{{description}}} */ {{/description}} - export class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{ + export interface {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{ {{#vars}} {{#description}} @@ -23,7 +23,7 @@ module {{package}} { } {{#hasEnums}} - export module {{classname}} { + export namespace {{classname}} { {{#vars}} {{#isEnum}} diff --git a/modules/swagger-codegen/src/main/resources/TypeScript-node/api.mustache b/modules/swagger-codegen/src/main/resources/TypeScript-node/api.mustache index 6528a5d3a22c..4d03ae0f4248 100644 --- a/modules/swagger-codegen/src/main/resources/TypeScript-node/api.mustache +++ b/modules/swagger-codegen/src/main/resources/TypeScript-node/api.mustache @@ -27,7 +27,7 @@ export class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{ } {{#hasEnums}} -export module {{classname}} { +export namespace {{classname}} { {{#vars}} {{#isEnum}} export enum {{datatypeWithEnum}} { {{#allowableValues}}{{#values}} @@ -157,15 +157,15 @@ export class {{classname}} { {{#operation}} public {{nickname}} ({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) : Promise<{ response: http.ClientResponse; {{#returnType}}body: {{{returnType}}}; {{/returnType}} }> { - var path = this.url + this.basePath + '{{path}}'; + let path = this.url + this.basePath + '{{path}}'; {{#pathParams}} path = path.replace('{' + '{{baseName}}' + '}', String({{paramName}})); {{/pathParams}} - var queryParameters: any = {}; - var headerParams: any = {}; - var formParams: any = {}; + let queryParameters: any = {}; + let headerParams: any = {}; + let formParams: any = {}; {{#allParams}}{{#required}} // verify required parameter '{{paramName}}' is set @@ -183,7 +183,7 @@ export class {{classname}} { headerParams['{{baseName}}'] = {{paramName}}; {{/headerParams}} - var useFormData = false; + let useFormData = false; {{#formParams}} if ({{paramName}} !== undefined) { @@ -194,9 +194,9 @@ export class {{classname}} { {{/isFile}} {{/formParams}} - var deferred = promise.defer<{ response: http.ClientResponse; {{#returnType}}body: {{{returnType}}}; {{/returnType}} }>(); + let deferred = promise.defer<{ response: http.ClientResponse; {{#returnType}}body: {{{returnType}}}; {{/returnType}} }>(); - var requestOptions: request.Options = { + let requestOptions: request.Options = { method: '{{httpMethod}}', qs: queryParameters, headers: headerParams, From 988de07c1798890d0468ecfdcfe32db5a246b119 Mon Sep 17 00:00:00 2001 From: aersamkull Date: Tue, 13 Oct 2015 13:32:01 +0200 Subject: [PATCH 16/17] Fixes noImplicitAny Error --- .../src/main/resources/TypeScript-Angular/api.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/swagger-codegen/src/main/resources/TypeScript-Angular/api.mustache b/modules/swagger-codegen/src/main/resources/TypeScript-Angular/api.mustache index 2045dd353826..9681634a765a 100644 --- a/modules/swagger-codegen/src/main/resources/TypeScript-Angular/api.mustache +++ b/modules/swagger-codegen/src/main/resources/TypeScript-Angular/api.mustache @@ -16,7 +16,7 @@ namespace {{package}} { static $inject: string[] = ['$http', '$httpParamSerializer']; - constructor(private $http: ng.IHttpService, basePath?: string, private $httpParamSerializer?: (any) => any) { + constructor(private $http: ng.IHttpService, basePath?: string, private $httpParamSerializer?: (d: any) => any) { if (basePath) { this.basePath = basePath; } From 0b4b5e8839cd3f447fde86e4aa2a8db8fc2985f6 Mon Sep 17 00:00:00 2001 From: wing328 Date: Tue, 13 Oct 2015 23:47:42 +0800 Subject: [PATCH 17/17] Revert "Add support for top-level consumes and produces" --- .../io/swagger/codegen/CodegenConfig.java | 2 - .../io/swagger/codegen/DefaultCodegen.java | 50 +------ .../io/swagger/codegen/DefaultGenerator.java | 2 +- .../codegen/languages/SwiftCodegen.java | 6 +- .../java/io/swagger/codegen/CodegenTest.java | 48 ------- .../2_0/globalConsumesAndProduces.json | 130 ------------------ 6 files changed, 10 insertions(+), 228 deletions(-) delete mode 100644 modules/swagger-codegen/src/test/resources/2_0/globalConsumesAndProduces.json diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConfig.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConfig.java index b50147a6ff3e..10d7363cc35a 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConfig.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConfig.java @@ -67,8 +67,6 @@ public interface CodegenConfig { CodegenModel fromModel(String name, Model model, Map allDefinitions); - CodegenOperation fromOperation(String resourcePath, String httpMethod, Operation operation, Map definitions, Swagger swagger); - CodegenOperation fromOperation(String resourcePath, String httpMethod, Operation operation, Map definitions); List fromSecurity(Map schemes); diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java index b5dd47b47687..69d7cadbf0ad 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java @@ -867,12 +867,8 @@ public class DefaultCodegen { } return responses.get(code); } - + public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, Map definitions) { - return fromOperation(path, httpMethod, operation, definitions, null); - } - - public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, Map definitions, Swagger swagger) { CodegenOperation op = CodegenModelFactory.newInstance(CodegenModelType.OPERATION); Set imports = new HashSet(); op.vendorExtensions = operation.getVendorExtensions(); @@ -908,32 +904,15 @@ public class DefaultCodegen { op.summary = escapeText(operation.getSummary()); op.notes = escapeText(operation.getDescription()); op.tags = operation.getTags(); - op.hasConsumes = false; - op.hasProduces = false; - List consumes = new ArrayList(); - if (operation.getConsumes() != null) { - if (operation.getConsumes().size() > 0) { - // use consumes defined in the operation - consumes = operation.getConsumes(); - } else { - // empty list, do nothing to override global setting - } - } else if (swagger != null && swagger.getConsumes() != null && swagger.getConsumes().size() > 0) { - // use consumes defined globally - consumes = swagger.getConsumes(); - LOGGER.debug("No consumes defined in operation. Using global consumes (" + swagger.getConsumes() + ") for " + op.operationId); - } - - // if "consumes" is defined (per operation or using global definition) - if (consumes != null && consumes.size() > 0) { + if (operation.getConsumes() != null && operation.getConsumes().size() > 0) { List> c = new ArrayList>(); int count = 0; - for (String key : consumes) { + for (String key : operation.getConsumes()) { Map mediaType = new HashMap(); mediaType.put("mediaType", key); count += 1; - if (count < consumes.size()) { + if (count < operation.getConsumes().size()) { mediaType.put("hasMore", "true"); } else { mediaType.put("hasMore", null); @@ -944,29 +923,14 @@ public class DefaultCodegen { op.hasConsumes = true; } - List produces = new ArrayList(); - if (operation.getProduces() != null) { - if (operation.getProduces().size() > 0) { - // use produces defined in the operation - produces = operation.getProduces(); - } else { - // empty list, do nothing to override global setting - } - } else if (swagger != null && swagger.getProduces() != null && swagger.getProduces().size() > 0) { - // use produces defined globally - produces = swagger.getProduces(); - LOGGER.debug("No produces defined in operation. Using global produces (" + swagger.getProduces() + ") for " + op.operationId); - } - - // if "produces" is defined (per operation or using global definition) - if (produces != null && produces.size() > 0) { + if (operation.getProduces() != null && operation.getProduces().size() > 0) { List> c = new ArrayList>(); int count = 0; - for (String key : produces) { + for (String key : operation.getProduces()) { Map mediaType = new HashMap(); mediaType.put("mediaType", key); count += 1; - if (count < produces.size()) { + if (count < operation.getProduces().size()) { mediaType.put("hasMore", "true"); } else { mediaType.put("hasMore", null); diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java index 2b61635e0b9b..a785f45bdf21 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java @@ -470,7 +470,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator { for (String tag : tags) { CodegenOperation co = null; try { - co = config.fromOperation(resourcePath, httpMethod, operation, swagger.getDefinitions(), swagger); + co = config.fromOperation(resourcePath, httpMethod, operation, swagger.getDefinitions()); co.tags = new ArrayList(); co.tags.add(sanitizeTag(tag)); config.addOperationToGroup(sanitizeTag(tag), resourcePath, operation, co, operations); diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/SwiftCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/SwiftCodegen.java index 9bb1dfd61d47..55c3864adb7d 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/SwiftCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/SwiftCodegen.java @@ -1,11 +1,9 @@ package io.swagger.codegen.languages; import com.google.common.base.Predicate; - import com.google.common.collect.Iterators; import com.google.common.collect.Lists; import io.swagger.codegen.*; -import io.swagger.models.Swagger; import io.swagger.models.Model; import io.swagger.models.Operation; import io.swagger.models.parameters.HeaderParameter; @@ -258,7 +256,7 @@ public class SwiftCodegen extends DefaultCodegen implements CodegenConfig { } @Override - public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, Map definitions, Swagger swagger) { + public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, Map definitions) { path = normalizePath(path); List parameters = operation.getParameters(); parameters = Lists.newArrayList(Iterators.filter(parameters.iterator(), new Predicate() { @@ -268,7 +266,7 @@ public class SwiftCodegen extends DefaultCodegen implements CodegenConfig { } })); operation.setParameters(parameters); - return super.fromOperation(path, httpMethod, operation, definitions, swagger); + return super.fromOperation(path, httpMethod, operation, definitions); } private static String normalizePath(String path) { diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/CodegenTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/CodegenTest.java index 0fa8953e7bf5..ee70b427bfdf 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/CodegenTest.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/CodegenTest.java @@ -139,52 +139,4 @@ public class CodegenTest { Assert.assertTrue(op.bodyParam.isBinary); Assert.assertTrue(op.responses.get(0).isBinary); } - - @Test(description = "use operation consumes and produces") - public void localConsumesAndProducesTest() { - final Swagger model = new SwaggerParser().read("src/test/resources/2_0/globalConsumesAndProduces.json"); - final DefaultCodegen codegen = new DefaultCodegen(); - final String path = "/tests/localConsumesAndProduces"; - final Operation p = model.getPaths().get(path).getGet(); - CodegenOperation op = codegen.fromOperation(path, "get", p, model.getDefinitions(), model); - - Assert.assertTrue(op.hasConsumes); - Assert.assertEquals(op.consumes.size(), 1); - Assert.assertEquals(op.consumes.get(0).get("mediaType"), "application/json"); - Assert.assertTrue(op.hasProduces); - Assert.assertEquals(op.produces.size(), 1); - Assert.assertEquals(op.produces.get(0).get("mediaType"), "application/json"); - } - - @Test(description = "use spec consumes and produces") - public void globalConsumesAndProducesTest() { - final Swagger model = new SwaggerParser().read("src/test/resources/2_0/globalConsumesAndProduces.json"); - final DefaultCodegen codegen = new DefaultCodegen(); - final String path = "/tests/globalConsumesAndProduces"; - final Operation p = model.getPaths().get(path).getGet(); - CodegenOperation op = codegen.fromOperation(path, "get", p, model.getDefinitions(), model); - - Assert.assertTrue(op.hasConsumes); - Assert.assertEquals(op.consumes.size(), 1); - Assert.assertEquals(op.consumes.get(0).get("mediaType"), "application/global_consumes"); - Assert.assertTrue(op.hasProduces); - Assert.assertEquals(op.produces.size(), 1); - Assert.assertEquals(op.produces.get(0).get("mediaType"), "application/global_produces"); - } - - @Test(description = "use operation consumes and produces (reset in operation with empty array)") - public void localResetConsumesAndProducesTest() { - final Swagger model = new SwaggerParser().read("src/test/resources/2_0/globalConsumesAndProduces.json"); - final DefaultCodegen codegen = new DefaultCodegen(); - final String path = "/tests/localResetConsumesAndProduces"; - final Operation p = model.getPaths().get(path).getGet(); - CodegenOperation op = codegen.fromOperation(path, "get", p, model.getDefinitions(), model); - - Assert.assertNotNull(op); - Assert.assertFalse(op.hasConsumes); - Assert.assertNull(op.consumes); - Assert.assertFalse(op.hasProduces); - Assert.assertNull(op.produces); - - } } diff --git a/modules/swagger-codegen/src/test/resources/2_0/globalConsumesAndProduces.json b/modules/swagger-codegen/src/test/resources/2_0/globalConsumesAndProduces.json deleted file mode 100644 index 520218ed707e..000000000000 --- a/modules/swagger-codegen/src/test/resources/2_0/globalConsumesAndProduces.json +++ /dev/null @@ -1,130 +0,0 @@ -{ - "swagger": "2.0", - "info": { - "description": "Spec for testing global consumes and produces", - "version": "1.0.0", - "title": "Swagger Petstore", - "termsOfService": "http://swagger.io/terms/", - "contact": { - "email": "apiteam@swagger.io" - }, - "license": { - "name": "Apache 2.0", - "url": "http://www.apache.org/licenses/LICENSE-2.0.html" - } - }, - "host": "petstore.swagger.io", - "basePath": "/v2", - "consumes": ["application/global_consumes"], - "produces": ["application/global_produces"], - "schemes": [ - "http" - ], - "paths": { - "/tests/localConsumesAndProduces": { - "get": { - "tags": [ - "tests" - ], - "summary": "Operation with local consumes and produces", - "description": "", - "operationId": "localConsumesAndProduces", - "produces": [ - "application/json" - ], - "consumes": [ - "application/json" - ], - "parameters": [ - ], - "responses": { - "200": { - "description": "successful operation. Returning a simple int.", - "schema": { - "type": "integer", - "format": "int64" - } - } - } - } - }, - "/tests/globalConsumesAndProduces": { - "get": { - "tags": [ - "tests" - ], - "summary": "Operation with global consumes and produces", - "description": "", - "operationId": "globalConsumesAndProduces", - "parameters": [ - ], - "responses": { - "200": { - "description": "successful operation. Returning a simple int.", - "schema": { - "type": "integer", - "format": "int64" - } - } - } - } - }, - "/tests/localResetConsumesAndProduces": { - "get": { - "tags": [ - "tests" - ], - "summary": "Operation with local consumes and produces set to empty (reset)", - "description": "", - "operationId": "localResetConsumesAndProduces", - "parameters": [ - ], - "consumes": [], - "produces": [], - "responses": { - "200": { - "description": "successful operation. Returning a simple int.", - "schema": { - "type": "integer", - "format": "int64" - } - } - } - } - } - - }, - "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "api_key", - "in": "header" - }, - "petstore_auth": { - "type": "oauth2", - "authorizationUrl": "http://petstore.swagger.io/api/oauth/dialog", - "flow": "implicit", - "scopes": { - "write:pets": "modify pets in your account", - "read:pets": "read your pets" - } - } - }, - "definitions": { - "CustomModel": { - "required": [ - "id" - ], - "properties": { - "id": { - "type": "integer", - "format": "int64" - }, - "name": { - "type": "string", - "example": "doggie" - } - } - } - } -}