From bf46da7c1407eb477d76729f5fb30c3a5de427f3 Mon Sep 17 00:00:00 2001 From: James Ebentier Date: Wed, 25 Mar 2015 11:44:46 -0700 Subject: [PATCH 001/192] Python: modifying request headers in ApiClient to act like those in Java and PHP --- .../src/main/resources/python/swagger.mustache | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/python/swagger.mustache b/modules/swagger-codegen/src/main/resources/python/swagger.mustache index 1cfc60981b..13fe146591 100644 --- a/modules/swagger-codegen/src/main/resources/python/swagger.mustache +++ b/modules/swagger-codegen/src/main/resources/python/swagger.mustache @@ -28,18 +28,25 @@ class ApiClient(object): headerValue: a header value to pass when making calls to the API """ def __init__(self, host=None, headerName=None, headerValue=None): - self.headerName = headerName - self.headerValue = headerValue + self.defaultHeaders = {} + if (headerName is not None): + self.defaultHeaders[headerName] = headerValue self.host = host self.cookie = None self.boundary = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(30)) + def setDefaultHeader(headerName, headerValue): + self.defaultHeaders[headerName] = headerValue + def callAPI(self, resourcePath, method, queryParams, postData, headerParams=None, files=None): url = self.host + resourcePath + + mergedHeaderParams = self.defaultHeaders.copy() + mergedHeaderParams.update(headerParams) headers = {} - if headerParams: + if mergedHeaderParams: for param, value in headerParams.iteritems(): headers[param] = ApiClient.sanitizeForSerialization(value) From fbe069cf5cb664d1e08145fe563557c272d5c600 Mon Sep 17 00:00:00 2001 From: geekerzp Date: Thu, 26 Mar 2015 10:07:33 +0800 Subject: [PATCH 002/192] add jsonmodel in objective-c client --- .../codegen/languages/ObjcClientCodegen.java | 53 ++++++++++--- .../src/main/resources/objc/Podfile.mustache | 1 + .../src/main/resources/objc/SWGObject.h | 5 +- .../src/main/resources/objc/SWGObject.m | 13 ---- .../main/resources/objc/model-body.mustache | 75 +------------------ .../main/resources/objc/model-header.mustache | 15 ++-- .../src/test/scala/Objc/ObjcModelTest.scala | 11 +-- 7 files changed, 61 insertions(+), 112 deletions(-) diff --git a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/ObjcClientCodegen.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/ObjcClientCodegen.java index 2e91cafa99..96d491aea7 100644 --- a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/ObjcClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/ObjcClientCodegen.java @@ -48,6 +48,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig { "NSObject", "NSArray", "NSNumber", + "NSDate", "NSDictionary", "NSMutableArray", "NSMutableDictionary") @@ -57,6 +58,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig { "NSNumber", "NSString", "NSObject", + "NSDate", "bool") ); @@ -70,9 +72,8 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig { typeMapping = new HashMap(); typeMapping.put("enum", "NSString"); - typeMapping.put("Date", "SWGDate"); - typeMapping.put("DateTime", "SWGDate"); - // typeMapping.put("Date", "SWGDate"); + typeMapping.put("Date", "NSDate"); + typeMapping.put("DateTime", "NSDate"); typeMapping.put("boolean", "NSNumber"); typeMapping.put("string", "NSString"); typeMapping.put("integer", "NSNumber"); @@ -87,13 +88,13 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig { typeMapping.put("object", "NSObject"); importMapping = new HashMap (); - importMapping.put("Date", "SWGDate"); foundationClasses = new HashSet ( Arrays.asList( "NSNumber", "NSObject", "NSString", + "NSDate", "NSDictionary") ); @@ -151,11 +152,45 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig { @Override public String getTypeDeclaration(Property p) { - String swaggerType = getSwaggerType(p); - if(languageSpecificPrimitives.contains(swaggerType) && !foundationClasses.contains(swaggerType)) - return toModelName(swaggerType); - else - return swaggerType + "*"; + if (p instanceof ArrayProperty) { + ArrayProperty ap = (ArrayProperty) p; + Property inner = ap.getItems(); + String innerType = getSwaggerType(inner); + + // In this codition, type of property p is array of primitive, + // return container type with pointer, e.g. `NSArray*' + if (languageSpecificPrimitives.contains(innerType)) + return getSwaggerType(p) + "*"; + + // In this codition, type of property p is array of model, + // return container type combine inner type with pointer, e.g. `NSArray*' + String innerTypeDeclaration = getTypeDeclaration(inner); + + if (innerTypeDeclaration.endsWith("*")) + innerTypeDeclaration = innerTypeDeclaration.substring(0, innerTypeDeclaration.length() - 1); + + return getSwaggerType(p) + "<" + innerTypeDeclaration + ">*"; + } + else { + String swaggerType = getSwaggerType(p); + + // In this codition, type of p is objective-c primitive type, e.g. `NSSNumber', + // return type of p with pointer, e.g. `NSNumber*' + if (languageSpecificPrimitives.contains(swaggerType) && + foundationClasses.contains(swaggerType)) { + return swaggerType + "*"; + } + // In this codition, type of p is c primitive type, e.g. `bool', + // return type of p, e.g. `bool' + else if (languageSpecificPrimitives.contains(swaggerType)) { + return swaggerType; + } + // In this codition, type of p is objective-c object type, e.g. `SWGPet', + // return type of p with pointer, e.g. `' + else { + return swaggerType + "*"; + } + } } @Override diff --git a/modules/swagger-codegen/src/main/resources/objc/Podfile.mustache b/modules/swagger-codegen/src/main/resources/objc/Podfile.mustache index ea7deab262..1a9d463c86 100644 --- a/modules/swagger-codegen/src/main/resources/objc/Podfile.mustache +++ b/modules/swagger-codegen/src/main/resources/objc/Podfile.mustache @@ -1,3 +1,4 @@ platform :ios, '6.0' xcodeproj '{{projectName}}/{{projectName}}.xcodeproj' pod 'AFNetworking', '~> 2.1' +pod 'JSONModel', '~> 1.0' diff --git a/modules/swagger-codegen/src/main/resources/objc/SWGObject.h b/modules/swagger-codegen/src/main/resources/objc/SWGObject.h index 031bae6927..ccec208abc 100644 --- a/modules/swagger-codegen/src/main/resources/objc/SWGObject.h +++ b/modules/swagger-codegen/src/main/resources/objc/SWGObject.h @@ -1,6 +1,5 @@ #import +#import "JSONModel.h" -@interface SWGObject : NSObject -- (id) initWithValues:(NSDictionary*)dict; -- (NSDictionary*) asDictionary; +@interface SWGObject : JSONModel @end diff --git a/modules/swagger-codegen/src/main/resources/objc/SWGObject.m b/modules/swagger-codegen/src/main/resources/objc/SWGObject.m index 9b37b3592b..1f897ab1d5 100644 --- a/modules/swagger-codegen/src/main/resources/objc/SWGObject.m +++ b/modules/swagger-codegen/src/main/resources/objc/SWGObject.m @@ -1,17 +1,4 @@ #import "SWGObject.h" @implementation SWGObject - -- (id) initWithValues:(NSDictionary*)dict { - return self; -} - -- (NSDictionary*) asDictionary{ - return [NSDictionary init]; -} - -- (NSString*)description { - return [NSString stringWithFormat:@"%@ %@", [super description], [self asDictionary]]; -} - @end diff --git a/modules/swagger-codegen/src/main/resources/objc/model-body.mustache b/modules/swagger-codegen/src/main/resources/objc/model-body.mustache index 17d2ec8083..f27d1d67db 100644 --- a/modules/swagger-codegen/src/main/resources/objc/model-body.mustache +++ b/modules/swagger-codegen/src/main/resources/objc/model-body.mustache @@ -1,81 +1,12 @@ {{#models}} {{#model}} -#import "SWGDate.h" #import "{{classname}}.h" @implementation {{classname}} - --(id){{#vars}}{{name}}: ({{datatype}}) {{name}} - {{/vars}} -{{newline}}{ - {{#vars}}_{{name}} = {{name}}; - {{/vars}} - - return self; -} - --(id) initWithValues:(NSDictionary*)dict + ++ (JSONKeyMapper *)keyMapper { - self = [super init]; - if(self) { - {{#vars}}{{#isPrimitiveType}}_{{name}} = dict[@"{{baseName}}"];{{/isPrimitiveType}} - {{#complexType}} - id {{name}}_dict = dict[@"{{baseName}}"]; - {{#isContainer}} - if([{{name}}_dict isKindOfClass:[NSArray class]]) { - NSMutableArray * objs = [[NSMutableArray alloc] initWithCapacity:[(NSArray*){{name}}_dict count]]; - if([(NSArray*){{name}}_dict count] > 0) { - for (NSDictionary* dict in (NSArray*){{name}}_dict) { - {{{complexType}}}* d = [[{{#instantiationType}}NSClassFromString(@"{{{instantiationType}}}") {{/instantiationType}}{{^instantiationType}}{{{complexType}}}{{/instantiationType}} alloc] initWithValues:dict]; - [objs addObject:d]; - } - _{{{name}}} = [[NSArray alloc] initWithArray:objs]; - } - else - _{{name}} = [[NSArray alloc] init]; - } - else { - _{{name}} = [[NSArray alloc] init]; - } - {{/isContainer}}{{#isNotContainer}} - if({{name}}_dict != nil) - _{{name}} = [[{{#instantiationType}}NSClassFromString(@"{{{instantiationType}}}") {{/instantiationType}}{{^instantiationType}}{{{complexType}}} {{/instantiationType}} alloc]{{setter}}:{{name}}_dict]; - {{/isNotContainer}} - {{/complexType}} - {{/vars}}{{newline}} - } - return self; -} - --(NSDictionary*) asDictionary { - NSMutableDictionary* dict = [[NSMutableDictionary alloc] init]; - {{#vars}} - {{#complexType}} - if(_{{name}} != nil){ - if([_{{name}} isKindOfClass:[NSArray class]]){ - NSMutableArray * array = [[NSMutableArray alloc] init]; - for( {{complexType}} *{{name}} in (NSArray*)_{{name}}) { - [array addObject:[(SWGObject*){{name}} asDictionary]]; - } - dict[@"{{name}}"] = array; - } - else if(_{{name}} && [_{{name}} isKindOfClass:[SWGDate class]]) { - NSString * dateString = [(SWGDate*)_{{name}} toString]; - if(dateString){ - dict[@"{{name}}"] = dateString; - } - } - else { - {{/complexType}} - if(_{{name}} != nil) dict[@"{{baseName}}"] = {{#complexType}}[(SWGObject*){{/complexType}}_{{name}} {{#complexType}}asDictionary]{{/complexType}}; - {{#complexType}} - } - } - {{/complexType}} - {{/vars}} - - NSDictionary* output = [dict copy]; - return output; + return [[JSONKeyMapper alloc] initWithDictionary:@{ {{#vars}}@"{{baseName}}": @"{{name}}"{{#hasMore}}, {{/hasMore}}{{/vars}} }]; } {{/model}} diff --git a/modules/swagger-codegen/src/main/resources/objc/model-header.mustache b/modules/swagger-codegen/src/main/resources/objc/model-header.mustache index cb954f9121..e1e9a85a2d 100644 --- a/modules/swagger-codegen/src/main/resources/objc/model-header.mustache +++ b/modules/swagger-codegen/src/main/resources/objc/model-header.mustache @@ -6,17 +6,16 @@ {{#models}} {{#model}} +@protocol {{classname}} +@end + @interface {{classname}} : SWGObject {{#vars}} -@property(nonatomic) {{datatype}} {{name}}; {{#description}}/* {{{description}}} {{#isNotRequired}}[optional]{{/isNotRequired}} */{{/description}}{{newline}} +{{#description}}/* {{{description}}} {{#isNotRequired}}[optional]{{/isNotRequired}} */{{/description}} +@property(nonatomic) {{{ datatype }}}{{#isNotRequired}}{{/isNotRequired}} {{name}}; {{/vars}} -- (id) {{#vars}}{{name}}: ({{datatype}}) {{name}}{{#hasMore}}{{newline}} {{/hasMore}}{{^hasMore}};{{/hasMore}} - {{/vars}} -{{newline}} -- (id) initWithValues: (NSDictionary*)dict; -- (NSDictionary*) asDictionary; -{{newline}} + @end {{/model}} -{{/models}} \ No newline at end of file +{{/models}} diff --git a/modules/swagger-codegen/src/test/scala/Objc/ObjcModelTest.scala b/modules/swagger-codegen/src/test/scala/Objc/ObjcModelTest.scala index e0de2110dd..069b4a8e35 100644 --- a/modules/swagger-codegen/src/test/scala/Objc/ObjcModelTest.scala +++ b/modules/swagger-codegen/src/test/scala/Objc/ObjcModelTest.scala @@ -56,17 +56,14 @@ class ObjcModelTest extends FlatSpec with Matchers { vars.get(1).isNotContainer should equal (true) vars.get(2).baseName should be ("createdAt") - vars.get(2).complexType should be ("SWGDate") - vars.get(2).datatype should be ("SWGDate*") + vars.get(2).datatype should be ("NSDate*") vars.get(2).name should be ("createdAt") vars.get(2).defaultValue should be (null) - vars.get(2).baseType should be ("SWGDate") + vars.get(2).baseType should be ("NSDate") vars.get(2).hasMore should equal (null) vars.get(2).required should equal (false) vars.get(2).isNotContainer should equal (true) - (cm.imports.asScala.toSet & - Set("SWGDate")).size should be (1) } it should "convert a model with list property" in { @@ -173,7 +170,7 @@ class ObjcModelTest extends FlatSpec with Matchers { val vars = cm.vars vars.get(0).baseName should be ("children") vars.get(0).complexType should be ("SWGChildren") - vars.get(0).datatype should be ("NSArray*") + vars.get(0).datatype should be ("NSArray*") vars.get(0).name should be ("children") vars.get(0).baseType should be ("NSArray") vars.get(0).containerType should be ("array") @@ -259,4 +256,4 @@ class ObjcModelTest extends FlatSpec with Matchers { insectCo.imports.size should be (1) insectCo.imports.contains("SWGInsect") should equal (true) } -} \ No newline at end of file +} From 93e19e48db4a0a362a425b492eefed991d702257 Mon Sep 17 00:00:00 2001 From: geekerzp Date: Thu, 26 Mar 2015 11:23:47 +0800 Subject: [PATCH 003/192] update swagger-core version to 1.5.4-M1-SNAPSHOT --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7e8e7b9ddc..b456ea7c60 100644 --- a/pom.xml +++ b/pom.xml @@ -363,7 +363,7 @@ 1.0.3 2.11.1 2.3.4 - 1.5.3-M1-SNAPSHOT + 1.5.4-M1-SNAPSHOT 2.1.4 2.3 1.2 From fe11b064af34b09d76fa5307038da8633823cca7 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 26 Mar 2015 16:27:00 +0800 Subject: [PATCH 004/192] update java doc --- .../src/main/resources/Java/api.mustache | 10 +-- .../java/io/swagger/client/api/PetApi.java | 61 ++++++++++++++++--- .../java/io/swagger/client/api/StoreApi.java | 27 ++++++-- .../java/io/swagger/client/api/UserApi.java | 57 ++++++++++++++--- 4 files changed, 131 insertions(+), 24 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/Java/api.mustache b/modules/swagger-codegen/src/main/resources/Java/api.mustache index ad26268d71..5160ed2ff4 100644 --- a/modules/swagger-codegen/src/main/resources/Java/api.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/api.mustache @@ -36,10 +36,12 @@ public class {{classname}} { } {{#operation}} - {{#errorList}} //error info- code: {{code}} reason: "{{reason}}" model: {{#responseModel}}{{responseModel}} - {{/responseModel}}{{^responseModel}} - {{/responseModel}} - {{/errorList}} + /** + * {{summary}} + * {{notes}}{{newLine}} +{{#allParams}}{{newLine}} * @param {{paramName}} {{description}} +{{/allParams}}{{newLine}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}{{newLine}} + */ public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException { Object postBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}}; {{#requiredParamCount}} diff --git a/samples/client/petstore/java/src/main/java/io/swagger/client/api/PetApi.java b/samples/client/petstore/java/src/main/java/io/swagger/client/api/PetApi.java index 21f5beea53..8e81b18148 100644 --- a/samples/client/petstore/java/src/main/java/io/swagger/client/api/PetApi.java +++ b/samples/client/petstore/java/src/main/java/io/swagger/client/api/PetApi.java @@ -35,7 +35,12 @@ public class PetApi { } - + /** + * Update an existing pet + * + * @param body Pet object that needs to be added to the store + * @return void + */ public void updatePet (Pet body) throws ApiException { Object postBody = body; @@ -85,7 +90,12 @@ public class PetApi { } } - + /** + * Add a new pet to the store + * + * @param body Pet object that needs to be added to the store + * @return void + */ public void addPet (Pet body) throws ApiException { Object postBody = body; @@ -135,7 +145,12 @@ public class PetApi { } } - + /** + * Finds Pets by status + * Multiple status values can be provided with comma seperated strings + * @param status Status values that need to be considered for filter + * @return List + */ public List findPetsByStatus (List status) throws ApiException { Object postBody = null; @@ -187,7 +202,12 @@ public class PetApi { } } - + /** + * Finds Pets by tags + * Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. + * @param tags Tags to filter by + * @return List + */ public List findPetsByTags (List tags) throws ApiException { Object postBody = null; @@ -239,7 +259,12 @@ 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 + * @return Pet + */ public Pet getPetById (Long petId) throws ApiException { Object postBody = null; @@ -290,7 +315,14 @@ public class PetApi { } } - + /** + * Updates a pet in the store with form data + * + * @param petId ID of pet that needs to be updated + * @param name Updated name of the pet + * @param status Updated status of the pet + * @return void + */ public void updatePetWithForm (String petId, String name, String status) throws ApiException { Object postBody = null; @@ -349,7 +381,13 @@ public class PetApi { } } - + /** + * Deletes a pet + * + * @param apiKey + * @param petId Pet id to delete + * @return void + */ public void deletePet (String apiKey, Long petId) throws ApiException { Object postBody = null; @@ -401,7 +439,14 @@ public class PetApi { } } - + /** + * uploads an image + * + * @param petId ID of pet to update + * @param additionalMetadata Additional data to pass to server + * @param file file to upload + * @return void + */ public void uploadFile (Long petId, String additionalMetadata, File file) throws ApiException { Object postBody = null; diff --git a/samples/client/petstore/java/src/main/java/io/swagger/client/api/StoreApi.java b/samples/client/petstore/java/src/main/java/io/swagger/client/api/StoreApi.java index 1da7519154..c0cf5243d7 100644 --- a/samples/client/petstore/java/src/main/java/io/swagger/client/api/StoreApi.java +++ b/samples/client/petstore/java/src/main/java/io/swagger/client/api/StoreApi.java @@ -35,7 +35,11 @@ public class StoreApi { } - + /** + * Returns pet inventories by status + * Returns a map of status codes to quantities + * @return Map + */ public Map getInventory () throws ApiException { Object postBody = null; @@ -85,7 +89,12 @@ public class StoreApi { } } - + /** + * Place an order for a pet + * + * @param body order placed for purchasing the pet + * @return Order + */ public Order placeOrder (Order body) throws ApiException { Object postBody = body; @@ -135,7 +144,12 @@ public class StoreApi { } } - + /** + * Find purchase order by ID + * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + * @param orderId ID of pet that needs to be fetched + * @return Order + */ public Order getOrderById (String orderId) throws ApiException { Object postBody = null; @@ -186,7 +200,12 @@ public class StoreApi { } } - + /** + * Delete purchase order by ID + * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + * @param orderId ID of the order that needs to be deleted + * @return void + */ public void deleteOrder (String orderId) throws ApiException { Object postBody = null; diff --git a/samples/client/petstore/java/src/main/java/io/swagger/client/api/UserApi.java b/samples/client/petstore/java/src/main/java/io/swagger/client/api/UserApi.java index 7b8b2cad83..2b7cac7529 100644 --- a/samples/client/petstore/java/src/main/java/io/swagger/client/api/UserApi.java +++ b/samples/client/petstore/java/src/main/java/io/swagger/client/api/UserApi.java @@ -35,7 +35,12 @@ public class UserApi { } - + /** + * Create user + * This can only be done by the logged in user. + * @param body Created user object + * @return void + */ public void createUser (User body) throws ApiException { Object postBody = body; @@ -85,7 +90,12 @@ public class UserApi { } } - + /** + * Creates list of users with given input array + * + * @param body List of user object + * @return void + */ public void createUsersWithArrayInput (List body) throws ApiException { Object postBody = body; @@ -135,7 +145,12 @@ public class UserApi { } } - + /** + * Creates list of users with given input array + * + * @param body List of user object + * @return void + */ public void createUsersWithListInput (List body) throws ApiException { Object postBody = body; @@ -185,7 +200,13 @@ public class UserApi { } } - + /** + * Logs user into the system + * + * @param username The user name for login + * @param password The password for login in clear text + * @return String + */ public String loginUser (String username, String password) throws ApiException { Object postBody = null; @@ -239,7 +260,11 @@ public class UserApi { } } - + /** + * Logs out current logged in user session + * + * @return void + */ public void logoutUser () throws ApiException { Object postBody = null; @@ -289,7 +314,12 @@ public class UserApi { } } - + /** + * Get user by user name + * + * @param username The name that needs to be fetched. Use user1 for testing. + * @return User + */ public User getUserByName (String username) throws ApiException { Object postBody = null; @@ -340,7 +370,13 @@ public class UserApi { } } - + /** + * Updated user + * This can only be done by the logged in user. + * @param username name that need to be deleted + * @param body Updated user object + * @return void + */ public void updateUser (String username, User body) throws ApiException { Object postBody = body; @@ -391,7 +427,12 @@ public class UserApi { } } - + /** + * Delete user + * This can only be done by the logged in user. + * @param username The name that needs to be deleted + * @return void + */ public void deleteUser (String username) throws ApiException { Object postBody = null; From a4690d76db7ab980c282c7fbd32cca3c46e6c161 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 26 Mar 2015 19:55:48 +0800 Subject: [PATCH 005/192] update ruby doc --- .../src/main/resources/ruby/api.mustache | 14 ++-- samples/client/petstore/ruby/lib/pet_api.rb | 73 ++++++++++--------- samples/client/petstore/ruby/lib/store_api.rb | 34 ++++----- samples/client/petstore/ruby/lib/user_api.rb | 71 +++++++++--------- 4 files changed, 95 insertions(+), 97 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/ruby/api.mustache b/modules/swagger-codegen/src/main/resources/ruby/api.mustache index c045a46f69..7bdb4764e2 100644 --- a/modules/swagger-codegen/src/main/resources/ruby/api.mustache +++ b/modules/swagger-codegen/src/main/resources/ruby/api.mustache @@ -9,12 +9,17 @@ class {{classname}} URI.encode(string.to_s) end - {{#operation}} +{{#operation}} +{{newline}} + # {{summary}} + # {{notes}}{{newLine}} +{{#allParams}}{{^optional}}{{newLine}} # @param {{paramName}} {{description}} +{{/optional}}{{/allParams}}{{#allParams}}{{#optional}}{{newLine}} # @option opts [{{dataType}}] :{{baseName}} {{description}} +{{/optional}}{{/allParams}} # @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}{{newLine}} def self.{{nickname}} ({{#allParams}}{{paramName}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}},{{/allParams}} opts={}) query_param_keys = [{{#queryParams}}:{{paramName}}{{#hasMore}},{{/hasMore}}{{/queryParams}}] {{#requiredParamCount}} - # verify existence of params {{#requiredParams}} raise "{{{paramName}}} is required" if {{{paramName}}}.nil? @@ -40,7 +45,6 @@ class {{classname}} headers = {} {{#headerParams}}{{#optional}}headers[:'{{{baseName}}}'] = options[:'{{{paramName}}}'] if options[:'{{{paramName}}}']{{/optional}}{{/headerParams}} {{#headerParams}}{{^optional}}headers[:'{{{baseName}}}'] = {{{paramName}}}{{/optional}}{{/headerParams}} - # http body (model) post_body = nil {{#bodyParam}} @@ -55,7 +59,6 @@ class {{classname}} end end post_body = array - else if body.respond_to?("to_body".to_sym) post_body = body.to_body @@ -65,12 +68,10 @@ class {{classname}} end end {{/bodyParam}} - # form parameters form_parameter_hash = {} {{#formParams}}{{#optional}}form_parameter_hash["{{baseName}}"] = options[:'{{paramName}}'] if options[:'{{paramName}}']{{/optional}} {{^optional}}form_parameter_hash["{{baseName}}"] = {{paramName}}{{/optional}}{{/formParams}} - {{#returnType}} response = Swagger::Request.new(:{{httpMethod}}, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make.body {{#returnContainer}} @@ -81,7 +82,6 @@ class {{classname}} {{/returnType}} {{newline}} end - {{/operation}} end {{/operations}} diff --git a/samples/client/petstore/ruby/lib/pet_api.rb b/samples/client/petstore/ruby/lib/pet_api.rb index e8b9644453..072bc0d0cf 100644 --- a/samples/client/petstore/ruby/lib/pet_api.rb +++ b/samples/client/petstore/ruby/lib/pet_api.rb @@ -8,7 +8,11 @@ class PetApi URI.encode(string.to_s) end - + + # Update an existing pet + # + # @param body Pet object that needs to be added to the store + # @return void def self.updatePet (body, opts={}) query_param_keys = [] @@ -32,7 +36,6 @@ class PetApi headers = {} - # http body (model) post_body = nil @@ -47,7 +50,6 @@ class PetApi end end post_body = array - else if body.respond_to?("to_body".to_sym) post_body = body.to_body @@ -57,11 +59,9 @@ class PetApi end end - # form parameters form_parameter_hash = {} - Swagger::Request.new(:PUT, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make @@ -69,7 +69,10 @@ class PetApi end - + # Add a new pet to the store + # + # @param body Pet object that needs to be added to the store + # @return void def self.addPet (body, opts={}) query_param_keys = [] @@ -93,7 +96,6 @@ class PetApi headers = {} - # http body (model) post_body = nil @@ -108,7 +110,6 @@ class PetApi end end post_body = array - else if body.respond_to?("to_body".to_sym) post_body = body.to_body @@ -118,11 +119,9 @@ class PetApi end end - # form parameters form_parameter_hash = {} - Swagger::Request.new(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make @@ -130,7 +129,10 @@ class PetApi end - + # Finds Pets by status + # Multiple status values can be provided with comma seperated strings + # @param status Status values that need to be considered for filter + # @return array[Pet] def self.findPetsByStatus (status, opts={}) query_param_keys = [:status] @@ -154,15 +156,12 @@ class PetApi headers = {} - # http body (model) post_body = nil - # form parameters form_parameter_hash = {} - response = Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make.body @@ -172,7 +171,10 @@ class PetApi end - + # Finds Pets by tags + # Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. + # @param tags Tags to filter by + # @return array[Pet] def self.findPetsByTags (tags, opts={}) query_param_keys = [:tags] @@ -196,15 +198,12 @@ class PetApi headers = {} - # http body (model) post_body = nil - # form parameters form_parameter_hash = {} - response = Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make.body @@ -214,7 +213,10 @@ class PetApi end - + # Find pet by ID + # Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions + # @param pet_id ID of pet that needs to be fetched + # @return Pet def self.getPetById (pet_id, opts={}) query_param_keys = [] @@ -239,15 +241,12 @@ class PetApi headers = {} - # http body (model) post_body = nil - # form parameters form_parameter_hash = {} - response = Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make.body Pet.new(response) @@ -256,7 +255,12 @@ class PetApi end - + # Updates a pet in the store with form data + # + # @param pet_id ID of pet that needs to be updated + # @param name Updated name of the pet + # @param status Updated status of the pet + # @return void def self.updatePetWithForm (pet_id,name,status, opts={}) query_param_keys = [] @@ -283,17 +287,14 @@ class PetApi headers = {} - # http body (model) post_body = nil - # form parameters form_parameter_hash = {} form_parameter_hash["name"] = name form_parameter_hash["status"] = status - Swagger::Request.new(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make @@ -301,7 +302,11 @@ class PetApi end - + # Deletes a pet + # + # @param api_key + # @param pet_id Pet id to delete + # @return void def self.deletePet (api_key,pet_id, opts={}) query_param_keys = [] @@ -327,15 +332,12 @@ class PetApi headers = {} headers[:'api_key'] = api_key - # http body (model) post_body = nil - # form parameters form_parameter_hash = {} - Swagger::Request.new(:DELETE, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make @@ -343,7 +345,12 @@ class PetApi end - + # uploads an image + # + # @param pet_id ID of pet to update + # @param additional_metadata Additional data to pass to server + # @param file file to upload + # @return void def self.uploadFile (pet_id,additional_metadata,file, opts={}) query_param_keys = [] @@ -370,22 +377,18 @@ class PetApi headers = {} - # http body (model) post_body = nil - # form parameters form_parameter_hash = {} form_parameter_hash["additionalMetadata"] = additional_metadata form_parameter_hash["file"] = file - Swagger::Request.new(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make end - end diff --git a/samples/client/petstore/ruby/lib/store_api.rb b/samples/client/petstore/ruby/lib/store_api.rb index 4c553185ef..c0796debeb 100644 --- a/samples/client/petstore/ruby/lib/store_api.rb +++ b/samples/client/petstore/ruby/lib/store_api.rb @@ -8,7 +8,10 @@ class StoreApi URI.encode(string.to_s) end - + + # Returns pet inventories by status + # Returns a map of status codes to quantities + # @return map[string,int] def self.getInventory ( opts={}) query_param_keys = [] @@ -31,15 +34,12 @@ class StoreApi headers = {} - # http body (model) post_body = nil - # form parameters form_parameter_hash = {} - response = Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make.body @@ -49,7 +49,10 @@ class StoreApi end - + # Place an order for a pet + # + # @param body order placed for purchasing the pet + # @return Order def self.placeOrder (body, opts={}) query_param_keys = [] @@ -73,7 +76,6 @@ class StoreApi headers = {} - # http body (model) post_body = nil @@ -88,7 +90,6 @@ class StoreApi end end post_body = array - else if body.respond_to?("to_body".to_sym) post_body = body.to_body @@ -98,11 +99,9 @@ class StoreApi end end - # form parameters form_parameter_hash = {} - response = Swagger::Request.new(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make.body Order.new(response) @@ -111,7 +110,10 @@ class StoreApi end - + # Find purchase order by ID + # For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + # @param order_id ID of pet that needs to be fetched + # @return Order def self.getOrderById (order_id, opts={}) query_param_keys = [] @@ -136,15 +138,12 @@ class StoreApi headers = {} - # http body (model) post_body = nil - # form parameters form_parameter_hash = {} - response = Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make.body Order.new(response) @@ -153,7 +152,10 @@ class StoreApi end - + # Delete purchase order by ID + # For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + # @param order_id ID of the order that needs to be deleted + # @return void def self.deleteOrder (order_id, opts={}) query_param_keys = [] @@ -178,20 +180,16 @@ class StoreApi headers = {} - # http body (model) post_body = nil - # form parameters form_parameter_hash = {} - Swagger::Request.new(:DELETE, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make end - end diff --git a/samples/client/petstore/ruby/lib/user_api.rb b/samples/client/petstore/ruby/lib/user_api.rb index 6738cddb5f..80a7e81442 100644 --- a/samples/client/petstore/ruby/lib/user_api.rb +++ b/samples/client/petstore/ruby/lib/user_api.rb @@ -8,7 +8,11 @@ class UserApi URI.encode(string.to_s) end - + + # Create user + # This can only be done by the logged in user. + # @param body Created user object + # @return void def self.createUser (body, opts={}) query_param_keys = [] @@ -32,7 +36,6 @@ class UserApi headers = {} - # http body (model) post_body = nil @@ -47,7 +50,6 @@ class UserApi end end post_body = array - else if body.respond_to?("to_body".to_sym) post_body = body.to_body @@ -57,11 +59,9 @@ class UserApi end end - # form parameters form_parameter_hash = {} - Swagger::Request.new(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make @@ -69,7 +69,10 @@ class UserApi end - + # Creates list of users with given input array + # + # @param body List of user object + # @return void def self.createUsersWithArrayInput (body, opts={}) query_param_keys = [] @@ -93,7 +96,6 @@ class UserApi headers = {} - # http body (model) post_body = nil @@ -108,7 +110,6 @@ class UserApi end end post_body = array - else if body.respond_to?("to_body".to_sym) post_body = body.to_body @@ -118,11 +119,9 @@ class UserApi end end - # form parameters form_parameter_hash = {} - Swagger::Request.new(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make @@ -130,7 +129,10 @@ class UserApi end - + # Creates list of users with given input array + # + # @param body List of user object + # @return void def self.createUsersWithListInput (body, opts={}) query_param_keys = [] @@ -154,7 +156,6 @@ class UserApi headers = {} - # http body (model) post_body = nil @@ -169,7 +170,6 @@ class UserApi end end post_body = array - else if body.respond_to?("to_body".to_sym) post_body = body.to_body @@ -179,11 +179,9 @@ class UserApi end end - # form parameters form_parameter_hash = {} - Swagger::Request.new(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make @@ -191,7 +189,11 @@ class UserApi end - + # Logs user into the system + # + # @param username The user name for login + # @param password The password for login in clear text + # @return string def self.loginUser (username,password, opts={}) query_param_keys = [:username,:password] @@ -216,15 +218,12 @@ class UserApi headers = {} - # http body (model) post_body = nil - # form parameters form_parameter_hash = {} - response = Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make.body string.new(response) @@ -233,7 +232,9 @@ class UserApi end - + # Logs out current logged in user session + # + # @return void def self.logoutUser ( opts={}) query_param_keys = [] @@ -256,15 +257,12 @@ class UserApi headers = {} - # http body (model) post_body = nil - # form parameters form_parameter_hash = {} - Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make @@ -272,7 +270,10 @@ class UserApi end - + # Get user by user name + # + # @param username The name that needs to be fetched. Use user1 for testing. + # @return User def self.getUserByName (username, opts={}) query_param_keys = [] @@ -297,15 +298,12 @@ class UserApi headers = {} - # http body (model) post_body = nil - # form parameters form_parameter_hash = {} - response = Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make.body User.new(response) @@ -314,7 +312,11 @@ class UserApi end - + # Updated user + # This can only be done by the logged in user. + # @param username name that need to be deleted + # @param body Updated user object + # @return void def self.updateUser (username,body, opts={}) query_param_keys = [] @@ -340,7 +342,6 @@ class UserApi headers = {} - # http body (model) post_body = nil @@ -355,7 +356,6 @@ class UserApi end end post_body = array - else if body.respond_to?("to_body".to_sym) post_body = body.to_body @@ -365,11 +365,9 @@ class UserApi end end - # form parameters form_parameter_hash = {} - Swagger::Request.new(:PUT, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make @@ -377,7 +375,10 @@ class UserApi end - + # Delete user + # This can only be done by the logged in user. + # @param username The name that needs to be deleted + # @return void def self.deleteUser (username, opts={}) query_param_keys = [] @@ -402,20 +403,16 @@ class UserApi headers = {} - # http body (model) post_body = nil - # form parameters form_parameter_hash = {} - Swagger::Request.new(:DELETE, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make end - end From 9ba13988316cb3d39cffd3e21c1924a553b41cfc Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 26 Mar 2015 20:20:28 +0800 Subject: [PATCH 006/192] better ruby method argument format --- .../swagger-codegen/src/main/resources/ruby/api.mustache | 2 +- samples/client/petstore/ruby/lib/pet_api.rb | 6 +++--- samples/client/petstore/ruby/lib/store_api.rb | 2 +- samples/client/petstore/ruby/lib/user_api.rb | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/ruby/api.mustache b/modules/swagger-codegen/src/main/resources/ruby/api.mustache index 7bdb4764e2..62d9ac0165 100644 --- a/modules/swagger-codegen/src/main/resources/ruby/api.mustache +++ b/modules/swagger-codegen/src/main/resources/ruby/api.mustache @@ -16,7 +16,7 @@ class {{classname}} {{#allParams}}{{^optional}}{{newLine}} # @param {{paramName}} {{description}} {{/optional}}{{/allParams}}{{#allParams}}{{#optional}}{{newLine}} # @option opts [{{dataType}}] :{{baseName}} {{description}} {{/optional}}{{/allParams}} # @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}{{newLine}} - def self.{{nickname}} ({{#allParams}}{{paramName}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}},{{/allParams}} opts={}) + def self.{{nickname}} ({{#allParams}}{{paramName}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}, {{/allParams}}opts={}) query_param_keys = [{{#queryParams}}:{{paramName}}{{#hasMore}},{{/hasMore}}{{/queryParams}}] {{#requiredParamCount}} diff --git a/samples/client/petstore/ruby/lib/pet_api.rb b/samples/client/petstore/ruby/lib/pet_api.rb index 072bc0d0cf..a254ad8edf 100644 --- a/samples/client/petstore/ruby/lib/pet_api.rb +++ b/samples/client/petstore/ruby/lib/pet_api.rb @@ -261,7 +261,7 @@ class PetApi # @param name Updated name of the pet # @param status Updated status of the pet # @return void - def self.updatePetWithForm (pet_id,name,status, opts={}) + def self.updatePetWithForm (pet_id, name, status, opts={}) query_param_keys = [] @@ -307,7 +307,7 @@ class PetApi # @param api_key # @param pet_id Pet id to delete # @return void - def self.deletePet (api_key,pet_id, opts={}) + def self.deletePet (api_key, pet_id, opts={}) query_param_keys = [] @@ -351,7 +351,7 @@ class PetApi # @param additional_metadata Additional data to pass to server # @param file file to upload # @return void - def self.uploadFile (pet_id,additional_metadata,file, opts={}) + def self.uploadFile (pet_id, additional_metadata, file, opts={}) query_param_keys = [] diff --git a/samples/client/petstore/ruby/lib/store_api.rb b/samples/client/petstore/ruby/lib/store_api.rb index c0796debeb..cc93b0edd0 100644 --- a/samples/client/petstore/ruby/lib/store_api.rb +++ b/samples/client/petstore/ruby/lib/store_api.rb @@ -12,7 +12,7 @@ class StoreApi # Returns pet inventories by status # Returns a map of status codes to quantities # @return map[string,int] - def self.getInventory ( opts={}) + def self.getInventory (opts={}) query_param_keys = [] diff --git a/samples/client/petstore/ruby/lib/user_api.rb b/samples/client/petstore/ruby/lib/user_api.rb index 80a7e81442..3bb359674c 100644 --- a/samples/client/petstore/ruby/lib/user_api.rb +++ b/samples/client/petstore/ruby/lib/user_api.rb @@ -194,7 +194,7 @@ class UserApi # @param username The user name for login # @param password The password for login in clear text # @return string - def self.loginUser (username,password, opts={}) + def self.loginUser (username, password, opts={}) query_param_keys = [:username,:password] @@ -235,7 +235,7 @@ class UserApi # Logs out current logged in user session # # @return void - def self.logoutUser ( opts={}) + def self.logoutUser (opts={}) query_param_keys = [] @@ -317,7 +317,7 @@ class UserApi # @param username name that need to be deleted # @param body Updated user object # @return void - def self.updateUser (username,body, opts={}) + def self.updateUser (username, body, opts={}) query_param_keys = [] From ae52a62c0963e2485e74786f38e4d29c51060d0c Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 26 Mar 2015 16:27:00 +0800 Subject: [PATCH 007/192] update java doc --- .../src/main/resources/Java/api.mustache | 10 +-- .../java/io/swagger/client/api/PetApi.java | 61 ++++++++++++++++--- .../java/io/swagger/client/api/StoreApi.java | 27 ++++++-- .../java/io/swagger/client/api/UserApi.java | 57 ++++++++++++++--- 4 files changed, 131 insertions(+), 24 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/Java/api.mustache b/modules/swagger-codegen/src/main/resources/Java/api.mustache index 20829f8297..b6c87b4da1 100644 --- a/modules/swagger-codegen/src/main/resources/Java/api.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/api.mustache @@ -37,10 +37,12 @@ public class {{classname}} { } {{#operation}} - {{#errorList}} //error info- code: {{code}} reason: "{{reason}}" model: {{#responseModel}}{{responseModel}} - {{/responseModel}}{{^responseModel}} - {{/responseModel}} - {{/errorList}} + /** + * {{summary}} + * {{notes}}{{newLine}} +{{#allParams}}{{newLine}} * @param {{paramName}} {{description}} +{{/allParams}}{{newLine}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}{{newLine}} + */ public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException { Object postBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}}; {{#requiredParamCount}} diff --git a/samples/client/petstore/java/src/main/java/io/swagger/client/api/PetApi.java b/samples/client/petstore/java/src/main/java/io/swagger/client/api/PetApi.java index cf6cdc3f0c..234cdadece 100644 --- a/samples/client/petstore/java/src/main/java/io/swagger/client/api/PetApi.java +++ b/samples/client/petstore/java/src/main/java/io/swagger/client/api/PetApi.java @@ -36,7 +36,12 @@ public class PetApi { } - + /** + * Update an existing pet + * + * @param body Pet object that needs to be added to the store + * @return void + */ public void updatePet (Pet body) throws ApiException { Object postBody = body; @@ -81,7 +86,12 @@ public class PetApi { } } - + /** + * Add a new pet to the store + * + * @param body Pet object that needs to be added to the store + * @return void + */ public void addPet (Pet body) throws ApiException { Object postBody = body; @@ -126,7 +136,12 @@ public class PetApi { } } - + /** + * Finds Pets by status + * Multiple status values can be provided with comma seperated strings + * @param status Status values that need to be considered for filter + * @return List + */ public List findPetsByStatus (List status) throws ApiException { Object postBody = null; @@ -173,7 +188,12 @@ public class PetApi { } } - + /** + * Finds Pets by tags + * Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. + * @param tags Tags to filter by + * @return List + */ public List findPetsByTags (List tags) throws ApiException { Object postBody = null; @@ -220,7 +240,12 @@ 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 + * @return Pet + */ public Pet getPetById (Long petId) throws ApiException { Object postBody = null; @@ -266,7 +291,14 @@ public class PetApi { } } - + /** + * Updates a pet in the store with form data + * + * @param petId ID of pet that needs to be updated + * @param name Updated name of the pet + * @param status Updated status of the pet + * @return void + */ public void updatePetWithForm (String petId, String name, String status) throws ApiException { Object postBody = null; @@ -320,7 +352,13 @@ public class PetApi { } } - + /** + * Deletes a pet + * + * @param apiKey + * @param petId Pet id to delete + * @return void + */ public void deletePet (String apiKey, Long petId) throws ApiException { Object postBody = null; @@ -367,7 +405,14 @@ public class PetApi { } } - + /** + * uploads an image + * + * @param petId ID of pet to update + * @param additionalMetadata Additional data to pass to server + * @param file file to upload + * @return void + */ public void uploadFile (Long petId, String additionalMetadata, File file) throws ApiException { Object postBody = null; diff --git a/samples/client/petstore/java/src/main/java/io/swagger/client/api/StoreApi.java b/samples/client/petstore/java/src/main/java/io/swagger/client/api/StoreApi.java index 318c55df21..cff340e69d 100644 --- a/samples/client/petstore/java/src/main/java/io/swagger/client/api/StoreApi.java +++ b/samples/client/petstore/java/src/main/java/io/swagger/client/api/StoreApi.java @@ -36,7 +36,11 @@ public class StoreApi { } - + /** + * Returns pet inventories by status + * Returns a map of status codes to quantities + * @return Map + */ public Map getInventory () throws ApiException { Object postBody = null; @@ -81,7 +85,12 @@ public class StoreApi { } } - + /** + * Place an order for a pet + * + * @param body order placed for purchasing the pet + * @return Order + */ public Order placeOrder (Order body) throws ApiException { Object postBody = body; @@ -126,7 +135,12 @@ public class StoreApi { } } - + /** + * Find purchase order by ID + * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + * @param orderId ID of pet that needs to be fetched + * @return Order + */ public Order getOrderById (String orderId) throws ApiException { Object postBody = null; @@ -172,7 +186,12 @@ public class StoreApi { } } - + /** + * Delete purchase order by ID + * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + * @param orderId ID of the order that needs to be deleted + * @return void + */ public void deleteOrder (String orderId) throws ApiException { Object postBody = null; diff --git a/samples/client/petstore/java/src/main/java/io/swagger/client/api/UserApi.java b/samples/client/petstore/java/src/main/java/io/swagger/client/api/UserApi.java index e50c034ab1..2296c0223c 100644 --- a/samples/client/petstore/java/src/main/java/io/swagger/client/api/UserApi.java +++ b/samples/client/petstore/java/src/main/java/io/swagger/client/api/UserApi.java @@ -36,7 +36,12 @@ public class UserApi { } - + /** + * Create user + * This can only be done by the logged in user. + * @param body Created user object + * @return void + */ public void createUser (User body) throws ApiException { Object postBody = body; @@ -81,7 +86,12 @@ public class UserApi { } } - + /** + * Creates list of users with given input array + * + * @param body List of user object + * @return void + */ public void createUsersWithArrayInput (List body) throws ApiException { Object postBody = body; @@ -126,7 +136,12 @@ public class UserApi { } } - + /** + * Creates list of users with given input array + * + * @param body List of user object + * @return void + */ public void createUsersWithListInput (List body) throws ApiException { Object postBody = body; @@ -171,7 +186,13 @@ public class UserApi { } } - + /** + * Logs user into the system + * + * @param username The user name for login + * @param password The password for login in clear text + * @return String + */ public String loginUser (String username, String password) throws ApiException { Object postBody = null; @@ -220,7 +241,11 @@ public class UserApi { } } - + /** + * Logs out current logged in user session + * + * @return void + */ public void logoutUser () throws ApiException { Object postBody = null; @@ -265,7 +290,12 @@ public class UserApi { } } - + /** + * Get user by user name + * + * @param username The name that needs to be fetched. Use user1 for testing. + * @return User + */ public User getUserByName (String username) throws ApiException { Object postBody = null; @@ -311,7 +341,13 @@ public class UserApi { } } - + /** + * Updated user + * This can only be done by the logged in user. + * @param username name that need to be deleted + * @param body Updated user object + * @return void + */ public void updateUser (String username, User body) throws ApiException { Object postBody = body; @@ -357,7 +393,12 @@ public class UserApi { } } - + /** + * Delete user + * This can only be done by the logged in user. + * @param username The name that needs to be deleted + * @return void + */ public void deleteUser (String username) throws ApiException { Object postBody = null; From fb2ab794552f0cefd9acb6d4c26b3043ca285551 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 26 Mar 2015 19:55:48 +0800 Subject: [PATCH 008/192] update ruby doc --- .../src/main/resources/ruby/api.mustache | 14 +- samples/client/petstore/ruby/lib/pet_api.rb | 73 +++---- samples/client/petstore/ruby/lib/store_api.rb | 195 ++++++++++++++++++ samples/client/petstore/ruby/lib/user_api.rb | 71 +++---- 4 files changed, 274 insertions(+), 79 deletions(-) create mode 100644 samples/client/petstore/ruby/lib/store_api.rb diff --git a/modules/swagger-codegen/src/main/resources/ruby/api.mustache b/modules/swagger-codegen/src/main/resources/ruby/api.mustache index c045a46f69..7bdb4764e2 100644 --- a/modules/swagger-codegen/src/main/resources/ruby/api.mustache +++ b/modules/swagger-codegen/src/main/resources/ruby/api.mustache @@ -9,12 +9,17 @@ class {{classname}} URI.encode(string.to_s) end - {{#operation}} +{{#operation}} +{{newline}} + # {{summary}} + # {{notes}}{{newLine}} +{{#allParams}}{{^optional}}{{newLine}} # @param {{paramName}} {{description}} +{{/optional}}{{/allParams}}{{#allParams}}{{#optional}}{{newLine}} # @option opts [{{dataType}}] :{{baseName}} {{description}} +{{/optional}}{{/allParams}} # @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}{{newLine}} def self.{{nickname}} ({{#allParams}}{{paramName}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}},{{/allParams}} opts={}) query_param_keys = [{{#queryParams}}:{{paramName}}{{#hasMore}},{{/hasMore}}{{/queryParams}}] {{#requiredParamCount}} - # verify existence of params {{#requiredParams}} raise "{{{paramName}}} is required" if {{{paramName}}}.nil? @@ -40,7 +45,6 @@ class {{classname}} headers = {} {{#headerParams}}{{#optional}}headers[:'{{{baseName}}}'] = options[:'{{{paramName}}}'] if options[:'{{{paramName}}}']{{/optional}}{{/headerParams}} {{#headerParams}}{{^optional}}headers[:'{{{baseName}}}'] = {{{paramName}}}{{/optional}}{{/headerParams}} - # http body (model) post_body = nil {{#bodyParam}} @@ -55,7 +59,6 @@ class {{classname}} end end post_body = array - else if body.respond_to?("to_body".to_sym) post_body = body.to_body @@ -65,12 +68,10 @@ class {{classname}} end end {{/bodyParam}} - # form parameters form_parameter_hash = {} {{#formParams}}{{#optional}}form_parameter_hash["{{baseName}}"] = options[:'{{paramName}}'] if options[:'{{paramName}}']{{/optional}} {{^optional}}form_parameter_hash["{{baseName}}"] = {{paramName}}{{/optional}}{{/formParams}} - {{#returnType}} response = Swagger::Request.new(:{{httpMethod}}, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make.body {{#returnContainer}} @@ -81,7 +82,6 @@ class {{classname}} {{/returnType}} {{newline}} end - {{/operation}} end {{/operations}} diff --git a/samples/client/petstore/ruby/lib/pet_api.rb b/samples/client/petstore/ruby/lib/pet_api.rb index e8b9644453..072bc0d0cf 100644 --- a/samples/client/petstore/ruby/lib/pet_api.rb +++ b/samples/client/petstore/ruby/lib/pet_api.rb @@ -8,7 +8,11 @@ class PetApi URI.encode(string.to_s) end - + + # Update an existing pet + # + # @param body Pet object that needs to be added to the store + # @return void def self.updatePet (body, opts={}) query_param_keys = [] @@ -32,7 +36,6 @@ class PetApi headers = {} - # http body (model) post_body = nil @@ -47,7 +50,6 @@ class PetApi end end post_body = array - else if body.respond_to?("to_body".to_sym) post_body = body.to_body @@ -57,11 +59,9 @@ class PetApi end end - # form parameters form_parameter_hash = {} - Swagger::Request.new(:PUT, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make @@ -69,7 +69,10 @@ class PetApi end - + # Add a new pet to the store + # + # @param body Pet object that needs to be added to the store + # @return void def self.addPet (body, opts={}) query_param_keys = [] @@ -93,7 +96,6 @@ class PetApi headers = {} - # http body (model) post_body = nil @@ -108,7 +110,6 @@ class PetApi end end post_body = array - else if body.respond_to?("to_body".to_sym) post_body = body.to_body @@ -118,11 +119,9 @@ class PetApi end end - # form parameters form_parameter_hash = {} - Swagger::Request.new(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make @@ -130,7 +129,10 @@ class PetApi end - + # Finds Pets by status + # Multiple status values can be provided with comma seperated strings + # @param status Status values that need to be considered for filter + # @return array[Pet] def self.findPetsByStatus (status, opts={}) query_param_keys = [:status] @@ -154,15 +156,12 @@ class PetApi headers = {} - # http body (model) post_body = nil - # form parameters form_parameter_hash = {} - response = Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make.body @@ -172,7 +171,10 @@ class PetApi end - + # Finds Pets by tags + # Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. + # @param tags Tags to filter by + # @return array[Pet] def self.findPetsByTags (tags, opts={}) query_param_keys = [:tags] @@ -196,15 +198,12 @@ class PetApi headers = {} - # http body (model) post_body = nil - # form parameters form_parameter_hash = {} - response = Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make.body @@ -214,7 +213,10 @@ class PetApi end - + # Find pet by ID + # Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions + # @param pet_id ID of pet that needs to be fetched + # @return Pet def self.getPetById (pet_id, opts={}) query_param_keys = [] @@ -239,15 +241,12 @@ class PetApi headers = {} - # http body (model) post_body = nil - # form parameters form_parameter_hash = {} - response = Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make.body Pet.new(response) @@ -256,7 +255,12 @@ class PetApi end - + # Updates a pet in the store with form data + # + # @param pet_id ID of pet that needs to be updated + # @param name Updated name of the pet + # @param status Updated status of the pet + # @return void def self.updatePetWithForm (pet_id,name,status, opts={}) query_param_keys = [] @@ -283,17 +287,14 @@ class PetApi headers = {} - # http body (model) post_body = nil - # form parameters form_parameter_hash = {} form_parameter_hash["name"] = name form_parameter_hash["status"] = status - Swagger::Request.new(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make @@ -301,7 +302,11 @@ class PetApi end - + # Deletes a pet + # + # @param api_key + # @param pet_id Pet id to delete + # @return void def self.deletePet (api_key,pet_id, opts={}) query_param_keys = [] @@ -327,15 +332,12 @@ class PetApi headers = {} headers[:'api_key'] = api_key - # http body (model) post_body = nil - # form parameters form_parameter_hash = {} - Swagger::Request.new(:DELETE, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make @@ -343,7 +345,12 @@ class PetApi end - + # uploads an image + # + # @param pet_id ID of pet to update + # @param additional_metadata Additional data to pass to server + # @param file file to upload + # @return void def self.uploadFile (pet_id,additional_metadata,file, opts={}) query_param_keys = [] @@ -370,22 +377,18 @@ class PetApi headers = {} - # http body (model) post_body = nil - # form parameters form_parameter_hash = {} form_parameter_hash["additionalMetadata"] = additional_metadata form_parameter_hash["file"] = file - Swagger::Request.new(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make end - end diff --git a/samples/client/petstore/ruby/lib/store_api.rb b/samples/client/petstore/ruby/lib/store_api.rb new file mode 100644 index 0000000000..c0796debeb --- /dev/null +++ b/samples/client/petstore/ruby/lib/store_api.rb @@ -0,0 +1,195 @@ +require "uri" + +class StoreApi + basePath = "http://petstore.swagger.io/v2" + # apiInvoker = APIInvoker + + def self.escapeString(string) + URI.encode(string.to_s) + end + + + # Returns pet inventories by status + # Returns a map of status codes to quantities + # @return map[string,int] + def self.getInventory ( opts={}) + query_param_keys = [] + + + + # set default values and merge with input + options = { + + }.merge(opts) + + #resource path + path = "/store/inventory".sub('{format}','json') + + # pull querystring keys from options + queryopts = options.select do |key,value| + query_param_keys.include? key + end + + # header parameters, if any + headers = {} + + + # http body (model) + post_body = nil + + # form parameters + form_parameter_hash = {} + + + response = Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make.body + + response.map {|response| map.new(response) } + + + + end + + # Place an order for a pet + # + # @param body order placed for purchasing the pet + # @return Order + def self.placeOrder (body, opts={}) + query_param_keys = [] + + + + # set default values and merge with input + options = { + :'body' => body + + }.merge(opts) + + #resource path + path = "/store/order".sub('{format}','json') + + # pull querystring keys from options + queryopts = options.select do |key,value| + query_param_keys.include? key + end + + # header parameters, if any + headers = {} + + + # http body (model) + post_body = nil + + if body != nil + if body.is_a?(Array) + array = Array.new + body.each do |item| + if item.respond_to?("to_body".to_sym) + array.push item.to_body + else + array.push item + end + end + post_body = array + else + if body.respond_to?("to_body".to_sym) + post_body = body.to_body + else + post_body = body + end + end + end + + # form parameters + form_parameter_hash = {} + + + response = Swagger::Request.new(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make.body + Order.new(response) + + + + end + + # Find purchase order by ID + # For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + # @param order_id ID of pet that needs to be fetched + # @return Order + def self.getOrderById (order_id, opts={}) + query_param_keys = [] + + + + # set default values and merge with input + options = { + :'order_id' => order_id + + }.merge(opts) + + #resource path + path = "/store/order/{orderId}".sub('{format}','json').sub('{' + 'orderId' + '}', escapeString(order_id)) + + + # pull querystring keys from options + queryopts = options.select do |key,value| + query_param_keys.include? key + end + + # header parameters, if any + headers = {} + + + # http body (model) + post_body = nil + + # form parameters + form_parameter_hash = {} + + + response = Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make.body + Order.new(response) + + + + end + + # Delete purchase order by ID + # For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + # @param order_id ID of the order that needs to be deleted + # @return void + def self.deleteOrder (order_id, opts={}) + query_param_keys = [] + + + + # set default values and merge with input + options = { + :'order_id' => order_id + + }.merge(opts) + + #resource path + path = "/store/order/{orderId}".sub('{format}','json').sub('{' + 'orderId' + '}', escapeString(order_id)) + + + # pull querystring keys from options + queryopts = options.select do |key,value| + query_param_keys.include? key + end + + # header parameters, if any + headers = {} + + + # http body (model) + post_body = nil + + # form parameters + form_parameter_hash = {} + + + + Swagger::Request.new(:DELETE, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make + + + end +end diff --git a/samples/client/petstore/ruby/lib/user_api.rb b/samples/client/petstore/ruby/lib/user_api.rb index 6738cddb5f..80a7e81442 100644 --- a/samples/client/petstore/ruby/lib/user_api.rb +++ b/samples/client/petstore/ruby/lib/user_api.rb @@ -8,7 +8,11 @@ class UserApi URI.encode(string.to_s) end - + + # Create user + # This can only be done by the logged in user. + # @param body Created user object + # @return void def self.createUser (body, opts={}) query_param_keys = [] @@ -32,7 +36,6 @@ class UserApi headers = {} - # http body (model) post_body = nil @@ -47,7 +50,6 @@ class UserApi end end post_body = array - else if body.respond_to?("to_body".to_sym) post_body = body.to_body @@ -57,11 +59,9 @@ class UserApi end end - # form parameters form_parameter_hash = {} - Swagger::Request.new(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make @@ -69,7 +69,10 @@ class UserApi end - + # Creates list of users with given input array + # + # @param body List of user object + # @return void def self.createUsersWithArrayInput (body, opts={}) query_param_keys = [] @@ -93,7 +96,6 @@ class UserApi headers = {} - # http body (model) post_body = nil @@ -108,7 +110,6 @@ class UserApi end end post_body = array - else if body.respond_to?("to_body".to_sym) post_body = body.to_body @@ -118,11 +119,9 @@ class UserApi end end - # form parameters form_parameter_hash = {} - Swagger::Request.new(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make @@ -130,7 +129,10 @@ class UserApi end - + # Creates list of users with given input array + # + # @param body List of user object + # @return void def self.createUsersWithListInput (body, opts={}) query_param_keys = [] @@ -154,7 +156,6 @@ class UserApi headers = {} - # http body (model) post_body = nil @@ -169,7 +170,6 @@ class UserApi end end post_body = array - else if body.respond_to?("to_body".to_sym) post_body = body.to_body @@ -179,11 +179,9 @@ class UserApi end end - # form parameters form_parameter_hash = {} - Swagger::Request.new(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make @@ -191,7 +189,11 @@ class UserApi end - + # Logs user into the system + # + # @param username The user name for login + # @param password The password for login in clear text + # @return string def self.loginUser (username,password, opts={}) query_param_keys = [:username,:password] @@ -216,15 +218,12 @@ class UserApi headers = {} - # http body (model) post_body = nil - # form parameters form_parameter_hash = {} - response = Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make.body string.new(response) @@ -233,7 +232,9 @@ class UserApi end - + # Logs out current logged in user session + # + # @return void def self.logoutUser ( opts={}) query_param_keys = [] @@ -256,15 +257,12 @@ class UserApi headers = {} - # http body (model) post_body = nil - # form parameters form_parameter_hash = {} - Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make @@ -272,7 +270,10 @@ class UserApi end - + # Get user by user name + # + # @param username The name that needs to be fetched. Use user1 for testing. + # @return User def self.getUserByName (username, opts={}) query_param_keys = [] @@ -297,15 +298,12 @@ class UserApi headers = {} - # http body (model) post_body = nil - # form parameters form_parameter_hash = {} - response = Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make.body User.new(response) @@ -314,7 +312,11 @@ class UserApi end - + # Updated user + # This can only be done by the logged in user. + # @param username name that need to be deleted + # @param body Updated user object + # @return void def self.updateUser (username,body, opts={}) query_param_keys = [] @@ -340,7 +342,6 @@ class UserApi headers = {} - # http body (model) post_body = nil @@ -355,7 +356,6 @@ class UserApi end end post_body = array - else if body.respond_to?("to_body".to_sym) post_body = body.to_body @@ -365,11 +365,9 @@ class UserApi end end - # form parameters form_parameter_hash = {} - Swagger::Request.new(:PUT, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make @@ -377,7 +375,10 @@ class UserApi end - + # Delete user + # This can only be done by the logged in user. + # @param username The name that needs to be deleted + # @return void def self.deleteUser (username, opts={}) query_param_keys = [] @@ -402,20 +403,16 @@ class UserApi headers = {} - # http body (model) post_body = nil - # form parameters form_parameter_hash = {} - Swagger::Request.new(:DELETE, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make end - end From 3d53cfc298e45f6e6021d43c8e277c85e172a933 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 26 Mar 2015 20:20:28 +0800 Subject: [PATCH 009/192] better ruby method argument format --- .../swagger-codegen/src/main/resources/ruby/api.mustache | 2 +- samples/client/petstore/ruby/lib/pet_api.rb | 6 +++--- samples/client/petstore/ruby/lib/store_api.rb | 2 +- samples/client/petstore/ruby/lib/user_api.rb | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/ruby/api.mustache b/modules/swagger-codegen/src/main/resources/ruby/api.mustache index 7bdb4764e2..62d9ac0165 100644 --- a/modules/swagger-codegen/src/main/resources/ruby/api.mustache +++ b/modules/swagger-codegen/src/main/resources/ruby/api.mustache @@ -16,7 +16,7 @@ class {{classname}} {{#allParams}}{{^optional}}{{newLine}} # @param {{paramName}} {{description}} {{/optional}}{{/allParams}}{{#allParams}}{{#optional}}{{newLine}} # @option opts [{{dataType}}] :{{baseName}} {{description}} {{/optional}}{{/allParams}} # @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}{{newLine}} - def self.{{nickname}} ({{#allParams}}{{paramName}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}},{{/allParams}} opts={}) + def self.{{nickname}} ({{#allParams}}{{paramName}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}, {{/allParams}}opts={}) query_param_keys = [{{#queryParams}}:{{paramName}}{{#hasMore}},{{/hasMore}}{{/queryParams}}] {{#requiredParamCount}} diff --git a/samples/client/petstore/ruby/lib/pet_api.rb b/samples/client/petstore/ruby/lib/pet_api.rb index 072bc0d0cf..a254ad8edf 100644 --- a/samples/client/petstore/ruby/lib/pet_api.rb +++ b/samples/client/petstore/ruby/lib/pet_api.rb @@ -261,7 +261,7 @@ class PetApi # @param name Updated name of the pet # @param status Updated status of the pet # @return void - def self.updatePetWithForm (pet_id,name,status, opts={}) + def self.updatePetWithForm (pet_id, name, status, opts={}) query_param_keys = [] @@ -307,7 +307,7 @@ class PetApi # @param api_key # @param pet_id Pet id to delete # @return void - def self.deletePet (api_key,pet_id, opts={}) + def self.deletePet (api_key, pet_id, opts={}) query_param_keys = [] @@ -351,7 +351,7 @@ class PetApi # @param additional_metadata Additional data to pass to server # @param file file to upload # @return void - def self.uploadFile (pet_id,additional_metadata,file, opts={}) + def self.uploadFile (pet_id, additional_metadata, file, opts={}) query_param_keys = [] diff --git a/samples/client/petstore/ruby/lib/store_api.rb b/samples/client/petstore/ruby/lib/store_api.rb index c0796debeb..cc93b0edd0 100644 --- a/samples/client/petstore/ruby/lib/store_api.rb +++ b/samples/client/petstore/ruby/lib/store_api.rb @@ -12,7 +12,7 @@ class StoreApi # Returns pet inventories by status # Returns a map of status codes to quantities # @return map[string,int] - def self.getInventory ( opts={}) + def self.getInventory (opts={}) query_param_keys = [] diff --git a/samples/client/petstore/ruby/lib/user_api.rb b/samples/client/petstore/ruby/lib/user_api.rb index 80a7e81442..3bb359674c 100644 --- a/samples/client/petstore/ruby/lib/user_api.rb +++ b/samples/client/petstore/ruby/lib/user_api.rb @@ -194,7 +194,7 @@ class UserApi # @param username The user name for login # @param password The password for login in clear text # @return string - def self.loginUser (username,password, opts={}) + def self.loginUser (username, password, opts={}) query_param_keys = [:username,:password] @@ -235,7 +235,7 @@ class UserApi # Logs out current logged in user session # # @return void - def self.logoutUser ( opts={}) + def self.logoutUser (opts={}) query_param_keys = [] @@ -317,7 +317,7 @@ class UserApi # @param username name that need to be deleted # @param body Updated user object # @return void - def self.updateUser (username,body, opts={}) + def self.updateUser (username, body, opts={}) query_param_keys = [] From 8b98a92805511e17acf0a8bb1e611154b9d23910 Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Thu, 26 Mar 2015 20:32:59 -0700 Subject: [PATCH 010/192] adds tests, fixes for java templates --- .../main/resources/Java/apiInvoker.mustache | 11 +- modules/swagger-generator/pom.xml | 4 +- pom.xml | 1 + .../java/io/swagger/client/ApiInvoker.java | 11 +- .../io/swagger/client/model/ApiResponse.java | 64 ++++++ .../io/swagger/petstore/test/PetApiTest.java | 83 ++++++++ .../PetstoreClientTests/PetApiTest.m | 3 +- samples/client/petstore/objc/pom.xml | 6 +- samples/client/petstore/ruby/lib/store_api.rb | 197 ------------------ 9 files changed, 174 insertions(+), 206 deletions(-) create mode 100644 samples/client/petstore/java/src/main/java/io/swagger/client/model/ApiResponse.java create mode 100644 samples/client/petstore/java/src/test/java/io/swagger/petstore/test/PetApiTest.java delete mode 100644 samples/client/petstore/ruby/lib/store_api.rb diff --git a/modules/swagger-codegen/src/main/resources/Java/apiInvoker.mustache b/modules/swagger-codegen/src/main/resources/Java/apiInvoker.mustache index cc77f01a9a..d9d772eaaa 100644 --- a/modules/swagger-codegen/src/main/resources/Java/apiInvoker.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/apiInvoker.mustache @@ -16,6 +16,7 @@ import com.sun.jersey.multipart.FormDataMultiPart; import javax.ws.rs.core.Response.Status.Family; import javax.ws.rs.core.MediaType; +import java.util.Collection; import java.util.Map; import java.util.HashMap; import java.util.List; @@ -83,11 +84,19 @@ public class ApiInvoker { return ""; } else if (param instanceof Date) { return formatDateTime((Date) param); + } else if (param instanceof Collection) { + StringBuilder b = new StringBuilder(); + for(Object o : (Collection)param) { + if(b.length() > 0) { + b.append(","); + } + b.append(String.valueOf(o)); + } + return b.toString(); } else { return String.valueOf(param); } } - public void enableDebug() { isDebug = true; } diff --git a/modules/swagger-generator/pom.xml b/modules/swagger-generator/pom.xml index c9a9eb8d56..527dca732a 100644 --- a/modules/swagger-generator/pom.xml +++ b/modules/swagger-generator/pom.xml @@ -104,7 +104,7 @@ start-jetty pre-integration-test - run + start 0 @@ -226,7 +226,7 @@ 1.0.0 2.5 1.3.2 - 9.0.7.v20131107 + 9.2.9.v20150224 2.4.1 diff --git a/pom.xml b/pom.xml index 7e8e7b9ddc..6e781ee7ed 100644 --- a/pom.xml +++ b/pom.xml @@ -288,6 +288,7 @@ samples/client/petstore/objc + samples/client/petstore/java diff --git a/samples/client/petstore/java/src/main/java/io/swagger/client/ApiInvoker.java b/samples/client/petstore/java/src/main/java/io/swagger/client/ApiInvoker.java index 4380b011ba..323fd18a05 100644 --- a/samples/client/petstore/java/src/main/java/io/swagger/client/ApiInvoker.java +++ b/samples/client/petstore/java/src/main/java/io/swagger/client/ApiInvoker.java @@ -16,6 +16,7 @@ import com.sun.jersey.multipart.FormDataMultiPart; import javax.ws.rs.core.Response.Status.Family; import javax.ws.rs.core.MediaType; +import java.util.Collection; import java.util.Map; import java.util.HashMap; import java.util.List; @@ -83,11 +84,19 @@ public class ApiInvoker { return ""; } else if (param instanceof Date) { return formatDateTime((Date) param); + } else if (param instanceof Collection) { + StringBuilder b = new StringBuilder(); + for(Object o : (Collection)param) { + if(b.length() > 0) { + b.append(","); + } + b.append(String.valueOf(o)); + } + return b.toString(); } else { return String.valueOf(param); } } - public void enableDebug() { isDebug = true; } diff --git a/samples/client/petstore/java/src/main/java/io/swagger/client/model/ApiResponse.java b/samples/client/petstore/java/src/main/java/io/swagger/client/model/ApiResponse.java new file mode 100644 index 0000000000..cd9ff24975 --- /dev/null +++ b/samples/client/petstore/java/src/main/java/io/swagger/client/model/ApiResponse.java @@ -0,0 +1,64 @@ +package io.swagger.client.model; + + +import com.wordnik.swagger.annotations.*; +import com.fasterxml.jackson.annotation.JsonProperty; + + +@ApiModel(description = "") +public class ApiResponse { + + private Integer code = null; + private String type = null; + private String message = null; + + + /** + **/ + @ApiModelProperty(required = false, value = "") + @JsonProperty("code") + public Integer getCode() { + return code; + } + public void setCode(Integer code) { + this.code = code; + } + + + /** + **/ + @ApiModelProperty(required = false, value = "") + @JsonProperty("type") + public String getType() { + return type; + } + public void setType(String type) { + this.type = type; + } + + + /** + **/ + @ApiModelProperty(required = false, value = "") + @JsonProperty("message") + 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/java/src/test/java/io/swagger/petstore/test/PetApiTest.java b/samples/client/petstore/java/src/test/java/io/swagger/petstore/test/PetApiTest.java new file mode 100644 index 0000000000..36a29bce48 --- /dev/null +++ b/samples/client/petstore/java/src/test/java/io/swagger/petstore/test/PetApiTest.java @@ -0,0 +1,83 @@ +package io.swagger.petstore.test; + +import io.swagger.client.api.*; +import io.swagger.client.model.*; + +import java.util.Arrays; +import java.util.List; + +import static org.junit.Assert.*; +import org.junit.*; + +public class PetApiTest { + PetApi api = null; + + @Before + public void setup() { + api = new PetApi(); + } + + @Test + public void testCreateAndGetPet() throws Exception { + Pet pet = createRandomPet(); + api.addPet(pet); + + Pet fetched = api.getPetById(pet.getId()); + assertNotNull(fetched); + assertEquals(pet.getId(), fetched.getId()); + assertNotNull(fetched.getCategory()); + assertEquals(fetched.getCategory().getName(), pet.getCategory().getName()); + } + + @Test + public void testUpdatePet() throws Exception { + Pet pet = createRandomPet(); + pet.setName("programmer"); + + api.updatePet(pet); + + Pet fetched = api.getPetById(pet.getId()); + assertNotNull(fetched); + assertEquals(pet.getId(), fetched.getId()); + assertNotNull(fetched.getCategory()); + assertEquals(fetched.getCategory().getName(), pet.getCategory().getName()); + } + + @Test + public void testFindPetByStatus() throws Exception { + Pet pet = createRandomPet(); + pet.setName("programmer"); + pet.setStatus(Pet.StatusEnum.available); + + api.updatePet(pet); + + List pets = api.findPetsByStatus(Arrays.asList(new String[]{"available"})); + assertNotNull(pets); + + boolean found = false; + for(Pet fetched : pets) { + if(fetched.getId().equals(pet.getId())) { + found = true; + break; + } + } + + assertTrue(found); + } + + private Pet createRandomPet() { + Pet pet = new Pet(); + pet.setId(System.currentTimeMillis()); + pet.setName("gorilla"); + + Category category = new Category(); + category.setName("really-happy"); + + pet.setCategory(category); + pet.setStatus(Pet.StatusEnum.available); + List photos = Arrays.asList(new String[]{"http://foo.bar.com/1", "http://foo.bar.com/2"}); + pet.setPhotoUrls(photos); + + return pet; + } +} \ No newline at end of file diff --git a/samples/client/petstore/objc/PetstoreClient/PetstoreClientTests/PetApiTest.m b/samples/client/petstore/objc/PetstoreClient/PetstoreClientTests/PetApiTest.m index a4539c9255..f21e8fc516 100644 --- a/samples/client/petstore/objc/PetstoreClient/PetstoreClientTests/PetApiTest.m +++ b/samples/client/petstore/objc/PetstoreClient/PetstoreClientTests/PetApiTest.m @@ -6,8 +6,7 @@ - (void)setUp { [super setUp]; api = [[SWGPetApi alloc ]init]; -// [[SWGApiClient sharedClientFromPool]setLoggingEnabled:true]; - [SWGPetApi setBasePath:@"http://localhost:8002/api"]; + [SWGPetApi setBasePath:@"http://localhost:8080/api"]; } - (void)tearDown { diff --git a/samples/client/petstore/objc/pom.xml b/samples/client/petstore/objc/pom.xml index 0a6e65e1d4..1e144d0458 100644 --- a/samples/client/petstore/objc/pom.xml +++ b/samples/client/petstore/objc/pom.xml @@ -30,7 +30,7 @@ alpha 9099 - 8002 + 8080 @@ -41,8 +41,8 @@ deploy-war - - + + org.codehaus.mojo exec-maven-plugin diff --git a/samples/client/petstore/ruby/lib/store_api.rb b/samples/client/petstore/ruby/lib/store_api.rb deleted file mode 100644 index 4c553185ef..0000000000 --- a/samples/client/petstore/ruby/lib/store_api.rb +++ /dev/null @@ -1,197 +0,0 @@ -require "uri" - -class StoreApi - basePath = "http://petstore.swagger.io/v2" - # apiInvoker = APIInvoker - - def self.escapeString(string) - URI.encode(string.to_s) - end - - - def self.getInventory ( opts={}) - query_param_keys = [] - - - - # set default values and merge with input - options = { - - }.merge(opts) - - #resource path - path = "/store/inventory".sub('{format}','json') - - # pull querystring keys from options - queryopts = options.select do |key,value| - query_param_keys.include? key - end - - # header parameters, if any - headers = {} - - - - # http body (model) - post_body = nil - - - # form parameters - form_parameter_hash = {} - - - - response = Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make.body - - response.map {|response| map.new(response) } - - - - end - - - def self.placeOrder (body, opts={}) - query_param_keys = [] - - - - # set default values and merge with input - options = { - :'body' => body - - }.merge(opts) - - #resource path - path = "/store/order".sub('{format}','json') - - # pull querystring keys from options - queryopts = options.select do |key,value| - query_param_keys.include? key - end - - # header parameters, if any - headers = {} - - - - # http body (model) - post_body = nil - - if body != nil - if body.is_a?(Array) - array = Array.new - body.each do |item| - if item.respond_to?("to_body".to_sym) - array.push item.to_body - else - array.push item - end - end - post_body = array - - else - if body.respond_to?("to_body".to_sym) - post_body = body.to_body - else - post_body = body - end - end - end - - - # form parameters - form_parameter_hash = {} - - - - response = Swagger::Request.new(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make.body - Order.new(response) - - - - end - - - def self.getOrderById (order_id, opts={}) - query_param_keys = [] - - - - # set default values and merge with input - options = { - :'order_id' => order_id - - }.merge(opts) - - #resource path - path = "/store/order/{orderId}".sub('{format}','json').sub('{' + 'orderId' + '}', escapeString(order_id)) - - - # pull querystring keys from options - queryopts = options.select do |key,value| - query_param_keys.include? key - end - - # header parameters, if any - headers = {} - - - - # http body (model) - post_body = nil - - - # form parameters - form_parameter_hash = {} - - - - response = Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make.body - Order.new(response) - - - - end - - - def self.deleteOrder (order_id, opts={}) - query_param_keys = [] - - - - # set default values and merge with input - options = { - :'order_id' => order_id - - }.merge(opts) - - #resource path - path = "/store/order/{orderId}".sub('{format}','json').sub('{' + 'orderId' + '}', escapeString(order_id)) - - - # pull querystring keys from options - queryopts = options.select do |key,value| - query_param_keys.include? key - end - - # header parameters, if any - headers = {} - - - - # http body (model) - post_body = nil - - - # form parameters - form_parameter_hash = {} - - - - - Swagger::Request.new(:DELETE, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make - - - end - -end From ddb1d6e0d35475256f1b425a506b179793d96df1 Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Thu, 26 Mar 2015 23:09:29 -0700 Subject: [PATCH 011/192] removed 404 handling --- .../src/main/resources/Java/api.mustache | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/Java/api.mustache b/modules/swagger-codegen/src/main/resources/Java/api.mustache index ad26268d71..20829f8297 100644 --- a/modules/swagger-codegen/src/main/resources/Java/api.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/api.mustache @@ -11,6 +11,7 @@ import java.util.*; {{/imports}} import com.sun.jersey.multipart.FormDataMultiPart; +import com.sun.jersey.multipart.file.FileDataBodyPart; import javax.ws.rs.core.MediaType; @@ -77,7 +78,8 @@ public class {{classname}} { mp.field("{{baseName}}", ApiInvoker.parameterToString({{paramName}}), MediaType.MULTIPART_FORM_DATA_TYPE); {{/notFile}}{{#isFile}} hasFields = true; - mp.field("{{baseName}}", {{paramName}}, MediaType.MULTIPART_FORM_DATA_TYPE); + mp.field("{{baseName}}", file.getName()); + mp.bodyPart(new FileDataBodyPart("{{baseName}}", {{paramName}}, MediaType.MULTIPART_FORM_DATA_TYPE)); {{/isFile}}{{/formParams}} if(hasFields) postBody = mp; @@ -96,12 +98,7 @@ public class {{classname}} { return {{#returnType}}null{{/returnType}}; } } catch (ApiException ex) { - if(ex.getCode() == 404) { - return {{#returnType}} null{{/returnType}}; - } - else { - throw ex; - } + throw ex; } } {{/operation}} From 287bb7d9360013978548f72ff286d418546d00ec Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Thu, 26 Mar 2015 23:09:47 -0700 Subject: [PATCH 012/192] fixed builder, error msg --- .../main/resources/Java/apiInvoker.mustache | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/Java/apiInvoker.mustache b/modules/swagger-codegen/src/main/resources/Java/apiInvoker.mustache index d9d772eaaa..eff710a044 100644 --- a/modules/swagger-codegen/src/main/resources/Java/apiInvoker.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/apiInvoker.mustache @@ -226,7 +226,7 @@ public class ApiInvoker { } else if ("DELETE".equals(method)) { if(body == null) - response = builder.delete(ClientResponse.class, serialize(body)); + response = builder.delete(ClientResponse.class); else response = builder.type(contentType).delete(ClientResponse.class, serialize(body)); } @@ -237,12 +237,26 @@ public class ApiInvoker { return null; } else if(response.getClientResponseStatus().getFamily() == Family.SUCCESSFUL) { - return (String) response.getEntity(String.class); + if(response.hasEntity()) { + return (String) response.getEntity(String.class); + } + else { + return ""; + } } else { + String message = "error"; + if(response.hasEntity()) { + try{ + message = String.valueOf(response.getEntity(String.class)); + } + catch (RuntimeException e) { + // e.printStackTrace(); + } + } throw new ApiException( response.getClientResponseStatus().getStatusCode(), - response.getEntity(String.class)); + message); } } From 442be8624c513fd3b3b7337bd0f1f9b9105d5a7f Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Thu, 26 Mar 2015 23:10:10 -0700 Subject: [PATCH 013/192] rebuilt client, added tests --- .../java/io/swagger/client/ApiInvoker.java | 20 ++++- .../java/io/swagger/client/api/PetApi.java | 60 +++---------- .../java/io/swagger/client/api/StoreApi.java | 29 ++----- .../java/io/swagger/client/api/UserApi.java | 57 ++----------- .../io/swagger/petstore/test/PetApiTest.java | 78 ++++++++++++++++- .../swagger/petstore/test/StoreApiTest.java | 68 +++++++++++++++ .../io/swagger/petstore/test/UserApiTest.java | 84 +++++++++++++++++++ 7 files changed, 269 insertions(+), 127 deletions(-) create mode 100644 samples/client/petstore/java/src/test/java/io/swagger/petstore/test/StoreApiTest.java create mode 100644 samples/client/petstore/java/src/test/java/io/swagger/petstore/test/UserApiTest.java diff --git a/samples/client/petstore/java/src/main/java/io/swagger/client/ApiInvoker.java b/samples/client/petstore/java/src/main/java/io/swagger/client/ApiInvoker.java index 323fd18a05..f3b3466dbd 100644 --- a/samples/client/petstore/java/src/main/java/io/swagger/client/ApiInvoker.java +++ b/samples/client/petstore/java/src/main/java/io/swagger/client/ApiInvoker.java @@ -226,7 +226,7 @@ public class ApiInvoker { } else if ("DELETE".equals(method)) { if(body == null) - response = builder.delete(ClientResponse.class, serialize(body)); + response = builder.delete(ClientResponse.class); else response = builder.type(contentType).delete(ClientResponse.class, serialize(body)); } @@ -237,12 +237,26 @@ public class ApiInvoker { return null; } else if(response.getClientResponseStatus().getFamily() == Family.SUCCESSFUL) { - return (String) response.getEntity(String.class); + if(response.hasEntity()) { + return (String) response.getEntity(String.class); + } + else { + return ""; + } } else { + String message = "error"; + if(response.hasEntity()) { + try{ + message = String.valueOf(response.getEntity(String.class)); + } + catch (RuntimeException e) { + // e.printStackTrace(); + } + } throw new ApiException( response.getClientResponseStatus().getStatusCode(), - response.getEntity(String.class)); + message); } } diff --git a/samples/client/petstore/java/src/main/java/io/swagger/client/api/PetApi.java b/samples/client/petstore/java/src/main/java/io/swagger/client/api/PetApi.java index 21f5beea53..cf6cdc3f0c 100644 --- a/samples/client/petstore/java/src/main/java/io/swagger/client/api/PetApi.java +++ b/samples/client/petstore/java/src/main/java/io/swagger/client/api/PetApi.java @@ -11,6 +11,7 @@ import io.swagger.client.model.Pet; import java.io.File; import com.sun.jersey.multipart.FormDataMultiPart; +import com.sun.jersey.multipart.file.FileDataBodyPart; import javax.ws.rs.core.MediaType; @@ -76,12 +77,7 @@ public class PetApi { return ; } } catch (ApiException ex) { - if(ex.getCode() == 404) { - return ; - } - else { - throw ex; - } + throw ex; } } @@ -126,12 +122,7 @@ public class PetApi { return ; } } catch (ApiException ex) { - if(ex.getCode() == 404) { - return ; - } - else { - throw ex; - } + throw ex; } } @@ -178,12 +169,7 @@ public class PetApi { return null; } } catch (ApiException ex) { - if(ex.getCode() == 404) { - return null; - } - else { - throw ex; - } + throw ex; } } @@ -230,12 +216,7 @@ public class PetApi { return null; } } catch (ApiException ex) { - if(ex.getCode() == 404) { - return null; - } - else { - throw ex; - } + throw ex; } } @@ -281,12 +262,7 @@ public class PetApi { return null; } } catch (ApiException ex) { - if(ex.getCode() == 404) { - return null; - } - else { - throw ex; - } + throw ex; } } @@ -340,12 +316,7 @@ public class PetApi { return ; } } catch (ApiException ex) { - if(ex.getCode() == 404) { - return ; - } - else { - throw ex; - } + throw ex; } } @@ -392,12 +363,7 @@ public class PetApi { return ; } } catch (ApiException ex) { - if(ex.getCode() == 404) { - return ; - } - else { - throw ex; - } + throw ex; } } @@ -431,7 +397,8 @@ public class PetApi { mp.field("additionalMetadata", ApiInvoker.parameterToString(additionalMetadata), MediaType.MULTIPART_FORM_DATA_TYPE); hasFields = true; - mp.field("file", file, MediaType.MULTIPART_FORM_DATA_TYPE); + mp.field("file", file.getName()); + mp.bodyPart(new FileDataBodyPart("file", file, MediaType.MULTIPART_FORM_DATA_TYPE)); if(hasFields) postBody = mp; @@ -451,12 +418,7 @@ public class PetApi { return ; } } catch (ApiException ex) { - if(ex.getCode() == 404) { - return ; - } - else { - throw ex; - } + throw ex; } } diff --git a/samples/client/petstore/java/src/main/java/io/swagger/client/api/StoreApi.java b/samples/client/petstore/java/src/main/java/io/swagger/client/api/StoreApi.java index 1da7519154..318c55df21 100644 --- a/samples/client/petstore/java/src/main/java/io/swagger/client/api/StoreApi.java +++ b/samples/client/petstore/java/src/main/java/io/swagger/client/api/StoreApi.java @@ -11,6 +11,7 @@ import java.util.Map; import io.swagger.client.model.Order; import com.sun.jersey.multipart.FormDataMultiPart; +import com.sun.jersey.multipart.file.FileDataBodyPart; import javax.ws.rs.core.MediaType; @@ -76,12 +77,7 @@ public class StoreApi { return null; } } catch (ApiException ex) { - if(ex.getCode() == 404) { - return null; - } - else { - throw ex; - } + throw ex; } } @@ -126,12 +122,7 @@ public class StoreApi { return null; } } catch (ApiException ex) { - if(ex.getCode() == 404) { - return null; - } - else { - throw ex; - } + throw ex; } } @@ -177,12 +168,7 @@ public class StoreApi { return null; } } catch (ApiException ex) { - if(ex.getCode() == 404) { - return null; - } - else { - throw ex; - } + throw ex; } } @@ -228,12 +214,7 @@ public class StoreApi { return ; } } catch (ApiException ex) { - if(ex.getCode() == 404) { - return ; - } - else { - throw ex; - } + throw ex; } } diff --git a/samples/client/petstore/java/src/main/java/io/swagger/client/api/UserApi.java b/samples/client/petstore/java/src/main/java/io/swagger/client/api/UserApi.java index 7b8b2cad83..e50c034ab1 100644 --- a/samples/client/petstore/java/src/main/java/io/swagger/client/api/UserApi.java +++ b/samples/client/petstore/java/src/main/java/io/swagger/client/api/UserApi.java @@ -11,6 +11,7 @@ import io.swagger.client.model.User; import java.util.*; import com.sun.jersey.multipart.FormDataMultiPart; +import com.sun.jersey.multipart.file.FileDataBodyPart; import javax.ws.rs.core.MediaType; @@ -76,12 +77,7 @@ public class UserApi { return ; } } catch (ApiException ex) { - if(ex.getCode() == 404) { - return ; - } - else { - throw ex; - } + throw ex; } } @@ -126,12 +122,7 @@ public class UserApi { return ; } } catch (ApiException ex) { - if(ex.getCode() == 404) { - return ; - } - else { - throw ex; - } + throw ex; } } @@ -176,12 +167,7 @@ public class UserApi { return ; } } catch (ApiException ex) { - if(ex.getCode() == 404) { - return ; - } - else { - throw ex; - } + throw ex; } } @@ -230,12 +216,7 @@ public class UserApi { return null; } } catch (ApiException ex) { - if(ex.getCode() == 404) { - return null; - } - else { - throw ex; - } + throw ex; } } @@ -280,12 +261,7 @@ public class UserApi { return ; } } catch (ApiException ex) { - if(ex.getCode() == 404) { - return ; - } - else { - throw ex; - } + throw ex; } } @@ -331,12 +307,7 @@ public class UserApi { return null; } } catch (ApiException ex) { - if(ex.getCode() == 404) { - return null; - } - else { - throw ex; - } + throw ex; } } @@ -382,12 +353,7 @@ public class UserApi { return ; } } catch (ApiException ex) { - if(ex.getCode() == 404) { - return ; - } - else { - throw ex; - } + throw ex; } } @@ -433,12 +399,7 @@ public class UserApi { return ; } } catch (ApiException ex) { - if(ex.getCode() == 404) { - return ; - } - else { - throw ex; - } + throw ex; } } diff --git a/samples/client/petstore/java/src/test/java/io/swagger/petstore/test/PetApiTest.java b/samples/client/petstore/java/src/test/java/io/swagger/petstore/test/PetApiTest.java index 36a29bce48..97f3b5f800 100644 --- a/samples/client/petstore/java/src/test/java/io/swagger/petstore/test/PetApiTest.java +++ b/samples/client/petstore/java/src/test/java/io/swagger/petstore/test/PetApiTest.java @@ -1,10 +1,11 @@ package io.swagger.petstore.test; +import io.swagger.client.ApiException; import io.swagger.client.api.*; import io.swagger.client.model.*; -import java.util.Arrays; -import java.util.List; +import java.util.*; +import java.io.*; import static org.junit.Assert.*; import org.junit.*; @@ -44,7 +45,7 @@ public class PetApiTest { } @Test - public void testFindPetByStatus() throws Exception { + public void testFindPetsByStatus() throws Exception { Pet pet = createRandomPet(); pet.setName("programmer"); pet.setStatus(Pet.StatusEnum.available); @@ -65,6 +66,77 @@ public class PetApiTest { assertTrue(found); } + @Test + public void testFindPetsByTags() throws Exception { + Pet pet = createRandomPet(); + pet.setName("monster"); + pet.setStatus(Pet.StatusEnum.available); + + List tags = new ArrayList(); + Tag tag1 = new Tag(); + tag1.setName("friendly"); + tags.add(tag1); + pet.setTags(tags); + + api.updatePet(pet); + + List pets = api.findPetsByTags(Arrays.asList(new String[]{"friendly"})); + assertNotNull(pets); + + boolean found = false; + for(Pet fetched : pets) { + if(fetched.getId().equals(pet.getId())) { + found = true; + break; + } + } + assertTrue(found); + } + + @Test + public void testUpdatePetWithForm() throws Exception { + Pet pet = createRandomPet(); + pet.setName("frank"); + api.addPet(pet); + + Pet fetched = api.getPetById(pet.getId()); + + api.updatePetWithForm(String.valueOf(fetched.getId()), "furt", null); + Pet updated = api.getPetById(fetched.getId()); + + assertEquals(updated.getName(), fetched.getName()); + } + + @Test + public void testDeletePet() throws Exception { + Pet pet = createRandomPet(); + api.addPet(pet); + + Pet fetched = api.getPetById(pet.getId()); + api.deletePet(null, fetched.getId()); + + try { + fetched = api.getPetById(fetched.getId()); + fail("expected an error"); + } + catch (ApiException e) { + assertEquals(404, e.getCode()); + } + } + + @Test + public void testUploadFile() throws Exception { + Pet pet = createRandomPet(); + api.addPet(pet); + + File file = new File("hello.txt"); + BufferedWriter writer = new BufferedWriter(new FileWriter(file)); + writer.write("Hello world!"); + writer.close(); + + api.uploadFile(pet.getId(), "a test file", new File(file.getAbsolutePath())); + } + private Pet createRandomPet() { Pet pet = new Pet(); pet.setId(System.currentTimeMillis()); diff --git a/samples/client/petstore/java/src/test/java/io/swagger/petstore/test/StoreApiTest.java b/samples/client/petstore/java/src/test/java/io/swagger/petstore/test/StoreApiTest.java new file mode 100644 index 0000000000..25a52009b9 --- /dev/null +++ b/samples/client/petstore/java/src/test/java/io/swagger/petstore/test/StoreApiTest.java @@ -0,0 +1,68 @@ +package io.swagger.petstore.test; + +import io.swagger.client.ApiException; +import io.swagger.client.api.*; +import io.swagger.client.model.*; + +import java.util.*; +import java.io.*; + +import static org.junit.Assert.*; +import org.junit.*; + +public class StoreApiTest { + StoreApi api = null; + + @Before + public void setup() { + api = new StoreApi(); + } + + @Test + public void testGetInventory() throws Exception { + Map inventory = api.getInventory(); + assertTrue(inventory.keySet().size() > 0); + } + + @Test + public void testPlaceOrder() throws Exception { + Order order = createOrder(); + api.placeOrder(order); + + Order fetched = api.getOrderById(String.valueOf(order.getId())); + assertEquals(order.getId(), fetched.getId()); + assertEquals(order.getPetId(), fetched.getPetId()); + assertEquals(order.getQuantity(), fetched.getQuantity()); + } + + @Test + public void testDeleteOrder() throws Exception { + Order order = createOrder(); + api.placeOrder(order); + + Order fetched = api.getOrderById(String.valueOf(order.getId())); + assertEquals(fetched.getId(), order.getId()); + + api.deleteOrder(String.valueOf(order.getId())); + + try { + api.getOrderById(String.valueOf(order.getId())); + // fail("expected an error"); + } + catch (ApiException e) { + // ok + } + } + + private Order createOrder() { + Order order = new Order(); + order.setId(new Long(System.currentTimeMillis())); + order.setPetId(new Long(200)); + order.setQuantity(new Integer(13)); + order.setShipDate(new java.util.Date()); + order.setStatus(Order.StatusEnum.placed); + order.setComplete(true); + + return order; + } +} \ No newline at end of file diff --git a/samples/client/petstore/java/src/test/java/io/swagger/petstore/test/UserApiTest.java b/samples/client/petstore/java/src/test/java/io/swagger/petstore/test/UserApiTest.java new file mode 100644 index 0000000000..9d683faab7 --- /dev/null +++ b/samples/client/petstore/java/src/test/java/io/swagger/petstore/test/UserApiTest.java @@ -0,0 +1,84 @@ +package io.swagger.petstore.test; + +import io.swagger.client.ApiException; +import io.swagger.client.api.*; +import io.swagger.client.model.*; + +import java.util.*; +import java.io.*; + +import static org.junit.Assert.*; +import org.junit.*; + +public class UserApiTest { + UserApi api = null; + + @Before + public void setup() { + api = new UserApi(); + } + + @Test + public void testCreateUser() throws Exception { + User user = createUser(); + + api.createUser(user); + + User fetched = api.getUserByName(user.getUsername()); + assertEquals(user.getId(), fetched.getId()); + } + + @Test + public void testCreateUsersWithArray() throws Exception { + User user1 = createUser(); + user1.setUsername("abc123"); + User user2 = createUser(); + user2.setUsername("123abc"); + + api.createUsersWithArrayInput(Arrays.asList(new User[]{user1, user2})); + + User fetched = api.getUserByName(user1.getUsername()); + assertEquals(user1.getId(), fetched.getId()); + } + + @Test + public void testCreateUsersWithList() throws Exception { + User user1 = createUser(); + user1.setUsername("abc123"); + User user2 = createUser(); + user2.setUsername("123abc"); + + api.createUsersWithListInput(Arrays.asList(new User[]{user1, user2})); + + User fetched = api.getUserByName(user1.getUsername()); + assertEquals(user1.getId(), fetched.getId()); + } + + @Test + public void testLoginUser() throws Exception { + User user = createUser(); + api.createUser(user); + + String token = api.loginUser(user.getUsername(), user.getPassword()); + assertTrue(token.startsWith("logged in user session:")); + } + + @Test + public void logoutUser() throws Exception { + api.logoutUser(); + } + + private User createUser() { + User user = new User(); + user.setId(System.currentTimeMillis()); + user.setUsername("fred"); + user.setFirstName("Fred"); + user.setLastName("Meyer"); + user.setEmail("fred@fredmeyer.com"); + user.setPassword("xxXXxx"); + user.setPhone("408-867-5309"); + user.setUserStatus(123); + + return user; + } +} \ No newline at end of file From 5d6d563a8eb95dd76982a3a6725475c72254248a Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Thu, 26 Mar 2015 23:17:17 -0700 Subject: [PATCH 014/192] updated versions --- .../swagger-codegen/src/main/resources/Java/pom.mustache | 7 +++---- pom.xml | 2 +- samples/client/petstore/java/pom.xml | 7 +++---- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/Java/pom.mustache b/modules/swagger-codegen/src/main/resources/Java/pom.mustache index 73d62103e2..9f4c858a8a 100644 --- a/modules/swagger-codegen/src/main/resources/Java/pom.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/pom.mustache @@ -157,11 +157,10 @@ - 1.5.0-M1 - 1.7 - 2.1.4 + 1.5.3-M1 + 1.18 + 2.4.2 2.3 - 4.8.1 1.0.0 4.8.1 diff --git a/pom.xml b/pom.xml index 6e781ee7ed..8848c072c0 100644 --- a/pom.xml +++ b/pom.xml @@ -364,7 +364,7 @@ 1.0.3 2.11.1 2.3.4 - 1.5.3-M1-SNAPSHOT + 1.5.3-M1 2.1.4 2.3 1.2 diff --git a/samples/client/petstore/java/pom.xml b/samples/client/petstore/java/pom.xml index 10b1a29476..efdc5f59dd 100644 --- a/samples/client/petstore/java/pom.xml +++ b/samples/client/petstore/java/pom.xml @@ -157,11 +157,10 @@ - 1.5.0-M1 - 1.7 - 2.1.4 + 1.5.3-M1 + 1.18 + 2.4.2 2.3 - 4.8.1 1.0.0 4.8.1 From 1c547e959880c2ca1b2273cbc6663ea7e61c3f58 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Fri, 27 Mar 2015 22:40:59 +0800 Subject: [PATCH 015/192] update php documentation --- .../src/main/resources/php/api.mustache | 7 +- samples/client/petstore/php/PetApi.php | 66 ++++++++----------- samples/client/petstore/php/StoreApi.php | 26 ++++---- samples/client/petstore/php/UserApi.php | 58 +++++++--------- 4 files changed, 68 insertions(+), 89 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/php/api.mustache b/modules/swagger-codegen/src/main/resources/php/api.mustache index bdf66defca..375ff8a4f4 100644 --- a/modules/swagger-codegen/src/main/resources/php/api.mustache +++ b/modules/swagger-codegen/src/main/resources/php/api.mustache @@ -31,11 +31,10 @@ class {{classname}} { * {{{nickname}}} * * {{{summary}}} - {{#allParams}}* {{paramName}}, {{dataType}}: {{description}} {{^optional}}(required){{/optional}}{{#optional}}(optional){{/optional}} - * {{/allParams}} - * @return {{{returnType}}} + * +{{#allParams}} * @param {{dataType}} ${{paramName}} {{description}} {{^optional}}(required){{/optional}}{{#optional}}(optional){{/optional}} +{{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} */ - public function {{nickname}}({{#allParams}}${{paramName}}{{#optional}}=null{{/optional}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) { // parse inputs diff --git a/samples/client/petstore/php/PetApi.php b/samples/client/petstore/php/PetApi.php index 49f623b4da..25c3ea24bd 100644 --- a/samples/client/petstore/php/PetApi.php +++ b/samples/client/petstore/php/PetApi.php @@ -30,11 +30,10 @@ class PetApi { * updatePet * * Update an existing pet - * body, Pet: Pet object that needs to be added to the store (required) - * - * @return + * + * @param Pet $body Pet object that needs to be added to the store (required) + * @return void */ - public function updatePet($body) { // parse inputs @@ -76,11 +75,10 @@ class PetApi { * addPet * * Add a new pet to the store - * body, Pet: Pet object that needs to be added to the store (required) - * - * @return + * + * @param Pet $body Pet object that needs to be added to the store (required) + * @return void */ - public function addPet($body) { // parse inputs @@ -122,11 +120,10 @@ class PetApi { * findPetsByStatus * * Finds Pets by status - * status, array[string]: Status values that need to be considered for filter (required) - * - * @return array[Pet] + * + * @param array[string] $status Status values that need to be considered for filter (required) + * @return array[Pet] */ - public function findPetsByStatus($status) { // parse inputs @@ -173,11 +170,10 @@ class PetApi { * findPetsByTags * * Finds Pets by tags - * tags, array[string]: Tags to filter by (required) - * - * @return array[Pet] + * + * @param array[string] $tags Tags to filter by (required) + * @return array[Pet] */ - public function findPetsByTags($tags) { // parse inputs @@ -224,11 +220,10 @@ class PetApi { * getPetById * * Find pet by ID - * pet_id, int: ID of pet that needs to be fetched (required) - * - * @return Pet + * + * @param int $pet_id ID of pet that needs to be fetched (required) + * @return Pet */ - public function getPetById($pet_id) { // parse inputs @@ -276,13 +271,12 @@ class PetApi { * updatePetWithForm * * Updates a pet in the store with form data - * pet_id, string: ID of pet that needs to be updated (required) - * * name, string: Updated name of the pet (required) - * * status, string: Updated status of the pet (required) - * - * @return + * + * @param string $pet_id ID of pet that needs to be updated (required) + * @param string $name Updated name of the pet (required) + * @param string $status Updated status of the pet (required) + * @return void */ - public function updatePetWithForm($pet_id, $name, $status) { // parse inputs @@ -330,12 +324,11 @@ class PetApi { * deletePet * * Deletes a pet - * api_key, string: (required) - * * pet_id, int: Pet id to delete (required) - * - * @return + * + * @param string $api_key (required) + * @param int $pet_id Pet id to delete (required) + * @return void */ - public function deletePet($api_key, $pet_id) { // parse inputs @@ -380,13 +373,12 @@ class PetApi { * uploadFile * * uploads an image - * pet_id, int: ID of pet to update (required) - * * additional_metadata, string: Additional data to pass to server (required) - * * file, file: file to upload (required) - * - * @return + * + * @param int $pet_id ID of pet to update (required) + * @param string $additional_metadata Additional data to pass to server (required) + * @param file $file file to upload (required) + * @return void */ - public function uploadFile($pet_id, $additional_metadata, $file) { // parse inputs diff --git a/samples/client/petstore/php/StoreApi.php b/samples/client/petstore/php/StoreApi.php index 12b4628650..fbd2fc0afe 100644 --- a/samples/client/petstore/php/StoreApi.php +++ b/samples/client/petstore/php/StoreApi.php @@ -30,10 +30,9 @@ class StoreApi { * getInventory * * Returns pet inventories by status - - * @return map[string,int] + * + * @return map[string,int] */ - public function getInventory() { // parse inputs @@ -77,11 +76,10 @@ class StoreApi { * placeOrder * * Place an order for a pet - * body, Order: order placed for purchasing the pet (required) - * - * @return Order + * + * @param Order $body order placed for purchasing the pet (required) + * @return Order */ - public function placeOrder($body) { // parse inputs @@ -129,11 +127,10 @@ class StoreApi { * getOrderById * * Find purchase order by ID - * order_id, string: ID of pet that needs to be fetched (required) - * - * @return Order + * + * @param string $order_id ID of pet that needs to be fetched (required) + * @return Order */ - public function getOrderById($order_id) { // parse inputs @@ -181,11 +178,10 @@ class StoreApi { * deleteOrder * * Delete purchase order by ID - * order_id, string: ID of the order that needs to be deleted (required) - * - * @return + * + * @param string $order_id ID of the order that needs to be deleted (required) + * @return void */ - public function deleteOrder($order_id) { // parse inputs diff --git a/samples/client/petstore/php/UserApi.php b/samples/client/petstore/php/UserApi.php index cd5d197394..9e0b5280e4 100644 --- a/samples/client/petstore/php/UserApi.php +++ b/samples/client/petstore/php/UserApi.php @@ -30,11 +30,10 @@ class UserApi { * createUser * * Create user - * body, User: Created user object (required) - * - * @return + * + * @param User $body Created user object (required) + * @return void */ - public function createUser($body) { // parse inputs @@ -76,11 +75,10 @@ class UserApi { * createUsersWithArrayInput * * Creates list of users with given input array - * body, array[User]: List of user object (required) - * - * @return + * + * @param array[User] $body List of user object (required) + * @return void */ - public function createUsersWithArrayInput($body) { // parse inputs @@ -122,11 +120,10 @@ class UserApi { * createUsersWithListInput * * Creates list of users with given input array - * body, array[User]: List of user object (required) - * - * @return + * + * @param array[User] $body List of user object (required) + * @return void */ - public function createUsersWithListInput($body) { // parse inputs @@ -168,12 +165,11 @@ class UserApi { * loginUser * * Logs user into the system - * username, string: The user name for login (required) - * * password, string: The password for login in clear text (required) - * - * @return string + * + * @param string $username The user name for login (required) + * @param string $password The password for login in clear text (required) + * @return string */ - public function loginUser($username, $password) { // parse inputs @@ -223,10 +219,9 @@ class UserApi { * logoutUser * * Logs out current logged in user session - - * @return + * + * @return void */ - public function logoutUser() { // parse inputs @@ -264,11 +259,10 @@ class UserApi { * getUserByName * * Get user by user name - * username, string: The name that needs to be fetched. Use user1 for testing. (required) - * - * @return User + * + * @param string $username The name that needs to be fetched. Use user1 for testing. (required) + * @return User */ - public function getUserByName($username) { // parse inputs @@ -316,12 +310,11 @@ class UserApi { * updateUser * * Updated user - * username, string: name that need to be deleted (required) - * * body, User: Updated user object (required) - * - * @return + * + * @param string $username name that need to be deleted (required) + * @param User $body Updated user object (required) + * @return void */ - public function updateUser($username, $body) { // parse inputs @@ -367,11 +360,10 @@ class UserApi { * deleteUser * * Delete user - * username, string: The name that needs to be deleted (required) - * - * @return + * + * @param string $username The name that needs to be deleted (required) + * @return void */ - public function deleteUser($username) { // parse inputs From 6ab51bcb4e52eae61634d40902c1efc6494c0b68 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Fri, 27 Mar 2015 23:11:13 +0800 Subject: [PATCH 016/192] remove tab with 2 spaces in php api template --- .../src/main/resources/php/api.mustache | 44 ++-- samples/client/petstore/php/PetApi.php | 234 +++++++++--------- samples/client/petstore/php/StoreApi.php | 114 ++++----- samples/client/petstore/php/UserApi.php | 224 ++++++++--------- 4 files changed, 308 insertions(+), 308 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/php/api.mustache b/modules/swagger-codegen/src/main/resources/php/api.mustache index 375ff8a4f4..74c32a891f 100644 --- a/modules/swagger-codegen/src/main/resources/php/api.mustache +++ b/modules/swagger-codegen/src/main/resources/php/api.mustache @@ -22,25 +22,25 @@ {{#operations}} class {{classname}} { - function __construct($apiClient) { - $this->apiClient = $apiClient; - } + function __construct($apiClient) { + $this->apiClient = $apiClient; + } {{#operation}} - /** - * {{{nickname}}} + /** + * {{{nickname}}} * - * {{{summary}}} + * {{{summary}}} * {{#allParams}} * @param {{dataType}} ${{paramName}} {{description}} {{^optional}}(required){{/optional}}{{#optional}}(optional){{/optional}} {{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} - */ + */ public function {{nickname}}({{#allParams}}${{paramName}}{{#optional}}=null{{/optional}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) { - // parse inputs - $resourcePath = "{{path}}"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "{{httpMethod}}"; + // parse inputs + $resourcePath = "{{path}}"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "{{httpMethod}}"; $queryParams = array(); $headerParams = array(); $formParams = array(); @@ -49,17 +49,17 @@ class {{classname}} { {{#queryParams}}// query params if(${{paramName}} !== null) { - $queryParams['{{baseName}}'] = $this->apiClient->toQueryValue(${{paramName}}); - }{{/queryParams}} + $queryParams['{{baseName}}'] = $this->apiClient->toQueryValue(${{paramName}}); + }{{/queryParams}} {{#headerParams}}// header params if(${{paramName}} !== null) { - $headerParams['{{baseName}}'] = $this->apiClient->toHeaderValue(${{paramName}}); - }{{/headerParams}} + $headerParams['{{baseName}}'] = $this->apiClient->toHeaderValue(${{paramName}}); + }{{/headerParams}} {{#pathParams}}// path params if(${{paramName}} !== null) { - $resourcePath = str_replace("{" . "{{baseName}}" . "}", - $this->apiClient->toPathValue(${{paramName}}), $resourcePath); - }{{/pathParams}} + $resourcePath = str_replace("{" . "{{baseName}}" . "}", + $this->apiClient->toPathValue(${{paramName}}), $resourcePath); + }{{/pathParams}} {{#formParams}}// form params if (${{paramName}} !== null) { $formParams['{{baseName}}'] = {{#isFile}}'@' . {{/isFile}}$this->apiClient->toFormValue(${{paramName}}); @@ -77,10 +77,10 @@ class {{classname}} { $body = http_build_query($body); } - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $body, - $headerParams); + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $body, + $headerParams); {{#returnType}}if(! $response) { return null; diff --git a/samples/client/petstore/php/PetApi.php b/samples/client/petstore/php/PetApi.php index 25c3ea24bd..87850e3128 100644 --- a/samples/client/petstore/php/PetApi.php +++ b/samples/client/petstore/php/PetApi.php @@ -21,25 +21,25 @@ */ class PetApi { - function __construct($apiClient) { - $this->apiClient = $apiClient; - } + function __construct($apiClient) { + $this->apiClient = $apiClient; + } - /** - * updatePet + /** + * updatePet * - * Update an existing pet + * Update an existing pet * * @param Pet $body Pet object that needs to be added to the store (required) * @return void - */ + */ public function updatePet($body) { - // parse inputs - $resourcePath = "/pet"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "PUT"; + // parse inputs + $resourcePath = "/pet"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "PUT"; $queryParams = array(); $headerParams = array(); $formParams = array(); @@ -63,28 +63,28 @@ class PetApi { $body = http_build_query($body); } - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $body, - $headerParams); + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $body, + $headerParams); } - /** - * addPet + /** + * addPet * - * Add a new pet to the store + * Add a new pet to the store * * @param Pet $body Pet object that needs to be added to the store (required) * @return void - */ + */ public function addPet($body) { - // parse inputs - $resourcePath = "/pet"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "POST"; + // parse inputs + $resourcePath = "/pet"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "POST"; $queryParams = array(); $headerParams = array(); $formParams = array(); @@ -108,28 +108,28 @@ class PetApi { $body = http_build_query($body); } - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $body, - $headerParams); + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $body, + $headerParams); } - /** - * findPetsByStatus + /** + * findPetsByStatus * - * Finds Pets by status + * Finds Pets by status * * @param array[string] $status Status values that need to be considered for filter (required) * @return array[Pet] - */ + */ public function findPetsByStatus($status) { - // parse inputs - $resourcePath = "/pet/findByStatus"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "GET"; + // parse inputs + $resourcePath = "/pet/findByStatus"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "GET"; $queryParams = array(); $headerParams = array(); $formParams = array(); @@ -138,8 +138,8 @@ class PetApi { // query params if($status !== null) { - $queryParams['status'] = $this->apiClient->toQueryValue($status); - } + $queryParams['status'] = $this->apiClient->toQueryValue($status); + } @@ -152,10 +152,10 @@ class PetApi { $body = http_build_query($body); } - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $body, - $headerParams); + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $body, + $headerParams); if(! $response) { return null; @@ -166,20 +166,20 @@ class PetApi { return $responseObject; } - /** - * findPetsByTags + /** + * findPetsByTags * - * Finds Pets by tags + * Finds Pets by tags * * @param array[string] $tags Tags to filter by (required) * @return array[Pet] - */ + */ public function findPetsByTags($tags) { - // parse inputs - $resourcePath = "/pet/findByTags"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "GET"; + // parse inputs + $resourcePath = "/pet/findByTags"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "GET"; $queryParams = array(); $headerParams = array(); $formParams = array(); @@ -188,8 +188,8 @@ class PetApi { // query params if($tags !== null) { - $queryParams['tags'] = $this->apiClient->toQueryValue($tags); - } + $queryParams['tags'] = $this->apiClient->toQueryValue($tags); + } @@ -202,10 +202,10 @@ class PetApi { $body = http_build_query($body); } - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $body, - $headerParams); + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $body, + $headerParams); if(! $response) { return null; @@ -216,20 +216,20 @@ class PetApi { return $responseObject; } - /** - * getPetById + /** + * getPetById * - * Find pet by ID + * Find pet by ID * * @param int $pet_id ID of pet that needs to be fetched (required) * @return Pet - */ + */ public function getPetById($pet_id) { - // parse inputs - $resourcePath = "/pet/{petId}"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "GET"; + // parse inputs + $resourcePath = "/pet/{petId}"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "GET"; $queryParams = array(); $headerParams = array(); $formParams = array(); @@ -240,9 +240,9 @@ class PetApi { // path params if($pet_id !== null) { - $resourcePath = str_replace("{" . "petId" . "}", - $this->apiClient->toPathValue($pet_id), $resourcePath); - } + $resourcePath = str_replace("{" . "petId" . "}", + $this->apiClient->toPathValue($pet_id), $resourcePath); + } @@ -253,10 +253,10 @@ class PetApi { $body = http_build_query($body); } - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $body, - $headerParams); + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $body, + $headerParams); if(! $response) { return null; @@ -267,22 +267,22 @@ class PetApi { return $responseObject; } - /** - * updatePetWithForm + /** + * updatePetWithForm * - * Updates a pet in the store with form data + * Updates a pet in the store with form data * * @param string $pet_id ID of pet that needs to be updated (required) * @param string $name Updated name of the pet (required) * @param string $status Updated status of the pet (required) * @return void - */ + */ public function updatePetWithForm($pet_id, $name, $status) { - // parse inputs - $resourcePath = "/pet/{petId}"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "POST"; + // parse inputs + $resourcePath = "/pet/{petId}"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "POST"; $queryParams = array(); $headerParams = array(); $formParams = array(); @@ -293,9 +293,9 @@ class PetApi { // path params if($pet_id !== null) { - $resourcePath = str_replace("{" . "petId" . "}", - $this->apiClient->toPathValue($pet_id), $resourcePath); - } + $resourcePath = str_replace("{" . "petId" . "}", + $this->apiClient->toPathValue($pet_id), $resourcePath); + } // form params if ($name !== null) { $formParams['name'] = $this->apiClient->toFormValue($name); @@ -312,29 +312,29 @@ class PetApi { $body = http_build_query($body); } - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $body, - $headerParams); + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $body, + $headerParams); } - /** - * deletePet + /** + * deletePet * - * Deletes a pet + * Deletes a pet * * @param string $api_key (required) * @param int $pet_id Pet id to delete (required) * @return void - */ + */ public function deletePet($api_key, $pet_id) { - // parse inputs - $resourcePath = "/pet/{petId}"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "DELETE"; + // parse inputs + $resourcePath = "/pet/{petId}"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "DELETE"; $queryParams = array(); $headerParams = array(); $formParams = array(); @@ -344,13 +344,13 @@ class PetApi { // header params if($api_key !== null) { - $headerParams['api_key'] = $this->apiClient->toHeaderValue($api_key); - } + $headerParams['api_key'] = $this->apiClient->toHeaderValue($api_key); + } // path params if($pet_id !== null) { - $resourcePath = str_replace("{" . "petId" . "}", - $this->apiClient->toPathValue($pet_id), $resourcePath); - } + $resourcePath = str_replace("{" . "petId" . "}", + $this->apiClient->toPathValue($pet_id), $resourcePath); + } @@ -361,30 +361,30 @@ class PetApi { $body = http_build_query($body); } - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $body, - $headerParams); + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $body, + $headerParams); } - /** - * uploadFile + /** + * uploadFile * - * uploads an image + * uploads an image * * @param int $pet_id ID of pet to update (required) * @param string $additional_metadata Additional data to pass to server (required) * @param file $file file to upload (required) * @return void - */ + */ public function uploadFile($pet_id, $additional_metadata, $file) { - // parse inputs - $resourcePath = "/pet/{petId}/uploadImage"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "POST"; + // parse inputs + $resourcePath = "/pet/{petId}/uploadImage"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "POST"; $queryParams = array(); $headerParams = array(); $formParams = array(); @@ -395,9 +395,9 @@ class PetApi { // path params if($pet_id !== null) { - $resourcePath = str_replace("{" . "petId" . "}", - $this->apiClient->toPathValue($pet_id), $resourcePath); - } + $resourcePath = str_replace("{" . "petId" . "}", + $this->apiClient->toPathValue($pet_id), $resourcePath); + } // form params if ($additional_metadata !== null) { $formParams['additionalMetadata'] = $this->apiClient->toFormValue($additional_metadata); @@ -414,10 +414,10 @@ class PetApi { $body = http_build_query($body); } - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $body, - $headerParams); + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $body, + $headerParams); } diff --git a/samples/client/petstore/php/StoreApi.php b/samples/client/petstore/php/StoreApi.php index fbd2fc0afe..6ff2f83d1b 100644 --- a/samples/client/petstore/php/StoreApi.php +++ b/samples/client/petstore/php/StoreApi.php @@ -21,24 +21,24 @@ */ class StoreApi { - function __construct($apiClient) { - $this->apiClient = $apiClient; - } + function __construct($apiClient) { + $this->apiClient = $apiClient; + } - /** - * getInventory + /** + * getInventory * - * Returns pet inventories by status + * Returns pet inventories by status * * @return map[string,int] - */ + */ public function getInventory() { - // parse inputs - $resourcePath = "/store/inventory"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "GET"; + // parse inputs + $resourcePath = "/store/inventory"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "GET"; $queryParams = array(); $headerParams = array(); $formParams = array(); @@ -58,10 +58,10 @@ class StoreApi { $body = http_build_query($body); } - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $body, - $headerParams); + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $body, + $headerParams); if(! $response) { return null; @@ -72,20 +72,20 @@ class StoreApi { return $responseObject; } - /** - * placeOrder + /** + * placeOrder * - * Place an order for a pet + * Place an order for a pet * * @param Order $body order placed for purchasing the pet (required) * @return Order - */ + */ public function placeOrder($body) { - // parse inputs - $resourcePath = "/store/order"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "POST"; + // parse inputs + $resourcePath = "/store/order"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "POST"; $queryParams = array(); $headerParams = array(); $formParams = array(); @@ -109,10 +109,10 @@ class StoreApi { $body = http_build_query($body); } - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $body, - $headerParams); + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $body, + $headerParams); if(! $response) { return null; @@ -123,20 +123,20 @@ class StoreApi { return $responseObject; } - /** - * getOrderById + /** + * getOrderById * - * Find purchase order by ID + * Find purchase order by ID * * @param string $order_id ID of pet that needs to be fetched (required) * @return Order - */ + */ public function getOrderById($order_id) { - // parse inputs - $resourcePath = "/store/order/{orderId}"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "GET"; + // parse inputs + $resourcePath = "/store/order/{orderId}"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "GET"; $queryParams = array(); $headerParams = array(); $formParams = array(); @@ -147,9 +147,9 @@ class StoreApi { // path params if($order_id !== null) { - $resourcePath = str_replace("{" . "orderId" . "}", - $this->apiClient->toPathValue($order_id), $resourcePath); - } + $resourcePath = str_replace("{" . "orderId" . "}", + $this->apiClient->toPathValue($order_id), $resourcePath); + } @@ -160,10 +160,10 @@ class StoreApi { $body = http_build_query($body); } - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $body, - $headerParams); + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $body, + $headerParams); if(! $response) { return null; @@ -174,20 +174,20 @@ class StoreApi { return $responseObject; } - /** - * deleteOrder + /** + * deleteOrder * - * Delete purchase order by ID + * Delete purchase order by ID * * @param string $order_id ID of the order that needs to be deleted (required) * @return void - */ + */ public function deleteOrder($order_id) { - // parse inputs - $resourcePath = "/store/order/{orderId}"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "DELETE"; + // parse inputs + $resourcePath = "/store/order/{orderId}"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "DELETE"; $queryParams = array(); $headerParams = array(); $formParams = array(); @@ -198,9 +198,9 @@ class StoreApi { // path params if($order_id !== null) { - $resourcePath = str_replace("{" . "orderId" . "}", - $this->apiClient->toPathValue($order_id), $resourcePath); - } + $resourcePath = str_replace("{" . "orderId" . "}", + $this->apiClient->toPathValue($order_id), $resourcePath); + } @@ -211,10 +211,10 @@ class StoreApi { $body = http_build_query($body); } - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $body, - $headerParams); + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $body, + $headerParams); } diff --git a/samples/client/petstore/php/UserApi.php b/samples/client/petstore/php/UserApi.php index 9e0b5280e4..a811d8c9f9 100644 --- a/samples/client/petstore/php/UserApi.php +++ b/samples/client/petstore/php/UserApi.php @@ -21,25 +21,25 @@ */ class UserApi { - function __construct($apiClient) { - $this->apiClient = $apiClient; - } + function __construct($apiClient) { + $this->apiClient = $apiClient; + } - /** - * createUser + /** + * createUser * - * Create user + * Create user * * @param User $body Created user object (required) * @return void - */ + */ public function createUser($body) { - // parse inputs - $resourcePath = "/user"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "POST"; + // parse inputs + $resourcePath = "/user"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "POST"; $queryParams = array(); $headerParams = array(); $formParams = array(); @@ -63,28 +63,28 @@ class UserApi { $body = http_build_query($body); } - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $body, - $headerParams); + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $body, + $headerParams); } - /** - * createUsersWithArrayInput + /** + * createUsersWithArrayInput * - * Creates list of users with given input array + * Creates list of users with given input array * * @param array[User] $body List of user object (required) * @return void - */ + */ public function createUsersWithArrayInput($body) { - // parse inputs - $resourcePath = "/user/createWithArray"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "POST"; + // parse inputs + $resourcePath = "/user/createWithArray"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "POST"; $queryParams = array(); $headerParams = array(); $formParams = array(); @@ -108,28 +108,28 @@ class UserApi { $body = http_build_query($body); } - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $body, - $headerParams); + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $body, + $headerParams); } - /** - * createUsersWithListInput + /** + * createUsersWithListInput * - * Creates list of users with given input array + * Creates list of users with given input array * * @param array[User] $body List of user object (required) * @return void - */ + */ public function createUsersWithListInput($body) { - // parse inputs - $resourcePath = "/user/createWithList"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "POST"; + // parse inputs + $resourcePath = "/user/createWithList"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "POST"; $queryParams = array(); $headerParams = array(); $formParams = array(); @@ -153,29 +153,29 @@ class UserApi { $body = http_build_query($body); } - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $body, - $headerParams); + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $body, + $headerParams); } - /** - * loginUser + /** + * loginUser * - * Logs user into the system + * Logs user into the system * * @param string $username The user name for login (required) * @param string $password The password for login in clear text (required) * @return string - */ + */ public function loginUser($username, $password) { - // parse inputs - $resourcePath = "/user/login"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "GET"; + // parse inputs + $resourcePath = "/user/login"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "GET"; $queryParams = array(); $headerParams = array(); $formParams = array(); @@ -184,11 +184,11 @@ class UserApi { // query params if($username !== null) { - $queryParams['username'] = $this->apiClient->toQueryValue($username); - }// query params + $queryParams['username'] = $this->apiClient->toQueryValue($username); + }// query params if($password !== null) { - $queryParams['password'] = $this->apiClient->toQueryValue($password); - } + $queryParams['password'] = $this->apiClient->toQueryValue($password); + } @@ -201,10 +201,10 @@ class UserApi { $body = http_build_query($body); } - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $body, - $headerParams); + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $body, + $headerParams); if(! $response) { return null; @@ -215,19 +215,19 @@ class UserApi { return $responseObject; } - /** - * logoutUser + /** + * logoutUser * - * Logs out current logged in user session + * Logs out current logged in user session * * @return void - */ + */ public function logoutUser() { - // parse inputs - $resourcePath = "/user/logout"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "GET"; + // parse inputs + $resourcePath = "/user/logout"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "GET"; $queryParams = array(); $headerParams = array(); $formParams = array(); @@ -247,28 +247,28 @@ class UserApi { $body = http_build_query($body); } - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $body, - $headerParams); + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $body, + $headerParams); } - /** - * getUserByName + /** + * getUserByName * - * Get user by user name + * Get user by user name * * @param string $username The name that needs to be fetched. Use user1 for testing. (required) * @return User - */ + */ public function getUserByName($username) { - // parse inputs - $resourcePath = "/user/{username}"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "GET"; + // parse inputs + $resourcePath = "/user/{username}"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "GET"; $queryParams = array(); $headerParams = array(); $formParams = array(); @@ -279,9 +279,9 @@ class UserApi { // path params if($username !== null) { - $resourcePath = str_replace("{" . "username" . "}", - $this->apiClient->toPathValue($username), $resourcePath); - } + $resourcePath = str_replace("{" . "username" . "}", + $this->apiClient->toPathValue($username), $resourcePath); + } @@ -292,10 +292,10 @@ class UserApi { $body = http_build_query($body); } - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $body, - $headerParams); + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $body, + $headerParams); if(! $response) { return null; @@ -306,21 +306,21 @@ class UserApi { return $responseObject; } - /** - * updateUser + /** + * updateUser * - * Updated user + * Updated user * * @param string $username name that need to be deleted (required) * @param User $body Updated user object (required) * @return void - */ + */ public function updateUser($username, $body) { - // parse inputs - $resourcePath = "/user/{username}"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "PUT"; + // parse inputs + $resourcePath = "/user/{username}"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "PUT"; $queryParams = array(); $headerParams = array(); $formParams = array(); @@ -331,9 +331,9 @@ class UserApi { // path params if($username !== null) { - $resourcePath = str_replace("{" . "username" . "}", - $this->apiClient->toPathValue($username), $resourcePath); - } + $resourcePath = str_replace("{" . "username" . "}", + $this->apiClient->toPathValue($username), $resourcePath); + } // body params $body = null; @@ -348,28 +348,28 @@ class UserApi { $body = http_build_query($body); } - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $body, - $headerParams); + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $body, + $headerParams); } - /** - * deleteUser + /** + * deleteUser * - * Delete user + * Delete user * * @param string $username The name that needs to be deleted (required) * @return void - */ + */ public function deleteUser($username) { - // parse inputs - $resourcePath = "/user/{username}"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "DELETE"; + // parse inputs + $resourcePath = "/user/{username}"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "DELETE"; $queryParams = array(); $headerParams = array(); $formParams = array(); @@ -380,9 +380,9 @@ class UserApi { // path params if($username !== null) { - $resourcePath = str_replace("{" . "username" . "}", - $this->apiClient->toPathValue($username), $resourcePath); - } + $resourcePath = str_replace("{" . "username" . "}", + $this->apiClient->toPathValue($username), $resourcePath); + } @@ -393,10 +393,10 @@ class UserApi { $body = http_build_query($body); } - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $body, - $headerParams); + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $body, + $headerParams); } From bfb35aa3ee6b871003f089761d6210d5faf9198d Mon Sep 17 00:00:00 2001 From: William Cheng Date: Fri, 27 Mar 2015 23:49:27 +0800 Subject: [PATCH 017/192] remove {{newline}} as it has no impact at all --- .../swagger-codegen/src/main/resources/Java/api.mustache | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/Java/api.mustache b/modules/swagger-codegen/src/main/resources/Java/api.mustache index b6c87b4da1..a1c9e05042 100644 --- a/modules/swagger-codegen/src/main/resources/Java/api.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/api.mustache @@ -39,9 +39,9 @@ public class {{classname}} { {{#operation}} /** * {{summary}} - * {{notes}}{{newLine}} -{{#allParams}}{{newLine}} * @param {{paramName}} {{description}} -{{/allParams}}{{newLine}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}{{newLine}} + * {{notes}} +{{#allParams}} * @param {{paramName}} {{description}} +{{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} */ public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException { Object postBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}}; From 98c8f867e53753d381cf9d1fe397dd22466ccee9 Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Fri, 27 Mar 2015 08:52:22 -0700 Subject: [PATCH 018/192] enabled java test --- pom.xml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 8848c072c0..4f01fcc868 100644 --- a/pom.xml +++ b/pom.xml @@ -279,15 +279,14 @@ - samples + java-client env - samples + java - samples/client/petstore/objc samples/client/petstore/java From bdd1d1621f4a9d39349095fe872988543c7b39b5 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Fri, 27 Mar 2015 23:55:26 +0800 Subject: [PATCH 019/192] remove {{newLine}} and replace tab wtih 2 spaces --- .../src/main/resources/ruby/api.mustache | 16 +++++----- samples/client/petstore/ruby/lib/pet_api.rb | 16 +++++----- samples/client/petstore/ruby/lib/store_api.rb | 8 ++--- samples/client/petstore/ruby/lib/user_api.rb | 32 +++++++++---------- 4 files changed, 36 insertions(+), 36 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/ruby/api.mustache b/modules/swagger-codegen/src/main/resources/ruby/api.mustache index 62d9ac0165..6514f2c1b7 100644 --- a/modules/swagger-codegen/src/main/resources/ruby/api.mustache +++ b/modules/swagger-codegen/src/main/resources/ruby/api.mustache @@ -12,10 +12,10 @@ class {{classname}} {{#operation}} {{newline}} # {{summary}} - # {{notes}}{{newLine}} -{{#allParams}}{{^optional}}{{newLine}} # @param {{paramName}} {{description}} -{{/optional}}{{/allParams}}{{#allParams}}{{#optional}}{{newLine}} # @option opts [{{dataType}}] :{{baseName}} {{description}} -{{/optional}}{{/allParams}} # @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}{{newLine}} + # {{notes}} +{{#allParams}}{{^optional}} # @param {{paramName}} {{description}} +{{/optional}}{{/allParams}}{{#allParams}}{{#optional}} # @option opts [{{dataType}}] :{{baseName}} {{description}} +{{/optional}}{{/allParams}} # @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} def self.{{nickname}} ({{#allParams}}{{paramName}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}, {{/allParams}}opts={}) query_param_keys = [{{#queryParams}}:{{paramName}}{{#hasMore}},{{/hasMore}}{{/queryParams}}] @@ -61,10 +61,10 @@ class {{classname}} post_body = array else if body.respond_to?("to_body".to_sym) - post_body = body.to_body - else - post_body = body - end + post_body = body.to_body + else + post_body = body + end end end {{/bodyParam}} diff --git a/samples/client/petstore/ruby/lib/pet_api.rb b/samples/client/petstore/ruby/lib/pet_api.rb index a254ad8edf..771536c924 100644 --- a/samples/client/petstore/ruby/lib/pet_api.rb +++ b/samples/client/petstore/ruby/lib/pet_api.rb @@ -52,10 +52,10 @@ class PetApi post_body = array else if body.respond_to?("to_body".to_sym) - post_body = body.to_body - else - post_body = body - end + post_body = body.to_body + else + post_body = body + end end end @@ -112,10 +112,10 @@ class PetApi post_body = array else if body.respond_to?("to_body".to_sym) - post_body = body.to_body - else - post_body = body - end + post_body = body.to_body + else + post_body = body + end end end diff --git a/samples/client/petstore/ruby/lib/store_api.rb b/samples/client/petstore/ruby/lib/store_api.rb index cc93b0edd0..0d438576ec 100644 --- a/samples/client/petstore/ruby/lib/store_api.rb +++ b/samples/client/petstore/ruby/lib/store_api.rb @@ -92,10 +92,10 @@ class StoreApi post_body = array else if body.respond_to?("to_body".to_sym) - post_body = body.to_body - else - post_body = body - end + post_body = body.to_body + else + post_body = body + end end end diff --git a/samples/client/petstore/ruby/lib/user_api.rb b/samples/client/petstore/ruby/lib/user_api.rb index 3bb359674c..64aeb210f6 100644 --- a/samples/client/petstore/ruby/lib/user_api.rb +++ b/samples/client/petstore/ruby/lib/user_api.rb @@ -52,10 +52,10 @@ class UserApi post_body = array else if body.respond_to?("to_body".to_sym) - post_body = body.to_body - else - post_body = body - end + post_body = body.to_body + else + post_body = body + end end end @@ -112,10 +112,10 @@ class UserApi post_body = array else if body.respond_to?("to_body".to_sym) - post_body = body.to_body - else - post_body = body - end + post_body = body.to_body + else + post_body = body + end end end @@ -172,10 +172,10 @@ class UserApi post_body = array else if body.respond_to?("to_body".to_sym) - post_body = body.to_body - else - post_body = body - end + post_body = body.to_body + else + post_body = body + end end end @@ -358,10 +358,10 @@ class UserApi post_body = array else if body.respond_to?("to_body".to_sym) - post_body = body.to_body - else - post_body = body - end + post_body = body.to_body + else + post_body = body + end end end From 7eba8670e3bcc311442ea8a5b29b0c55001d8bca Mon Sep 17 00:00:00 2001 From: gandrianakis Date: Fri, 27 Mar 2015 18:41:16 +0200 Subject: [PATCH 020/192] Switched SingleClientConnManager with ThreadSafeClientConnManager. The SingleClientConnManager cannot be used safely in multi-threaded environments --- .../src/main/resources/android-java/apiInvoker.mustache | 3 ++- 1 file changed, 2 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 8b31abd48a..9975e3f7ea 100644 --- a/modules/swagger-codegen/src/main/resources/android-java/apiInvoker.mustache +++ b/modules/swagger-codegen/src/main/resources/android-java/apiInvoker.mustache @@ -16,6 +16,7 @@ import org.apache.http.entity.ContentType; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.*; import org.apache.http.impl.conn.*; +import org.apache.http.impl.conn.tsccm.*; import org.apache.http.params.*; import org.apache.http.util.EntityUtils; @@ -364,7 +365,7 @@ public class ApiInvoker { schemeRegistry.register(httpsScheme); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); - ignoreSSLConnectionManager = new SingleClientConnManager(new BasicHttpParams(), schemeRegistry); + ignoreSSLConnectionManager = new ThreadSafeClientConnManager(new BasicHttpParams(), schemeRegistry); } catch (NoSuchAlgorithmException e) { // This will only be thrown if SSL isn't available for some reason. } catch (KeyManagementException e) { From 236a1147b7b1cbb9f506b26b955c4603091d15dd Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Fri, 27 Mar 2015 09:53:40 -0700 Subject: [PATCH 021/192] minor comment --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4f01fcc868..29d0ec0b8d 100644 --- a/pom.xml +++ b/pom.xml @@ -277,8 +277,8 @@ + - java-client From c9a2a14da51679ba2d9bf0625a4cc11606af98fe Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Fri, 27 Mar 2015 22:17:50 -0700 Subject: [PATCH 022/192] added queryParamCollection --- bin/objc-petstore.sh | 2 +- .../codegen/languages/ObjcClientCodegen.java | 2 + .../resources/objc/SWGQueryParamCollection.h | 9 + .../resources/objc/SWGQueryParamCollection.m | 16 ++ .../src/main/resources/objc/api-body.mustache | 9 +- .../PetstoreClient.xcodeproj/project.pbxproj | 6 + .../PetstoreClientTests/PetApiTest.m | 162 ++++++++---------- .../petstore/objc/client/SWGApiClient.m | 35 +++- .../client/petstore/objc/client/SWGPetApi.m | 17 +- .../objc/client/SWGQueryParamCollection.h | 9 + .../objc/client/SWGQueryParamCollection.m | 16 ++ .../client/petstore/objc/client/SWGStoreApi.m | 1 + .../client/petstore/objc/client/SWGUserApi.m | 9 +- 13 files changed, 194 insertions(+), 99 deletions(-) create mode 100644 modules/swagger-codegen/src/main/resources/objc/SWGQueryParamCollection.h create mode 100644 modules/swagger-codegen/src/main/resources/objc/SWGQueryParamCollection.m create mode 100644 samples/client/petstore/objc/client/SWGQueryParamCollection.h create mode 100644 samples/client/petstore/objc/client/SWGQueryParamCollection.m diff --git a/bin/objc-petstore.sh b/bin/objc-petstore.sh index feefc99a28..513b753578 100755 --- a/bin/objc-petstore.sh +++ b/bin/objc-petstore.sh @@ -26,6 +26,6 @@ fi # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l objc -o samples/client/petstore/objc" +ags="$@ generate -t modules/swagger-codegen/src/main/resources/objc -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l objc -o samples/client/petstore/objc" java -DappName=PetstoreClient $JAVA_OPTS -jar $executable $ags diff --git a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/ObjcClientCodegen.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/ObjcClientCodegen.java index 2e91cafa99..76d9e41935 100644 --- a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/ObjcClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/ObjcClientCodegen.java @@ -102,6 +102,8 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig { supportingFiles.add(new SupportingFile("SWGObject.h", sourceFolder, "SWGObject.h")); supportingFiles.add(new SupportingFile("SWGObject.m", sourceFolder, "SWGObject.m")); + supportingFiles.add(new SupportingFile("SWGQueryParamCollection.h", sourceFolder, "SWGQueryParamCollection.h")); + supportingFiles.add(new SupportingFile("SWGQueryParamCollection.m", sourceFolder, "SWGQueryParamCollection.m")); supportingFiles.add(new SupportingFile("SWGApiClient.h", sourceFolder, "SWGApiClient.h")); supportingFiles.add(new SupportingFile("SWGApiClient.m", sourceFolder, "SWGApiClient.m")); supportingFiles.add(new SupportingFile("SWGFile.h", sourceFolder, "SWGFile.h")); diff --git a/modules/swagger-codegen/src/main/resources/objc/SWGQueryParamCollection.h b/modules/swagger-codegen/src/main/resources/objc/SWGQueryParamCollection.h new file mode 100644 index 0000000000..26b830875f --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/objc/SWGQueryParamCollection.h @@ -0,0 +1,9 @@ +@interface SWGQueryParamCollection : NSObject + +@property(nonatomic, readonly) NSArray* values; +@property(nonatomic, readonly) NSString* format; + +- (id) initWithValuesAndFormat: (NSArray*) values + format: (NSString*) format; + +@end diff --git a/modules/swagger-codegen/src/main/resources/objc/SWGQueryParamCollection.m b/modules/swagger-codegen/src/main/resources/objc/SWGQueryParamCollection.m new file mode 100644 index 0000000000..9ce319940d --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/objc/SWGQueryParamCollection.m @@ -0,0 +1,16 @@ +#import "SWGQueryParamCollection.h" + +@implementation SWGQueryParamCollection + +@synthesize values = _values; +@synthesize format = _format; + +- (id) initWithValuesAndFormat: (NSArray*) values + format: (NSString*) format { + _values = values; + _format = format; + + return self; +} + +@end \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/objc/api-body.mustache b/modules/swagger-codegen/src/main/resources/objc/api-body.mustache index ffead406a8..e079df918a 100644 --- a/modules/swagger-codegen/src/main/resources/objc/api-body.mustache +++ b/modules/swagger-codegen/src/main/resources/objc/api-body.mustache @@ -1,6 +1,7 @@ {{#operations}} #import "{{classname}}.h" #import "SWGFile.h" +#import "SWGQueryParamCollection.h" #import "SWGApiClient.h" {{#imports}}#import "{{import}}.h" {{/imports}} @@ -71,8 +72,12 @@ static NSString * basePath = @"{{basePath}}"; NSString* responseContentType = @"application/json"; NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; - {{#queryParams}}if({{paramName}} != nil) - queryParams[@"{{baseName}}"] = {{paramName}}; + {{#queryParams}}if({{paramName}} != nil) { + {{#collectionFormat}} + queryParams[@"{{baseName}}"] = [[SWGQueryParamCollection alloc] initWithValuesAndFormat: {{baseName}} format: @"{{collectionFormat}}"]; + {{/collectionFormat}} + {{^collectionFormat}}queryParams[@"{{baseName}}"] = {{paramName}};{{/collectionFormat}} + } {{/queryParams}} NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init]; {{#headerParams}}if({{paramName}} != nil) diff --git a/samples/client/petstore/objc/PetstoreClient/PetstoreClient.xcodeproj/project.pbxproj b/samples/client/petstore/objc/PetstoreClient/PetstoreClient.xcodeproj/project.pbxproj index 66a244ebf3..bf04a276ca 100644 --- a/samples/client/petstore/objc/PetstoreClient/PetstoreClient.xcodeproj/project.pbxproj +++ b/samples/client/petstore/objc/PetstoreClient/PetstoreClient.xcodeproj/project.pbxproj @@ -23,6 +23,7 @@ EA6699BE1811D2FB00A70D03 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EA66999D1811D2FA00A70D03 /* UIKit.framework */; }; EA6699C61811D2FB00A70D03 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = EA6699C41811D2FB00A70D03 /* InfoPlist.strings */; }; EA6699C81811D2FB00A70D03 /* PetApiTest.m in Sources */ = {isa = PBXBuildFile; fileRef = EA6699C71811D2FB00A70D03 /* PetApiTest.m */; }; + EA8B8AA41AC6683700638FBB /* SWGQueryParamCollection.m in Sources */ = {isa = PBXBuildFile; fileRef = EA8B8AA31AC6683700638FBB /* SWGQueryParamCollection.m */; }; EA8CD3ED1AC2763600C47D0B /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EA8CD3EC1AC2763600C47D0B /* SenTestingKit.framework */; }; EAEA85E41811D3AE00F06E69 /* SWGApiClient.m in Sources */ = {isa = PBXBuildFile; fileRef = EAEA85CD1811D3AE00F06E69 /* SWGApiClient.m */; }; EAEA85E51811D3AE00F06E69 /* SWGCategory.m in Sources */ = {isa = PBXBuildFile; fileRef = EAEA85CF1811D3AE00F06E69 /* SWGCategory.m */; }; @@ -75,6 +76,8 @@ EA6699C31811D2FB00A70D03 /* PetstoreClientTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "PetstoreClientTests-Info.plist"; sourceTree = ""; }; EA6699C51811D2FB00A70D03 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; EA6699C71811D2FB00A70D03 /* PetApiTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PetApiTest.m; sourceTree = ""; }; + EA8B8AA21AC6683700638FBB /* SWGQueryParamCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SWGQueryParamCollection.h; sourceTree = ""; }; + EA8B8AA31AC6683700638FBB /* SWGQueryParamCollection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SWGQueryParamCollection.m; sourceTree = ""; }; EA8CD3EB1AC274BE00C47D0B /* PetApiTest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PetApiTest.h; sourceTree = ""; }; EA8CD3EC1AC2763600C47D0B /* SenTestingKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SenTestingKit.framework; path = Library/Frameworks/SenTestingKit.framework; sourceTree = DEVELOPER_DIR; }; EAEA85CC1811D3AE00F06E69 /* SWGApiClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SWGApiClient.h; sourceTree = ""; }; @@ -227,6 +230,8 @@ EAEA85CB1811D3AE00F06E69 /* client */ = { isa = PBXGroup; children = ( + EA8B8AA21AC6683700638FBB /* SWGQueryParamCollection.h */, + EA8B8AA31AC6683700638FBB /* SWGQueryParamCollection.m */, EAFBEABC1A92C42700A27431 /* SWGApiResponse.h */, EAFBEABD1A92C42700A27431 /* SWGApiResponse.m */, EAEA85CC1811D3AE00F06E69 /* SWGApiClient.h */, @@ -407,6 +412,7 @@ EAEA85EC1811D3AE00F06E69 /* SWGStoreApi.m in Sources */, EAEA85E91811D3AE00F06E69 /* SWGOrder.m in Sources */, EAEA85E81811D3AE00F06E69 /* SWGObject.m in Sources */, + EA8B8AA41AC6683700638FBB /* SWGQueryParamCollection.m in Sources */, EAEA85E71811D3AE00F06E69 /* SWGFile.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/samples/client/petstore/objc/PetstoreClient/PetstoreClientTests/PetApiTest.m b/samples/client/petstore/objc/PetstoreClient/PetstoreClientTests/PetApiTest.m index f21e8fc516..8c5d597748 100644 --- a/samples/client/petstore/objc/PetstoreClient/PetstoreClientTests/PetApiTest.m +++ b/samples/client/petstore/objc/PetstoreClient/PetstoreClientTests/PetApiTest.m @@ -6,96 +6,45 @@ - (void)setUp { [super setUp]; api = [[SWGPetApi alloc ]init]; - [SWGPetApi setBasePath:@"http://localhost:8080/api"]; } - (void)tearDown { [super tearDown]; } -- (void)testGetPetById { +- (void)testCreateAndGetPet { XCTestExpectation *expectation = [self expectationWithDescription:@"testGetPetById"]; - [api getPetByIdWithCompletionBlock:@1 completionHandler:^(SWGPet *output, NSError *error) { - if(error){ - XCTFail(@"got error %@", error); - } - if(output){ - XCTAssertNotNil([output _id], @"token was nil"); - } - [expectation fulfill]; - }]; - [self waitForExpectationsWithTimeout:2.0 handler:nil]; -} -- (void) testAddPet { - XCTestExpectation *expectation = [self expectationWithDescription:@"testAddPet"]; + SWGPet* pet = [self createPet]; - SWGPet * petToAdd = [[SWGPet alloc] init]; - [petToAdd set_id:@1000]; - NSMutableArray* tags = [[NSMutableArray alloc] init]; - for(int i = 0; i < 5; i++){ - SWGTag * tag = [[SWGTag alloc] init]; - [tag set_id:[NSNumber numberWithInt:i]]; - [tag setName:[NSString stringWithFormat:@"tag-%d", i]]; - [tags addObject:tag]; - } - [petToAdd setTags:tags]; - [petToAdd setStatus:@"lost"]; - - SWGCategory * category = [[SWGCategory alloc] init]; - [category setName:@"sold"]; - [petToAdd setCategory:category]; - [petToAdd setName:@"dragon"]; - - NSMutableArray* photos = [[NSMutableArray alloc] init]; - for(int i = 0; i < 10; i++){ - NSString * url = [NSString stringWithFormat:@"http://foo.com/photo/%d", i]; - [photos addObject:url]; - } - [petToAdd setPhotoUrls:photos]; - - [api addPetWithCompletionBlock:petToAdd completionHandler:^(NSError *error) { + [api addPetWithCompletionBlock:pet completionHandler:^(NSError *error) { if(error){ XCTFail(@"got error %@", error); } - [expectation fulfill]; + NSLog(@"%@", [pet _id]); + [api getPetByIdWithCompletionBlock:[pet _id] completionHandler:^(SWGPet *output, NSError *error) { + if(error){ + XCTFail(@"got error %@", error); + } + if(output){ + XCTAssertNotNil([output _id], @"token was nil"); + } + [expectation fulfill]; + }]; }]; - [self waitForExpectationsWithTimeout:2.0 handler:nil]; } - (void) testUpdatePet { XCTestExpectation *expectation = [self expectationWithDescription:@"testUpdatePet"]; - SWGPet * petToAdd = [[SWGPet alloc] init]; - [petToAdd set_id:[NSNumber numberWithInt:1000]]; - NSMutableArray* tags = [[NSMutableArray alloc] init]; - for(int i = 0; i < 5; i++){ - SWGTag * tag = [[SWGTag alloc] init]; - [tag set_id:[NSNumber numberWithInt:i]]; - [tag setName:[NSString stringWithFormat:@"tag-%d", i]]; - [tags addObject:tag]; - } - [petToAdd setTags:tags]; - [petToAdd setStatus:@"lost"]; + SWGPet* pet = [self createPet]; - SWGCategory * category = [[SWGCategory alloc] init]; - [category setName:@"sold"]; - [petToAdd setCategory:category]; - [petToAdd setName:@"dragon"]; - - NSMutableArray* photos = [[NSMutableArray alloc] init]; - for(int i = 0; i < 10; i++){ - NSString * url = [NSString stringWithFormat:@"http://foo.com/photo/%d", i]; - [photos addObject:url]; - } - [petToAdd setPhotoUrls:photos]; - - [api addPetWithCompletionBlock:petToAdd completionHandler:^(NSError *error) { + [api addPetWithCompletionBlock:pet completionHandler:^(NSError *error) { if(error) { XCTFail(@"got error %@", error); } else { - [api getPetByIdWithCompletionBlock:[NSString stringWithFormat:@"%@",[petToAdd _id]] completionHandler:^(SWGPet *output, NSError *error) { + [api getPetByIdWithCompletionBlock:[NSString stringWithFormat:@"%@",[pet _id]] completionHandler:^(SWGPet *output, NSError *error) { if(error) { XCTFail(@"got error %@", error); } @@ -140,39 +89,78 @@ - (void)testGetPetByStatus { XCTestExpectation *expectation = [self expectationWithDescription:@"testGetPetByStatus"]; - [api findPetsByStatusWithCompletionBlock:@"available" completionHandler:^(NSArray *output, NSError *error) { + SWGPet* pet = [self createPet]; + + [api addPetWithCompletionBlock:pet completionHandler:^(NSError *error) { if(error) { XCTFail(@"got error %@", error); } - if(output == nil){ - XCTFail(@"failed to fetch pets"); - } - else { - [expectation fulfill]; - } + NSArray* status = [[NSArray alloc] initWithObjects:@"available", nil]; + [api findPetsByStatusWithCompletionBlock:status completionHandler:^(NSArray *output, NSError *error) { + if(error) { + XCTFail(@"got error %@", error); + } + if(output == nil){ + XCTFail(@"failed to fetch pets"); + } + else { + for(SWGPet* fetched in output) { + if([pet _id] == [fetched _id]) { + [expectation fulfill]; + } + } + } + }]; }]; [self waitForExpectationsWithTimeout:2.0 handler:nil]; } - (void)testGetPetByTags { XCTestExpectation *expectation = [self expectationWithDescription:@"testGetPetByTags"]; - [api findPetsByTagsWithCompletionBlock:@"tag1,tag2" completionHandler:^(NSArray *output, NSError *error) { - if(error){ + SWGPet* pet = [self createPet]; + SWGTag* tag = [[SWGTag alloc] init]; + tag.name = @"tony"; + pet.tags = [[NSArray alloc] initWithObjects:tag, nil]; + + [api addPetWithCompletionBlock:pet completionHandler:^(NSError *error) { + if(error) { XCTFail(@"got error %@", error); } - if(output){ - for(SWGPet * pet in output) { - bool hasTag = false; - for(SWGTag * tag in [pet tags]){ - if([[tag name] isEqualToString:@"tag1"] || [[tag name] isEqualToString:@"tag2"]) - hasTag = true; - } - if(!hasTag) - XCTFail(@"failed to find tag in pet"); + NSArray* tags = [[NSArray alloc] initWithObjects:@"tony", nil]; + + [api findPetsByTagsWithCompletionBlock:tags completionHandler:^(NSArray *output, NSError *error) { + if(error){ + XCTFail(@"got error %@", error); } - } - [expectation fulfill]; + if(output){ + for(SWGPet * fetched in output) { + bool hasTag = false; + for(SWGTag * tag in [fetched tags]){ + if(fetched._id == pet._id && [[tag name] isEqualToString:@"tony"]) + hasTag = true; + } + if(!hasTag) + XCTFail(@"failed to find tag in pet"); + } + } + [expectation fulfill]; + }]; }]; [self waitForExpectationsWithTimeout:2.0 handler:nil]; } + +- (SWGPet*) createPet { + SWGPet * pet = [[SWGPet alloc] init]; + pet._id = [[NSNumber alloc] initWithLong:[[NSDate date] timeIntervalSince1970]]; + pet.name = @"monkey"; + SWGCategory * category = [[SWGCategory alloc] init]; + category.name = @"super-happy"; + + pet.category = category; + pet.status = @"available"; + + NSArray * photos = [[NSArray alloc] initWithObjects:@"http://foo.bar.com/3", @"http://foo.bar.com/4", nil]; + pet.photoUrls = photos; + return pet; +} @end \ No newline at end of file diff --git a/samples/client/petstore/objc/client/SWGApiClient.m b/samples/client/petstore/objc/client/SWGApiClient.m index ff454970cf..36af6ea44c 100644 --- a/samples/client/petstore/objc/client/SWGApiClient.m +++ b/samples/client/petstore/objc/client/SWGApiClient.m @@ -1,5 +1,6 @@ #import "SWGApiClient.h" #import "SWGFile.h" +#import "SWGQueryParamCollection.h" @implementation SWGApiClient @@ -208,14 +209,42 @@ static bool loggingEnabled = true; if(counter == 0) separator = @"?"; else separator = @"&"; NSString * value; - if([[queryParams valueForKey:key] isKindOfClass:[NSString class]]){ + id queryParamValue = [queryParams valueForKey:key]; + if([queryParamValue isKindOfClass:[NSString class]]){ value = [SWGApiClient escape:[queryParams valueForKey:key]]; + [requestUrl appendString:[NSString stringWithFormat:@"%@%@=%@", separator, + [SWGApiClient escape:key], value]]; + } + else if ([queryParamValue isKindOfClass:[SWGQueryParamCollection class]]) { + SWGQueryParamCollection* c = (SWGQueryParamCollection* ) queryParamValue; + NSString * format = [c format]; + NSArray * values = [c values]; + if([format isEqualToString:@"csv"]) { + [requestUrl appendString:[NSString stringWithFormat:@"%@%@=%@", separator, + [SWGApiClient escape:key], [values componentsJoinedByString:@","]]]; + } + else if([format isEqualToString:@"tsv"]) { + [requestUrl appendString:[NSString stringWithFormat:@"%@%@=%@", separator, + [SWGApiClient escape:key], [values componentsJoinedByString:@"\t"]]]; + } + else if ([format isEqualToString:@"pipes"]) { + [requestUrl appendString:[NSString stringWithFormat:@"%@%@=%@", separator, + [SWGApiClient escape:key], [values componentsJoinedByString:@"|"]]]; + } + else if([format isEqualToString:@"multi"]) { + for(id obj in values) { + + [requestUrl appendString: [NSString stringWithFormat:@"%@%@=%@", separator, [SWGApiClient escape:key], obj]]; + if(counter > 0) separator = @"&"; + } + } } else { value = [NSString stringWithFormat:@"%@", [queryParams valueForKey:key]]; + [requestUrl appendString:[NSString stringWithFormat:@"%@%@=%@", separator, + [SWGApiClient escape:key], value]]; } - [requestUrl appendString:[NSString stringWithFormat:@"%@%@=%@", separator, - [SWGApiClient escape:key], value]]; + counter += 1; } } diff --git a/samples/client/petstore/objc/client/SWGPetApi.m b/samples/client/petstore/objc/client/SWGPetApi.m index 5d134bb1f2..a52077eeab 100644 --- a/samples/client/petstore/objc/client/SWGPetApi.m +++ b/samples/client/petstore/objc/client/SWGPetApi.m @@ -1,5 +1,6 @@ #import "SWGPetApi.h" #import "SWGFile.h" +#import "SWGQueryParamCollection.h" #import "SWGApiClient.h" #import "SWGPet.h" #import "SWGFile.h" @@ -230,8 +231,12 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; NSString* responseContentType = @"application/json"; NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; - if(status != nil) - queryParams[@"status"] = status; + if(status != nil) { + + queryParams[@"status"] = [[SWGQueryParamCollection alloc] initWithValuesAndFormat: status format: @"multi"]; + + + } NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init]; @@ -303,8 +308,12 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; NSString* responseContentType = @"application/json"; NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; - if(tags != nil) - queryParams[@"tags"] = tags; + if(tags != nil) { + + queryParams[@"tags"] = [[SWGQueryParamCollection alloc] initWithValuesAndFormat: tags format: @"multi"]; + + + } NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init]; diff --git a/samples/client/petstore/objc/client/SWGQueryParamCollection.h b/samples/client/petstore/objc/client/SWGQueryParamCollection.h new file mode 100644 index 0000000000..26b830875f --- /dev/null +++ b/samples/client/petstore/objc/client/SWGQueryParamCollection.h @@ -0,0 +1,9 @@ +@interface SWGQueryParamCollection : NSObject + +@property(nonatomic, readonly) NSArray* values; +@property(nonatomic, readonly) NSString* format; + +- (id) initWithValuesAndFormat: (NSArray*) values + format: (NSString*) format; + +@end diff --git a/samples/client/petstore/objc/client/SWGQueryParamCollection.m b/samples/client/petstore/objc/client/SWGQueryParamCollection.m new file mode 100644 index 0000000000..9ce319940d --- /dev/null +++ b/samples/client/petstore/objc/client/SWGQueryParamCollection.m @@ -0,0 +1,16 @@ +#import "SWGQueryParamCollection.h" + +@implementation SWGQueryParamCollection + +@synthesize values = _values; +@synthesize format = _format; + +- (id) initWithValuesAndFormat: (NSArray*) values + format: (NSString*) format { + _values = values; + _format = format; + + return self; +} + +@end \ No newline at end of file diff --git a/samples/client/petstore/objc/client/SWGStoreApi.m b/samples/client/petstore/objc/client/SWGStoreApi.m index 3eb015ebc0..65d4751943 100644 --- a/samples/client/petstore/objc/client/SWGStoreApi.m +++ b/samples/client/petstore/objc/client/SWGStoreApi.m @@ -1,5 +1,6 @@ #import "SWGStoreApi.h" #import "SWGFile.h" +#import "SWGQueryParamCollection.h" #import "SWGApiClient.h" #import "SWGOrder.h" diff --git a/samples/client/petstore/objc/client/SWGUserApi.m b/samples/client/petstore/objc/client/SWGUserApi.m index 6e33862d11..85037247af 100644 --- a/samples/client/petstore/objc/client/SWGUserApi.m +++ b/samples/client/petstore/objc/client/SWGUserApi.m @@ -1,5 +1,6 @@ #import "SWGUserApi.h" #import "SWGFile.h" +#import "SWGQueryParamCollection.h" #import "SWGApiClient.h" #import "SWGUser.h" @@ -311,10 +312,14 @@ static NSString * basePath = @"http://petstore.swagger.io/v2"; NSString* responseContentType = @"application/json"; NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; - if(username != nil) + if(username != nil) { + queryParams[@"username"] = username; - if(password != nil) + } + if(password != nil) { + queryParams[@"password"] = password; + } NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init]; From 99271e77ab66624fd6ba05d11374e34864ec4f25 Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Fri, 27 Mar 2015 22:55:06 -0700 Subject: [PATCH 023/192] added multi-param args --- .../src/main/resources/objc/SWGApiClient.m | 42 +++++++++++++++-- .../main/resources/objc/api-header.mustache | 7 +-- .../PetstoreClientTests/PetApiTest.m | 46 ++++++++++++++++--- .../petstore/objc/client/SWGApiClient.m | 37 ++++++++------- .../client/petstore/objc/client/SWGPetApi.h | 29 ------------ .../client/petstore/objc/client/SWGStoreApi.h | 11 ----- .../client/petstore/objc/client/SWGUserApi.h | 25 ---------- 7 files changed, 98 insertions(+), 99 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/objc/SWGApiClient.m b/modules/swagger-codegen/src/main/resources/objc/SWGApiClient.m index ff454970cf..f84d7b3f62 100644 --- a/modules/swagger-codegen/src/main/resources/objc/SWGApiClient.m +++ b/modules/swagger-codegen/src/main/resources/objc/SWGApiClient.m @@ -1,5 +1,6 @@ #import "SWGApiClient.h" #import "SWGFile.h" +#import "SWGQueryParamCollection.h" @implementation SWGApiClient @@ -208,14 +209,45 @@ static bool loggingEnabled = true; if(counter == 0) separator = @"?"; else separator = @"&"; NSString * value; - if([[queryParams valueForKey:key] isKindOfClass:[NSString class]]){ - value = [SWGApiClient escape:[queryParams valueForKey:key]]; + id queryParam = [queryParams valueForKey:key]; + if([queryParam isKindOfClass:[NSString class]]){ + [requestUrl appendString:[NSString stringWithFormat:@"%@%@=%@", separator, + [SWGApiClient escape:key], [SWGApiClient escape:[queryParams valueForKey:key]]]]; + } + else if([queryParam isKindOfClass:[SWGQueryParamCollection class]]){ + SWGQueryParamCollection * coll = (SWGQueryParamCollection*) queryParam; + NSArray* values = [coll values]; + NSString* format = [coll format]; + + if([format isEqualToString:@"csv"]) { + [requestUrl appendString:[NSString stringWithFormat:@"%@%@=%@", separator, + [SWGApiClient escape:key], [NSString stringWithFormat:@"%@", [values componentsJoinedByString:@","]]]]; + + } + else if([format isEqualToString:@"tsv"]) { + [requestUrl appendString:[NSString stringWithFormat:@"%@%@=%@", separator, + [SWGApiClient escape:key], [NSString stringWithFormat:@"%@", [values componentsJoinedByString:@"\t"]]]]; + + } + else if([format isEqualToString:@"pipes"]) { + [requestUrl appendString:[NSString stringWithFormat:@"%@%@=%@", separator, + [SWGApiClient escape:key], [NSString stringWithFormat:@"%@", [values componentsJoinedByString:@"|"]]]]; + + } + else if([format isEqualToString:@"multi"]) { + for(id obj in values) { + [requestUrl appendString:[NSString stringWithFormat:@"%@%@=%@", separator, + [SWGApiClient escape:key], [NSString stringWithFormat:@"%@", obj]]]; + counter += 1; + } + + } } else { - value = [NSString stringWithFormat:@"%@", [queryParams valueForKey:key]]; + [requestUrl appendString:[NSString stringWithFormat:@"%@%@=%@", separator, + [SWGApiClient escape:key], [NSString stringWithFormat:@"%@", [queryParams valueForKey:key]]]]; } - [requestUrl appendString:[NSString stringWithFormat:@"%@%@=%@", separator, - [SWGApiClient escape:key], value]]; + counter += 1; } } diff --git a/modules/swagger-codegen/src/main/resources/objc/api-header.mustache b/modules/swagger-codegen/src/main/resources/objc/api-header.mustache index c42c02d5af..c5ef04f18a 100644 --- a/modules/swagger-codegen/src/main/resources/objc/api-header.mustache +++ b/modules/swagger-codegen/src/main/resources/objc/api-header.mustache @@ -16,12 +16,9 @@ /** {{{summary}}} - {{#notes}} - {{{notes}}} - {{/notes}} + {{#notes}}{{{notes}}}{{/notes}} - {{#allParams}} - @param {{paramName}} {{description}} + {{#allParams}}@param {{paramName}} {{description}} {{/allParams}} return type: {{returnType}} diff --git a/samples/client/petstore/objc/PetstoreClient/PetstoreClientTests/PetApiTest.m b/samples/client/petstore/objc/PetstoreClient/PetstoreClientTests/PetApiTest.m index 8c5d597748..d9ae301710 100644 --- a/samples/client/petstore/objc/PetstoreClient/PetstoreClientTests/PetApiTest.m +++ b/samples/client/petstore/objc/PetstoreClient/PetstoreClientTests/PetApiTest.m @@ -32,7 +32,7 @@ [expectation fulfill]; }]; }]; - [self waitForExpectationsWithTimeout:2.0 handler:nil]; + [self waitForExpectationsWithTimeout:10.0 handler:nil]; } - (void) testUpdatePet { @@ -84,7 +84,7 @@ }]; } }]; - [self waitForExpectationsWithTimeout:2.0 handler:nil]; + [self waitForExpectationsWithTimeout:10.0 handler:nil]; } - (void)testGetPetByStatus { @@ -104,15 +104,18 @@ XCTFail(@"failed to fetch pets"); } else { + bool found = false; for(SWGPet* fetched in output) { if([pet _id] == [fetched _id]) { - [expectation fulfill]; + found = true; } } + if(found) + [expectation fulfill]; } }]; }]; - [self waitForExpectationsWithTimeout:2.0 handler:nil]; + [self waitForExpectationsWithTimeout:10.0 handler:nil]; } - (void)testGetPetByTags { @@ -133,8 +136,8 @@ XCTFail(@"got error %@", error); } if(output){ + bool hasTag = false; for(SWGPet * fetched in output) { - bool hasTag = false; for(SWGTag * tag in [fetched tags]){ if(fetched._id == pet._id && [[tag name] isEqualToString:@"tony"]) hasTag = true; @@ -142,11 +145,40 @@ if(!hasTag) XCTFail(@"failed to find tag in pet"); } + if(hasTag) + [expectation fulfill]; } - [expectation fulfill]; }]; }]; - [self waitForExpectationsWithTimeout:2.0 handler:nil]; + [self waitForExpectationsWithTimeout:10.0 handler:nil]; +} + +- (void)testDeletePet { + XCTestExpectation *expectation = [self expectationWithDescription:@"testGetPetById"]; + + SWGPet* pet = [self createPet]; + + [api addPetWithCompletionBlock:pet completionHandler:^(NSError *error) { + if(error){ + XCTFail(@"got error %@", error); + } + [api deletePetWithCompletionBlock:@"" petId:[NSString stringWithFormat:@"%@", [pet _id]] completionHandler:^(NSError *error) { + if(error){ + XCTFail(@"got error %@", error); + } + [api getPetByIdWithCompletionBlock:[pet _id] completionHandler:^(SWGPet *output, NSError *error) { + if(error) { + // good + [expectation fulfill]; + + } + else { + XCTFail(@"expected a failure"); + } + }]; + }]; + }]; + [self waitForExpectationsWithTimeout:10.0 handler:nil]; } - (SWGPet*) createPet { diff --git a/samples/client/petstore/objc/client/SWGApiClient.m b/samples/client/petstore/objc/client/SWGApiClient.m index 36af6ea44c..f84d7b3f62 100644 --- a/samples/client/petstore/objc/client/SWGApiClient.m +++ b/samples/client/petstore/objc/client/SWGApiClient.m @@ -209,40 +209,43 @@ static bool loggingEnabled = true; if(counter == 0) separator = @"?"; else separator = @"&"; NSString * value; - id queryParamValue = [queryParams valueForKey:key]; - if([queryParamValue isKindOfClass:[NSString class]]){ - value = [SWGApiClient escape:[queryParams valueForKey:key]]; + id queryParam = [queryParams valueForKey:key]; + if([queryParam isKindOfClass:[NSString class]]){ [requestUrl appendString:[NSString stringWithFormat:@"%@%@=%@", separator, - [SWGApiClient escape:key], value]]; + [SWGApiClient escape:key], [SWGApiClient escape:[queryParams valueForKey:key]]]]; } - else if ([queryParamValue isKindOfClass:[SWGQueryParamCollection class]]) { - SWGQueryParamCollection* c = (SWGQueryParamCollection* ) queryParamValue; - NSString * format = [c format]; - NSArray * values = [c values]; + else if([queryParam isKindOfClass:[SWGQueryParamCollection class]]){ + SWGQueryParamCollection * coll = (SWGQueryParamCollection*) queryParam; + NSArray* values = [coll values]; + NSString* format = [coll format]; + if([format isEqualToString:@"csv"]) { [requestUrl appendString:[NSString stringWithFormat:@"%@%@=%@", separator, - [SWGApiClient escape:key], [values componentsJoinedByString:@","]]]; + [SWGApiClient escape:key], [NSString stringWithFormat:@"%@", [values componentsJoinedByString:@","]]]]; + } else if([format isEqualToString:@"tsv"]) { [requestUrl appendString:[NSString stringWithFormat:@"%@%@=%@", separator, - [SWGApiClient escape:key], [values componentsJoinedByString:@"\t"]]]; + [SWGApiClient escape:key], [NSString stringWithFormat:@"%@", [values componentsJoinedByString:@"\t"]]]]; + } - else if ([format isEqualToString:@"pipes"]) { + else if([format isEqualToString:@"pipes"]) { [requestUrl appendString:[NSString stringWithFormat:@"%@%@=%@", separator, - [SWGApiClient escape:key], [values componentsJoinedByString:@"|"]]]; + [SWGApiClient escape:key], [NSString stringWithFormat:@"%@", [values componentsJoinedByString:@"|"]]]]; + } else if([format isEqualToString:@"multi"]) { for(id obj in values) { - - [requestUrl appendString: [NSString stringWithFormat:@"%@%@=%@", separator, [SWGApiClient escape:key], obj]]; - if(counter > 0) separator = @"&"; + [requestUrl appendString:[NSString stringWithFormat:@"%@%@=%@", separator, + [SWGApiClient escape:key], [NSString stringWithFormat:@"%@", obj]]]; + counter += 1; } + } } else { - value = [NSString stringWithFormat:@"%@", [queryParams valueForKey:key]]; [requestUrl appendString:[NSString stringWithFormat:@"%@%@=%@", separator, - [SWGApiClient escape:key], value]]; + [SWGApiClient escape:key], [NSString stringWithFormat:@"%@", [queryParams valueForKey:key]]]]; } counter += 1; diff --git a/samples/client/petstore/objc/client/SWGPetApi.h b/samples/client/petstore/objc/client/SWGPetApi.h index b40a210ea4..e444cea8f4 100644 --- a/samples/client/petstore/objc/client/SWGPetApi.h +++ b/samples/client/petstore/objc/client/SWGPetApi.h @@ -15,10 +15,7 @@ Update an existing pet - - - @param body Pet object that needs to be added to the store @@ -34,10 +31,7 @@ Add a new pet to the store - - - @param body Pet object that needs to be added to the store @@ -52,11 +46,8 @@ /** Finds Pets by status - Multiple status values can be provided with comma seperated strings - - @param status Status values that need to be considered for filter @@ -71,11 +62,8 @@ /** Finds Pets by tags - Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. - - @param tags Tags to filter by @@ -90,11 +78,8 @@ /** 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 @@ -110,14 +95,9 @@ Updates a pet in the store with form data - - - @param petId ID of pet that needs to be updated - @param name Updated name of the pet - @param status Updated status of the pet @@ -135,12 +115,8 @@ Deletes a pet - - - @param api_key - @param petId Pet id to delete @@ -157,14 +133,9 @@ uploads an image - - - @param petId ID of pet to update - @param additionalMetadata Additional data to pass to server - @param file file to upload diff --git a/samples/client/petstore/objc/client/SWGStoreApi.h b/samples/client/petstore/objc/client/SWGStoreApi.h index 2daa1e8656..b4b8e5af5d 100644 --- a/samples/client/petstore/objc/client/SWGStoreApi.h +++ b/samples/client/petstore/objc/client/SWGStoreApi.h @@ -13,9 +13,7 @@ /** Returns pet inventories by status - Returns a map of status codes to quantities - @@ -30,10 +28,7 @@ Place an order for a pet - - - @param body order placed for purchasing the pet @@ -48,11 +43,8 @@ /** Find purchase order by ID - For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions - - @param orderId ID of pet that needs to be fetched @@ -67,11 +59,8 @@ /** Delete purchase order by ID - For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors - - @param orderId ID of the order that needs to be deleted diff --git a/samples/client/petstore/objc/client/SWGUserApi.h b/samples/client/petstore/objc/client/SWGUserApi.h index 14d08208f8..d110c02776 100644 --- a/samples/client/petstore/objc/client/SWGUserApi.h +++ b/samples/client/petstore/objc/client/SWGUserApi.h @@ -13,11 +13,8 @@ /** Create user - This can only be done by the logged in user. - - @param body Created user object @@ -33,10 +30,7 @@ Creates list of users with given input array - - - @param body List of user object @@ -52,10 +46,7 @@ Creates list of users with given input array - - - @param body List of user object @@ -71,12 +62,8 @@ Logs user into the system - - - @param username The user name for login - @param password The password for login in clear text @@ -93,8 +80,6 @@ Logs out current logged in user session - - @@ -109,10 +94,7 @@ Get user by user name - - - @param username The name that needs to be fetched. Use user1 for testing. @@ -127,13 +109,9 @@ /** Updated user - This can only be done by the logged in user. - - @param username name that need to be deleted - @param body Updated user object @@ -149,11 +127,8 @@ /** Delete user - This can only be done by the logged in user. - - @param username The name that needs to be deleted From 0686a9169018094e8386bed4f6101191a5ec4a5c Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Fri, 27 Mar 2015 23:18:54 -0700 Subject: [PATCH 024/192] updated camelize function for #567 --- .../wordnik/swagger/codegen/DefaultCodegen.java | 15 +++++++++++++++ .../src/test/scala/Java/JavaModelTest.scala | 11 +++++++++++ 2 files changed, 26 insertions(+) diff --git a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/DefaultCodegen.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/DefaultCodegen.java index f0664a72c7..062bcb5fe2 100644 --- a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/DefaultCodegen.java +++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/DefaultCodegen.java @@ -1099,6 +1099,21 @@ public class DefaultCodegen { m = p.matcher(word); } + // case out dots + String[] parts = word.split("\\."); + StringBuilder f = new StringBuilder(); + for(String z : parts) { + if(z.length() > 0) + f.append(Character.toUpperCase(z.charAt(0))).append(z.substring(1)); + } + word = f.toString(); + + m = p.matcher(word); + while (m.find()) { + word = m.replaceFirst("" + Character.toUpperCase(m.group(1).charAt(0)) + m.group(1).substring(1)/*.toUpperCase()*/); + m = p.matcher(word); + } + // Uppercase the class name. p = Pattern.compile("(\\.?)(\\w)([^\\.]*)$"); m = p.matcher(word); diff --git a/modules/swagger-codegen/src/test/scala/Java/JavaModelTest.scala b/modules/swagger-codegen/src/test/scala/Java/JavaModelTest.scala index a5d30bc680..16fd6677a4 100644 --- a/modules/swagger-codegen/src/test/scala/Java/JavaModelTest.scala +++ b/modules/swagger-codegen/src/test/scala/Java/JavaModelTest.scala @@ -335,4 +335,15 @@ class JavaModelTest extends FlatSpec with Matchers { vars.get(0).setter should be ("setCreatedAt") vars.get(0).name should be ("createdAt") } + + it should "properly escape names per 567" in { + val model = new ModelImpl() + .description("a sample model") + .property("created-at", new DateTimeProperty()) + + val codegen = new JavaClientCodegen() + val cm = codegen.fromModel("with.dots", model) + val vars = cm.vars + cm.classname should be ("WithDots") + } } From 27e1b1c4b2f1036ae3985f9f424c2c47b6252384 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 26 Mar 2015 16:27:00 +0800 Subject: [PATCH 025/192] update java doc --- .../src/main/resources/Java/api.mustache | 10 +-- .../java/io/swagger/client/api/PetApi.java | 61 ++++++++++++++++--- .../java/io/swagger/client/api/StoreApi.java | 27 ++++++-- .../java/io/swagger/client/api/UserApi.java | 57 ++++++++++++++--- 4 files changed, 131 insertions(+), 24 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/Java/api.mustache b/modules/swagger-codegen/src/main/resources/Java/api.mustache index 20829f8297..b6c87b4da1 100644 --- a/modules/swagger-codegen/src/main/resources/Java/api.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/api.mustache @@ -37,10 +37,12 @@ public class {{classname}} { } {{#operation}} - {{#errorList}} //error info- code: {{code}} reason: "{{reason}}" model: {{#responseModel}}{{responseModel}} - {{/responseModel}}{{^responseModel}} - {{/responseModel}} - {{/errorList}} + /** + * {{summary}} + * {{notes}}{{newLine}} +{{#allParams}}{{newLine}} * @param {{paramName}} {{description}} +{{/allParams}}{{newLine}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}{{newLine}} + */ public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException { Object postBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}}; {{#requiredParamCount}} diff --git a/samples/client/petstore/java/src/main/java/io/swagger/client/api/PetApi.java b/samples/client/petstore/java/src/main/java/io/swagger/client/api/PetApi.java index cf6cdc3f0c..234cdadece 100644 --- a/samples/client/petstore/java/src/main/java/io/swagger/client/api/PetApi.java +++ b/samples/client/petstore/java/src/main/java/io/swagger/client/api/PetApi.java @@ -36,7 +36,12 @@ public class PetApi { } - + /** + * Update an existing pet + * + * @param body Pet object that needs to be added to the store + * @return void + */ public void updatePet (Pet body) throws ApiException { Object postBody = body; @@ -81,7 +86,12 @@ public class PetApi { } } - + /** + * Add a new pet to the store + * + * @param body Pet object that needs to be added to the store + * @return void + */ public void addPet (Pet body) throws ApiException { Object postBody = body; @@ -126,7 +136,12 @@ public class PetApi { } } - + /** + * Finds Pets by status + * Multiple status values can be provided with comma seperated strings + * @param status Status values that need to be considered for filter + * @return List + */ public List findPetsByStatus (List status) throws ApiException { Object postBody = null; @@ -173,7 +188,12 @@ public class PetApi { } } - + /** + * Finds Pets by tags + * Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. + * @param tags Tags to filter by + * @return List + */ public List findPetsByTags (List tags) throws ApiException { Object postBody = null; @@ -220,7 +240,12 @@ 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 + * @return Pet + */ public Pet getPetById (Long petId) throws ApiException { Object postBody = null; @@ -266,7 +291,14 @@ public class PetApi { } } - + /** + * Updates a pet in the store with form data + * + * @param petId ID of pet that needs to be updated + * @param name Updated name of the pet + * @param status Updated status of the pet + * @return void + */ public void updatePetWithForm (String petId, String name, String status) throws ApiException { Object postBody = null; @@ -320,7 +352,13 @@ public class PetApi { } } - + /** + * Deletes a pet + * + * @param apiKey + * @param petId Pet id to delete + * @return void + */ public void deletePet (String apiKey, Long petId) throws ApiException { Object postBody = null; @@ -367,7 +405,14 @@ public class PetApi { } } - + /** + * uploads an image + * + * @param petId ID of pet to update + * @param additionalMetadata Additional data to pass to server + * @param file file to upload + * @return void + */ public void uploadFile (Long petId, String additionalMetadata, File file) throws ApiException { Object postBody = null; diff --git a/samples/client/petstore/java/src/main/java/io/swagger/client/api/StoreApi.java b/samples/client/petstore/java/src/main/java/io/swagger/client/api/StoreApi.java index 318c55df21..cff340e69d 100644 --- a/samples/client/petstore/java/src/main/java/io/swagger/client/api/StoreApi.java +++ b/samples/client/petstore/java/src/main/java/io/swagger/client/api/StoreApi.java @@ -36,7 +36,11 @@ public class StoreApi { } - + /** + * Returns pet inventories by status + * Returns a map of status codes to quantities + * @return Map + */ public Map getInventory () throws ApiException { Object postBody = null; @@ -81,7 +85,12 @@ public class StoreApi { } } - + /** + * Place an order for a pet + * + * @param body order placed for purchasing the pet + * @return Order + */ public Order placeOrder (Order body) throws ApiException { Object postBody = body; @@ -126,7 +135,12 @@ public class StoreApi { } } - + /** + * Find purchase order by ID + * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + * @param orderId ID of pet that needs to be fetched + * @return Order + */ public Order getOrderById (String orderId) throws ApiException { Object postBody = null; @@ -172,7 +186,12 @@ public class StoreApi { } } - + /** + * Delete purchase order by ID + * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + * @param orderId ID of the order that needs to be deleted + * @return void + */ public void deleteOrder (String orderId) throws ApiException { Object postBody = null; diff --git a/samples/client/petstore/java/src/main/java/io/swagger/client/api/UserApi.java b/samples/client/petstore/java/src/main/java/io/swagger/client/api/UserApi.java index e50c034ab1..2296c0223c 100644 --- a/samples/client/petstore/java/src/main/java/io/swagger/client/api/UserApi.java +++ b/samples/client/petstore/java/src/main/java/io/swagger/client/api/UserApi.java @@ -36,7 +36,12 @@ public class UserApi { } - + /** + * Create user + * This can only be done by the logged in user. + * @param body Created user object + * @return void + */ public void createUser (User body) throws ApiException { Object postBody = body; @@ -81,7 +86,12 @@ public class UserApi { } } - + /** + * Creates list of users with given input array + * + * @param body List of user object + * @return void + */ public void createUsersWithArrayInput (List body) throws ApiException { Object postBody = body; @@ -126,7 +136,12 @@ public class UserApi { } } - + /** + * Creates list of users with given input array + * + * @param body List of user object + * @return void + */ public void createUsersWithListInput (List body) throws ApiException { Object postBody = body; @@ -171,7 +186,13 @@ public class UserApi { } } - + /** + * Logs user into the system + * + * @param username The user name for login + * @param password The password for login in clear text + * @return String + */ public String loginUser (String username, String password) throws ApiException { Object postBody = null; @@ -220,7 +241,11 @@ public class UserApi { } } - + /** + * Logs out current logged in user session + * + * @return void + */ public void logoutUser () throws ApiException { Object postBody = null; @@ -265,7 +290,12 @@ public class UserApi { } } - + /** + * Get user by user name + * + * @param username The name that needs to be fetched. Use user1 for testing. + * @return User + */ public User getUserByName (String username) throws ApiException { Object postBody = null; @@ -311,7 +341,13 @@ public class UserApi { } } - + /** + * Updated user + * This can only be done by the logged in user. + * @param username name that need to be deleted + * @param body Updated user object + * @return void + */ public void updateUser (String username, User body) throws ApiException { Object postBody = body; @@ -357,7 +393,12 @@ public class UserApi { } } - + /** + * Delete user + * This can only be done by the logged in user. + * @param username The name that needs to be deleted + * @return void + */ public void deleteUser (String username) throws ApiException { Object postBody = null; From a12cc1c5448b193e9ed20f5e27fd4bacdd041ce7 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Fri, 27 Mar 2015 23:49:27 +0800 Subject: [PATCH 026/192] remove {{newline}} as it has no impact at all --- .../swagger-codegen/src/main/resources/Java/api.mustache | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/Java/api.mustache b/modules/swagger-codegen/src/main/resources/Java/api.mustache index b6c87b4da1..a1c9e05042 100644 --- a/modules/swagger-codegen/src/main/resources/Java/api.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/api.mustache @@ -39,9 +39,9 @@ public class {{classname}} { {{#operation}} /** * {{summary}} - * {{notes}}{{newLine}} -{{#allParams}}{{newLine}} * @param {{paramName}} {{description}} -{{/allParams}}{{newLine}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}{{newLine}} + * {{notes}} +{{#allParams}} * @param {{paramName}} {{description}} +{{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} */ public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException { Object postBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}}; From c2b3e68f8c6ad5b5ce31c2439a07d5c4403c68cc Mon Sep 17 00:00:00 2001 From: William Cheng Date: Sat, 28 Mar 2015 16:48:07 +0800 Subject: [PATCH 027/192] rebase on develop_2.0 --- samples/client/petstore/java/hello.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 samples/client/petstore/java/hello.txt diff --git a/samples/client/petstore/java/hello.txt b/samples/client/petstore/java/hello.txt new file mode 100644 index 0000000000..6769dd60bd --- /dev/null +++ b/samples/client/petstore/java/hello.txt @@ -0,0 +1 @@ +Hello world! \ No newline at end of file From 0dcd307333639fe5e5a2136b0941993ba56ce6d7 Mon Sep 17 00:00:00 2001 From: MerkushevKirill Date: Wed, 25 Mar 2015 12:58:22 +0300 Subject: [PATCH 028/192] update docs and bash about CLI usage, deprecate old cli classes (after #547) --- README.md | 57 ++++++++++++------- bin/all-petstore.sh | 3 +- .../com/wordnik/swagger/codegen/Readme.java | 7 --- .../swagger/codegen/SwaggerCodegen.java | 5 ++ .../wordnik/swagger/codegen/cmd/Generate.java | 12 ++-- .../com/wordnik/swagger/codegen/cmd/Meta.java | 12 ++-- .../com/wordnik/swagger/codegen/Codegen.java | 5 ++ .../swagger/codegen/MetaGenerator.java | 5 ++ 8 files changed, 65 insertions(+), 41 deletions(-) delete mode 100644 modules/swagger-codegen-cli/src/main/java/com/wordnik/swagger/codegen/Readme.java diff --git a/README.md b/README.md index ec3c7e67a4..bb52eb3a39 100644 --- a/README.md +++ b/README.md @@ -52,23 +52,41 @@ java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \ -o samples/client/petstore/java ``` -With a number of options. You can get the options with the -h flag: +With a number of options. You can get the options with the `help generate` command: + ``` -usage: Codegen - -a,--auth addes authorization headers when fetching the - swagger definitions remotely. Pass in a - URL-encoded string of name:header with a comma - separating multiple values - -d,--debug-info prints additional info for debugging - -h,--help shows this message - -i,--input-spec location of the swagger spec, as URL or file - -l,--lang client language to generate. - Available languages include: - [android, async-scala, java, jaxrs, nodejs, - objc, scalatra, scala, dynamic-html, html, - swagger, tizen, php, ruby, python] - -o,--output where to write the generated files - -t,--template-dir folder containing the template files +NAME + swagger generate - Generate code with chosen lang + +SYNOPSIS + swagger generate [(-a | --auth )] + (-i | --input-spec ) + (-l | --lang ) + [(-o | --output )] + [(-t