From 9311dcaccbfac1d8beda29a6017be217f462b399 Mon Sep 17 00:00:00 2001 From: wing328 Date: Sat, 10 Oct 2015 18:39:54 +0800 Subject: [PATCH 1/7] 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 10d7363cc35..b50147a6ff3 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 efc0aa31dbc..d0185c0ad02 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 a785f45bdf2..2b61635e0b9 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 55c3864adb7..9bb1dfd61d4 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 4445bc52ad2..0afb511073c 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 48a7cf0d6c1..4b132c57be5 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 83fe5741cd7..8bf5f75c5ad 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 84f10969e5b..e340e0e2b86 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 b890e03570f..156700c9a76 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 ec41ecd9907..21f314684fd 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 5c3c313b2e2..75cf8d51b0e 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 e8dea97be93..57af48845e1 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 b64b52d2225..1b0f9558695 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 efdc1c896ab..0d281b9d1fa 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 2/7] 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 d0185c0ad02..558f22bc0a0 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 ee70b427bfd..68ebb349e6c 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 3/7] 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 00000000000..221d00b6dad --- /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 4/7] 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 fc3c7907862..dcd33575fc6 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 16ce311c59e..3f1f926b331 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 4b132c57be5..48a7cf0d6c1 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 8bf5f75c5ad..83fe5741cd7 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 156700c9a76..64ff58e31e6 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 5fdf86b43af..8450022164c 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 c13e99f29fc..61640d687ac 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 a9d30a00147..bb1b66c19a4 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 235ff1c4106..b33aa87a505 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 f4672e2a358..7f546330f3a 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 4f747bcd6a1..77e9c448718 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 008be48ee4d..5e333ee79ef 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 5/7] 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 0afb511073c..4445bc52ad2 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 dcd33575fc6..fc3c7907862 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 3f1f926b331..16ce311c59e 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 e340e0e2b86..84f10969e5b 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 64ff58e31e6..b890e03570f 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 8450022164c..5fdf86b43af 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 21f314684fd..ec41ecd9907 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 75cf8d51b0e..5c3c313b2e2 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 57af48845e1..e8dea97be93 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 1b0f9558695..b64b52d2225 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 0d281b9d1fa..efdc1c896ab 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 61640d687ac..c13e99f29fc 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 bb1b66c19a4..a9d30a00147 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 b33aa87a505..235ff1c4106 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 7f546330f3a..f4672e2a358 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 77e9c448718..4f747bcd6a1 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 5e333ee79ef..008be48ee4d 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 6/7] 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 68ebb349e6c..0fa8953e7bf 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 7/7] 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 221d00b6dad..520218ed707 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 +}