Skip to content

[ObjC] Fix #2121, generated method names don't follow coding convention #2125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.swagger.codegen.CliOption;
import io.swagger.codegen.CodegenConfig;
import io.swagger.codegen.CodegenConstants;
import io.swagger.codegen.CodegenOperation;
import io.swagger.codegen.CodegenProperty;
import io.swagger.codegen.CodegenType;
import io.swagger.codegen.DefaultCodegen;
Expand All @@ -13,6 +14,8 @@
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.lang.StringUtils;
Expand Down Expand Up @@ -456,6 +459,21 @@ public void setLicense(String license) {
this.license = license;
}

@Override
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
if (operations != null) {
List<CodegenOperation> ops = (List<CodegenOperation>) operations.get("operation");
for (CodegenOperation operation : ops) {
if (!operation.allParams.isEmpty()) {
String firstParamName = operation.allParams.get(0).paramName;
operation.vendorExtensions.put("firstParamAltName", camelize(firstParamName));
}
}
}
return objs;
}

/**
* Return the default value of the property
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,19 +499,19 @@ static void (^reachabilityChangeBlock)(int);

#pragma mark - Perform Request Methods

-(NSNumber*) requestWithCompletionBlock: (NSString*) path
method: (NSString*) method
pathParams: (NSDictionary *) pathParams
queryParams: (NSDictionary*) queryParams
formParams: (NSDictionary *) formParams
files: (NSDictionary *) files
body: (id) body
headerParams: (NSDictionary*) headerParams
authSettings: (NSArray *) authSettings
requestContentType: (NSString*) requestContentType
responseContentType: (NSString*) responseContentType
responseType: (NSString *) responseType
completionBlock: (void (^)(id, NSError *))completionBlock {
-(NSNumber*) requestWithPath: (NSString*) path
method: (NSString*) method
pathParams: (NSDictionary *) pathParams
queryParams: (NSDictionary*) queryParams
formParams: (NSDictionary *) formParams
files: (NSDictionary *) files
body: (id) body
headerParams: (NSDictionary*) headerParams
authSettings: (NSArray *) authSettings
requestContentType: (NSString*) requestContentType
responseContentType: (NSString*) responseContentType
responseType: (NSString *) responseType
completionBlock: (void (^)(id, NSError *))completionBlock {
// setting request serializer
if ([requestContentType isEqualToString:@"application/json"]) {
self.requestSerializer = [{{classPrefix}}JSONRequestSerializer serializer];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,19 +186,19 @@ extern NSString *const {{classPrefix}}ResponseObjectErrorKey;
*
* @return The request id.
*/
-(NSNumber*) requestWithCompletionBlock:(NSString*) path
method:(NSString*) method
pathParams:(NSDictionary *) pathParams
queryParams:(NSDictionary*) queryParams
formParams:(NSDictionary *) formParams
files:(NSDictionary *) files
body:(id) body
headerParams:(NSDictionary*) headerParams
authSettings: (NSArray *) authSettings
requestContentType:(NSString*) requestContentType
responseContentType:(NSString*) responseContentType
responseType:(NSString *) responseType
completionBlock:(void (^)(id, NSError *))completionBlock;
-(NSNumber*) requestWithPath:(NSString*) path
method:(NSString*) method
pathParams:(NSDictionary *) pathParams
queryParams:(NSDictionary*) queryParams
formParams:(NSDictionary *) formParams
files:(NSDictionary *) files
body:(id) body
headerParams:(NSDictionary*) headerParams
authSettings:(NSArray *) authSettings
requestContentType:(NSString*) requestContentType
responseContentType:(NSString*) responseContentType
responseType:(NSString *) responseType
completionBlock:(void (^)(id, NSError *))completionBlock;

/**
* Sanitize object for request
Expand Down
38 changes: 18 additions & 20 deletions modules/swagger-codegen/src/main/resources/objc/api-body.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,9 @@ static {{classname}}* singletonAPI = nil;
///
/// {{/allParams}} @returns {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
///
-(NSNumber*) {{nickname}}WithCompletionBlock{{^allParams}}: {{/allParams}}{{#allParams}}{{#secondaryParam}} {{paramName}}{{/secondaryParam}}: ({{{dataType}}}) {{paramName}}
{{/allParams}}
{{#returnBaseType}}{{#hasParams}}completionHandler: {{/hasParams}}(void (^)({{{returnType}}} output, NSError* error))completionBlock { {{/returnBaseType}}
{{^returnBaseType}}{{#hasParams}}completionHandler: {{/hasParams}}(void (^)(NSError* error))completionBlock { {{/returnBaseType}}
-(NSNumber*) {{#vendorExtensions.x-objc-operationId}}{{vendorExtensions.x-objc-operationId}}{{/vendorExtensions.x-objc-operationId}}{{^vendorExtensions.x-objc-operationId}}{{nickname}}{{#hasParams}}With{{vendorExtensions.firstParamAltName}}{{/hasParams}}{{^hasParams}}WithCompletionHandler: {{/hasParams}}{{/vendorExtensions.x-objc-operationId}}{{#allParams}}{{#secondaryParam}}
{{paramName}}{{/secondaryParam}}: ({{{dataType}}}) {{paramName}}{{/allParams}}
{{#hasParams}}completionHandler: {{/hasParams}}(void (^)({{#returnBaseType}}{{{returnType}}} output, {{/returnBaseType}}NSError* error)) handler {

{{#allParams}}{{#required}}
// verify the required parameter '{{paramName}}' is set
Expand Down Expand Up @@ -164,22 +163,21 @@ static {{classname}}* singletonAPI = nil;
}
{{/requiredParams}}
{{/requiredParamCount}}
return [self.apiClient requestWithCompletionBlock: resourcePath
method: @"{{httpMethod}}"
pathParams: pathParams
queryParams: queryParams
formParams: formParams
files: files
body: bodyParam
headerParams: headerParams
authSettings: authSettings
requestContentType: requestContentType
responseContentType: responseContentType
responseType: {{^returnType}}nil{{/returnType}}{{#returnType}}@"{{{ returnType }}}"{{/returnType}}
completionBlock: ^(id data, NSError *error) {
{{^returnType}}completionBlock(error);{{/returnType}}
{{#returnType}}completionBlock(({{{ returnType }}})data, error);{{/returnType}}
}
return [self.apiClient requestWithPath: resourcePath
method: @"{{httpMethod}}"
pathParams: pathParams
queryParams: queryParams
formParams: formParams
files: files
body: bodyParam
headerParams: headerParams
authSettings: authSettings
requestContentType: requestContentType
responseContentType: responseContentType
responseType: {{^returnType}}nil{{/returnType}}{{#returnType}}@"{{{ returnType }}}"{{/returnType}}
completionBlock: ^(id data, NSError *error) {
handler({{#returnType}}({{{ returnType }}})data, {{/returnType}}error);
}
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,9 @@
/// {{/allParams}}
///
/// @return {{{returnType}}}
-(NSNumber*) {{nickname}}WithCompletionBlock {{^allParams}}:{{/allParams}}{{#allParams}}{{#secondaryParam}} {{paramName}}{{/secondaryParam}}:({{{dataType}}}) {{paramName}} {{#hasMore}}
{{/hasMore}}{{/allParams}}
{{#returnBaseType}}{{#hasParams}}
completionHandler: {{/hasParams}}(void (^)({{{returnType}}} output, NSError* error))completionBlock;{{/returnBaseType}}
{{^returnBaseType}}{{#hasParams}}
completionHandler: {{/hasParams}}(void (^)(NSError* error))completionBlock;{{/returnBaseType}}
-(NSNumber*) {{#vendorExtensions.x-objc-operationId}}{{vendorExtensions.x-objc-operationId}}{{/vendorExtensions.x-objc-operationId}}{{^vendorExtensions.x-objc-operationId}}{{nickname}}{{#hasParams}}With{{vendorExtensions.firstParamAltName}}{{/hasParams}}{{^hasParams}}WithCompletionHandler: {{/hasParams}}{{/vendorExtensions.x-objc-operationId}}{{#allParams}}{{#secondaryParam}}
{{paramName}}{{/secondaryParam}}: ({{{dataType}}}) {{paramName}}{{/allParams}}
{{#hasParams}}completionHandler: {{/hasParams}}(void (^)({{#returnBaseType}}{{{returnType}}} output, {{/returnBaseType}}NSError* error)) handler;

{{newline}}
{{/operation}}
Expand Down
26 changes: 13 additions & 13 deletions samples/client/petstore/objc/SwaggerClient/SWGApiClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,19 +190,19 @@ extern NSString *const SWGResponseObjectErrorKey;
*
* @return The request id.
*/
-(NSNumber*) requestWithCompletionBlock:(NSString*) path
method:(NSString*) method
pathParams:(NSDictionary *) pathParams
queryParams:(NSDictionary*) queryParams
formParams:(NSDictionary *) formParams
files:(NSDictionary *) files
body:(id) body
headerParams:(NSDictionary*) headerParams
authSettings: (NSArray *) authSettings
requestContentType:(NSString*) requestContentType
responseContentType:(NSString*) responseContentType
responseType:(NSString *) responseType
completionBlock:(void (^)(id, NSError *))completionBlock;
-(NSNumber*) requestWithPath:(NSString*) path
method:(NSString*) method
pathParams:(NSDictionary *) pathParams
queryParams:(NSDictionary*) queryParams
formParams:(NSDictionary *) formParams
files:(NSDictionary *) files
body:(id) body
headerParams:(NSDictionary*) headerParams
authSettings:(NSArray *) authSettings
requestContentType:(NSString*) requestContentType
responseContentType:(NSString*) responseContentType
responseType:(NSString *) responseType
completionBlock:(void (^)(id, NSError *))completionBlock;

/**
* Sanitize object for request
Expand Down
26 changes: 13 additions & 13 deletions samples/client/petstore/objc/SwaggerClient/SWGApiClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -499,19 +499,19 @@ - (void) downloadOperationWithCompletionBlock: (NSURLRequest *)request

#pragma mark - Perform Request Methods

-(NSNumber*) requestWithCompletionBlock: (NSString*) path
method: (NSString*) method
pathParams: (NSDictionary *) pathParams
queryParams: (NSDictionary*) queryParams
formParams: (NSDictionary *) formParams
files: (NSDictionary *) files
body: (id) body
headerParams: (NSDictionary*) headerParams
authSettings: (NSArray *) authSettings
requestContentType: (NSString*) requestContentType
responseContentType: (NSString*) responseContentType
responseType: (NSString *) responseType
completionBlock: (void (^)(id, NSError *))completionBlock {
-(NSNumber*) requestWithPath: (NSString*) path
method: (NSString*) method
pathParams: (NSDictionary *) pathParams
queryParams: (NSDictionary*) queryParams
formParams: (NSDictionary *) formParams
files: (NSDictionary *) files
body: (id) body
headerParams: (NSDictionary*) headerParams
authSettings: (NSArray *) authSettings
requestContentType: (NSString*) requestContentType
responseContentType: (NSString*) responseContentType
responseType: (NSString *) responseType
completionBlock: (void (^)(id, NSError *))completionBlock {
// setting request serializer
if ([requestContentType isEqualToString:@"application/json"]) {
self.requestSerializer = [SWGJSONRequestSerializer serializer];
Expand Down
70 changes: 25 additions & 45 deletions samples/client/petstore/objc/SwaggerClient/SWGPetApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@
///
///
/// @return
-(NSNumber*) updatePetWithCompletionBlock :(SWGPet*) body


completionHandler: (void (^)(NSError* error))completionBlock;
-(NSNumber*) updatePetWithBody: (SWGPet*) body
completionHandler: (void (^)(NSError* error)) handler;


///
Expand All @@ -43,10 +41,8 @@
///
///
/// @return
-(NSNumber*) addPetWithCompletionBlock :(SWGPet*) body


completionHandler: (void (^)(NSError* error))completionBlock;
-(NSNumber*) addPetWithBody: (SWGPet*) body
completionHandler: (void (^)(NSError* error)) handler;


///
Expand All @@ -58,10 +54,8 @@
///
///
/// @return NSArray<SWGPet>*
-(NSNumber*) findPetsByStatusWithCompletionBlock :(NSArray* /* NSString */) status

completionHandler: (void (^)(NSArray<SWGPet>* output, NSError* error))completionBlock;

-(NSNumber*) findPetsByStatusWithStatus: (NSArray* /* NSString */) status
completionHandler: (void (^)(NSArray<SWGPet>* output, NSError* error)) handler;


///
Expand All @@ -73,10 +67,8 @@
///
///
/// @return NSArray<SWGPet>*
-(NSNumber*) findPetsByTagsWithCompletionBlock :(NSArray* /* NSString */) tags

completionHandler: (void (^)(NSArray<SWGPet>* output, NSError* error))completionBlock;

-(NSNumber*) findPetsByTagsWithTags: (NSArray* /* NSString */) tags
completionHandler: (void (^)(NSArray<SWGPet>* output, NSError* error)) handler;


///
Expand All @@ -88,10 +80,8 @@
///
///
/// @return SWGPet*
-(NSNumber*) getPetByIdWithCompletionBlock :(NSNumber*) petId

completionHandler: (void (^)(SWGPet* output, NSError* error))completionBlock;

-(NSNumber*) getPetByIdWithPetId: (NSNumber*) petId
completionHandler: (void (^)(SWGPet* output, NSError* error)) handler;


///
Expand All @@ -105,12 +95,10 @@
///
///
/// @return
-(NSNumber*) updatePetWithFormWithCompletionBlock :(NSString*) petId
name:(NSString*) name
status:(NSString*) status


completionHandler: (void (^)(NSError* error))completionBlock;
-(NSNumber*) updatePetWithFormWithPetId: (NSString*) petId
name: (NSString*) name
status: (NSString*) status
completionHandler: (void (^)(NSError* error)) handler;


///
Expand All @@ -123,11 +111,9 @@
///
///
/// @return
-(NSNumber*) deletePetWithCompletionBlock :(NSNumber*) petId
apiKey:(NSString*) apiKey


completionHandler: (void (^)(NSError* error))completionBlock;
-(NSNumber*) deletePetWithPetId: (NSNumber*) petId
apiKey: (NSString*) apiKey
completionHandler: (void (^)(NSError* error)) handler;


///
Expand All @@ -141,12 +127,10 @@
///
///
/// @return
-(NSNumber*) uploadFileWithCompletionBlock :(NSNumber*) petId
additionalMetadata:(NSString*) additionalMetadata
file:(NSURL*) file


completionHandler: (void (^)(NSError* error))completionBlock;
-(NSNumber*) uploadFileWithPetId: (NSNumber*) petId
additionalMetadata: (NSString*) additionalMetadata
file: (NSURL*) file
completionHandler: (void (^)(NSError* error)) handler;


///
Expand All @@ -158,10 +142,8 @@
///
///
/// @return NSString*
-(NSNumber*) getPetByIdWithByteArrayWithCompletionBlock :(NSNumber*) petId

completionHandler: (void (^)(NSString* output, NSError* error))completionBlock;

-(NSNumber*) getPetByIdWithByteArrayWithPetId: (NSNumber*) petId
completionHandler: (void (^)(NSString* output, NSError* error)) handler;


///
Expand All @@ -173,10 +155,8 @@
///
///
/// @return
-(NSNumber*) addPetUsingByteArrayWithCompletionBlock :(NSString*) body


completionHandler: (void (^)(NSError* error))completionBlock;
-(NSNumber*) addPetUsingByteArrayWithBody: (NSString*) body
completionHandler: (void (^)(NSError* error)) handler;



Expand Down
Loading