Skip to content

Commit bad7e35

Browse files
committed
generated ObjC method names to follow Apple's coding convention
1 parent af594ea commit bad7e35

File tree

5 files changed

+65
-52
lines changed

5 files changed

+65
-52
lines changed

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/ObjcClientCodegen.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import io.swagger.codegen.CliOption;
44
import io.swagger.codegen.CodegenConfig;
55
import io.swagger.codegen.CodegenConstants;
6+
import io.swagger.codegen.CodegenOperation;
67
import io.swagger.codegen.CodegenProperty;
78
import io.swagger.codegen.CodegenType;
89
import io.swagger.codegen.DefaultCodegen;
@@ -13,6 +14,8 @@
1314
import java.util.Arrays;
1415
import java.util.HashMap;
1516
import java.util.HashSet;
17+
import java.util.List;
18+
import java.util.Map;
1619
import java.util.Set;
1720

1821
import org.apache.commons.lang.StringUtils;
@@ -456,6 +459,21 @@ public void setLicense(String license) {
456459
this.license = license;
457460
}
458461

462+
@Override
463+
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
464+
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
465+
if (operations != null) {
466+
List<CodegenOperation> ops = (List<CodegenOperation>) operations.get("operation");
467+
for (CodegenOperation operation : ops) {
468+
if (!operation.allParams.isEmpty()) {
469+
String firstParamName = operation.allParams.get(0).paramName;
470+
operation.vendorExtensions.put("firstParamAltName", camelize(firstParamName));
471+
}
472+
}
473+
}
474+
return objs;
475+
}
476+
459477
/**
460478
* Return the default value of the property
461479
*

modules/swagger-codegen/src/main/resources/objc/ApiClient-body.mustache

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -499,19 +499,19 @@ static void (^reachabilityChangeBlock)(int);
499499

500500
#pragma mark - Perform Request Methods
501501

502-
-(NSNumber*) requestWithCompletionBlock: (NSString*) path
503-
method: (NSString*) method
504-
pathParams: (NSDictionary *) pathParams
505-
queryParams: (NSDictionary*) queryParams
506-
formParams: (NSDictionary *) formParams
507-
files: (NSDictionary *) files
508-
body: (id) body
509-
headerParams: (NSDictionary*) headerParams
510-
authSettings: (NSArray *) authSettings
511-
requestContentType: (NSString*) requestContentType
512-
responseContentType: (NSString*) responseContentType
513-
responseType: (NSString *) responseType
514-
completionBlock: (void (^)(id, NSError *))completionBlock {
502+
-(NSNumber*) requestWithPath: (NSString*) path
503+
method: (NSString*) method
504+
pathParams: (NSDictionary *) pathParams
505+
queryParams: (NSDictionary*) queryParams
506+
formParams: (NSDictionary *) formParams
507+
files: (NSDictionary *) files
508+
body: (id) body
509+
headerParams: (NSDictionary*) headerParams
510+
authSettings: (NSArray *) authSettings
511+
requestContentType: (NSString*) requestContentType
512+
responseContentType: (NSString*) responseContentType
513+
responseType: (NSString *) responseType
514+
completionBlock: (void (^)(id, NSError *))completionBlock {
515515
// setting request serializer
516516
if ([requestContentType isEqualToString:@"application/json"]) {
517517
self.requestSerializer = [{{classPrefix}}JSONRequestSerializer serializer];

modules/swagger-codegen/src/main/resources/objc/ApiClient-header.mustache

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -186,19 +186,19 @@ extern NSString *const {{classPrefix}}ResponseObjectErrorKey;
186186
*
187187
* @return The request id.
188188
*/
189-
-(NSNumber*) requestWithCompletionBlock:(NSString*) path
190-
method:(NSString*) method
191-
pathParams:(NSDictionary *) pathParams
192-
queryParams:(NSDictionary*) queryParams
193-
formParams:(NSDictionary *) formParams
194-
files:(NSDictionary *) files
195-
body:(id) body
196-
headerParams:(NSDictionary*) headerParams
197-
authSettings: (NSArray *) authSettings
198-
requestContentType:(NSString*) requestContentType
199-
responseContentType:(NSString*) responseContentType
200-
responseType:(NSString *) responseType
201-
completionBlock:(void (^)(id, NSError *))completionBlock;
189+
-(NSNumber*) requestWithPath:(NSString*) path
190+
method:(NSString*) method
191+
pathParams:(NSDictionary *) pathParams
192+
queryParams:(NSDictionary*) queryParams
193+
formParams:(NSDictionary *) formParams
194+
files:(NSDictionary *) files
195+
body:(id) body
196+
headerParams:(NSDictionary*) headerParams
197+
authSettings:(NSArray *) authSettings
198+
requestContentType:(NSString*) requestContentType
199+
responseContentType:(NSString*) responseContentType
200+
responseType:(NSString *) responseType
201+
completionBlock:(void (^)(id, NSError *))completionBlock;
202202

203203
/**
204204
* Sanitize object for request

modules/swagger-codegen/src/main/resources/objc/api-body.mustache

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,9 @@ static {{classname}}* singletonAPI = nil;
7979
///
8080
/// {{/allParams}} @returns {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
8181
///
82-
-(NSNumber*) {{nickname}}WithCompletionBlock{{^allParams}}: {{/allParams}}{{#allParams}}{{#secondaryParam}} {{paramName}}{{/secondaryParam}}: ({{{dataType}}}) {{paramName}}
83-
{{/allParams}}
84-
{{#returnBaseType}}{{#hasParams}}completionHandler: {{/hasParams}}(void (^)({{{returnType}}} output, NSError* error))completionBlock { {{/returnBaseType}}
85-
{{^returnBaseType}}{{#hasParams}}completionHandler: {{/hasParams}}(void (^)(NSError* error))completionBlock { {{/returnBaseType}}
82+
-(NSNumber*) {{nickname}}{{#hasParams}}With{{vendorExtensions.firstParamAltName}}{{/hasParams}}{{^hasParams}}WithCompletionHandler: {{/hasParams}}{{#allParams}}{{#secondaryParam}}
83+
{{paramName}}{{/secondaryParam}}: ({{{dataType}}}) {{paramName}}{{/allParams}}
84+
{{#hasParams}}completionHandler: {{/hasParams}}(void (^)({{#returnBaseType}}{{{returnType}}} output, {{/returnBaseType}}NSError* error)) handler {
8685
8786
{{#allParams}}{{#required}}
8887
// verify the required parameter '{{paramName}}' is set
@@ -164,22 +163,21 @@ static {{classname}}* singletonAPI = nil;
164163
}
165164
{{/requiredParams}}
166165
{{/requiredParamCount}}
167-
return [self.apiClient requestWithCompletionBlock: resourcePath
168-
method: @"{{httpMethod}}"
169-
pathParams: pathParams
170-
queryParams: queryParams
171-
formParams: formParams
172-
files: files
173-
body: bodyParam
174-
headerParams: headerParams
175-
authSettings: authSettings
176-
requestContentType: requestContentType
177-
responseContentType: responseContentType
178-
responseType: {{^returnType}}nil{{/returnType}}{{#returnType}}@"{{{ returnType }}}"{{/returnType}}
179-
completionBlock: ^(id data, NSError *error) {
180-
{{^returnType}}completionBlock(error);{{/returnType}}
181-
{{#returnType}}completionBlock(({{{ returnType }}})data, error);{{/returnType}}
182-
}
166+
return [self.apiClient requestWithPath: resourcePath
167+
method: @"{{httpMethod}}"
168+
pathParams: pathParams
169+
queryParams: queryParams
170+
formParams: formParams
171+
files: files
172+
body: bodyParam
173+
headerParams: headerParams
174+
authSettings: authSettings
175+
requestContentType: requestContentType
176+
responseContentType: responseContentType
177+
responseType: {{^returnType}}nil{{/returnType}}{{#returnType}}@"{{{ returnType }}}"{{/returnType}}
178+
completionBlock: ^(id data, NSError *error) {
179+
handler({{#returnType}}({{{ returnType }}})data, {{/returnType}}error);
180+
}
183181
];
184182
}
185183

modules/swagger-codegen/src/main/resources/objc/api-header.mustache

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,9 @@
3131
/// {{/allParams}}
3232
///
3333
/// @return {{{returnType}}}
34-
-(NSNumber*) {{nickname}}WithCompletionBlock {{^allParams}}:{{/allParams}}{{#allParams}}{{#secondaryParam}} {{paramName}}{{/secondaryParam}}:({{{dataType}}}) {{paramName}} {{#hasMore}}
35-
{{/hasMore}}{{/allParams}}
36-
{{#returnBaseType}}{{#hasParams}}
37-
completionHandler: {{/hasParams}}(void (^)({{{returnType}}} output, NSError* error))completionBlock;{{/returnBaseType}}
38-
{{^returnBaseType}}{{#hasParams}}
39-
completionHandler: {{/hasParams}}(void (^)(NSError* error))completionBlock;{{/returnBaseType}}
34+
-(NSNumber*) {{nickname}}{{#hasParams}}With{{vendorExtensions.firstParamAltName}}{{/hasParams}}{{^hasParams}}WithCompletionHandler: {{/hasParams}}{{#allParams}}{{#secondaryParam}}
35+
{{paramName}}{{/secondaryParam}}: ({{{dataType}}}) {{paramName}}{{/allParams}}
36+
{{#hasParams}}completionHandler: {{/hasParams}}(void (^)({{#returnBaseType}}{{{returnType}}} output, {{/returnBaseType}}NSError* error)) handler;
4037

4138
{{newline}}
4239
{{/operation}}

0 commit comments

Comments
 (0)