Skip to content

Commit 9f3c34d

Browse files
committed
Merge pull request #2267 from wing328/objc_model_prefix
[ObjC] add prefix and suffix support to ObjC models
2 parents f3a1f82 + 17a93dd commit 9f3c34d

File tree

7 files changed

+154
-54
lines changed

7 files changed

+154
-54
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public ObjcClientCodegen() {
9898
// local variable names in API methods (endpoints)
9999
"resourcePath", "pathParams", "queryParams", "headerParams",
100100
"responseContentType", "requestContentType", "authSettings",
101-
"formParams", "files", "bodyParam",
101+
"formParams", "localVarFiles", "bodyParam",
102102
// objc reserved words
103103
"auto", "else", "long", "switch",
104104
"break", "enum", "register", "typedef",
@@ -343,7 +343,15 @@ public String toModelNameWithoutReservedWordCheck(String type) {
343343
}
344344
// custom classes
345345
else {
346-
return classPrefix + camelize(type);
346+
if (!StringUtils.isEmpty(modelNameSuffix)) { // set model suffix
347+
type = type + "_" + modelNameSuffix;
348+
}
349+
350+
if (!StringUtils.isEmpty(modelNamePrefix)) { // set model prefix
351+
type = modelNamePrefix + "_" + type;
352+
}
353+
354+
return classPrefix + camelize(type); // add class prefix
347355
}
348356
}
349357

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ static {{classname}}* singletonAPI = nil;
141141

142142
id bodyParam = nil;
143143
NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init];
144-
NSMutableDictionary *files = [[NSMutableDictionary alloc] init];
144+
NSMutableDictionary *localVarFiles = [[NSMutableDictionary alloc] init];
145145
{{#bodyParam}}
146146
bodyParam = {{paramName}};
147147
{{/bodyParam}}{{^bodyParam}}
@@ -151,7 +151,7 @@ static {{classname}}* singletonAPI = nil;
151151
formParams[@"{{baseName}}"] = {{paramName}};
152152
}
153153
{{/notFile}}{{#isFile}}
154-
files[@"{{paramName}}"] = {{paramName}};
154+
localVarFiles[@"{{paramName}}"] = {{paramName}};
155155
{{/isFile}}
156156
{{/formParams}}
157157
{{/bodyParam}}
@@ -168,7 +168,7 @@ static {{classname}}* singletonAPI = nil;
168168
pathParams: pathParams
169169
queryParams: queryParams
170170
formParams: formParams
171-
files: files
171+
files: localVarFiles
172172
body: bodyParam
173173
headerParams: headerParams
174174
authSettings: authSettings

samples/client/petstore/objc/SwaggerClient/SWGPetApi.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@
4848
///
4949
///
5050
/// Finds Pets by status
51-
/// Multiple status values can be provided with comma seperated strings
51+
/// Multiple status values can be provided with comma separated strings
5252
///
53-
/// @param status Status values that need to be considered for filter
53+
/// @param status Status values that need to be considered for query
5454
///
5555
///
5656
/// @return NSArray<SWGPet>*

samples/client/petstore/objc/SwaggerClient/SWGPetApi.m

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ -(NSNumber*) updatePetWithBody: (SWGPet*) body
120120

121121
id bodyParam = nil;
122122
NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init];
123-
NSMutableDictionary *files = [[NSMutableDictionary alloc] init];
123+
NSMutableDictionary *localVarFiles = [[NSMutableDictionary alloc] init];
124124

125125
bodyParam = body;
126126

@@ -131,7 +131,7 @@ -(NSNumber*) updatePetWithBody: (SWGPet*) body
131131
pathParams: pathParams
132132
queryParams: queryParams
133133
formParams: formParams
134-
files: files
134+
files: localVarFiles
135135
body: bodyParam
136136
headerParams: headerParams
137137
authSettings: authSettings
@@ -195,7 +195,7 @@ -(NSNumber*) addPetWithBody: (SWGPet*) body
195195

196196
id bodyParam = nil;
197197
NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init];
198-
NSMutableDictionary *files = [[NSMutableDictionary alloc] init];
198+
NSMutableDictionary *localVarFiles = [[NSMutableDictionary alloc] init];
199199

200200
bodyParam = body;
201201

@@ -206,7 +206,7 @@ -(NSNumber*) addPetWithBody: (SWGPet*) body
206206
pathParams: pathParams
207207
queryParams: queryParams
208208
formParams: formParams
209-
files: files
209+
files: localVarFiles
210210
body: bodyParam
211211
headerParams: headerParams
212212
authSettings: authSettings
@@ -221,8 +221,8 @@ -(NSNumber*) addPetWithBody: (SWGPet*) body
221221

222222
///
223223
/// Finds Pets by status
224-
/// Multiple status values can be provided with comma seperated strings
225-
/// @param status Status values that need to be considered for filter
224+
/// Multiple status values can be provided with comma separated strings
225+
/// @param status Status values that need to be considered for query
226226
///
227227
/// @returns NSArray<SWGPet>*
228228
///
@@ -276,7 +276,7 @@ -(NSNumber*) findPetsByStatusWithStatus: (NSArray* /* NSString */) status
276276

277277
id bodyParam = nil;
278278
NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init];
279-
NSMutableDictionary *files = [[NSMutableDictionary alloc] init];
279+
NSMutableDictionary *localVarFiles = [[NSMutableDictionary alloc] init];
280280

281281

282282

@@ -287,7 +287,7 @@ -(NSNumber*) findPetsByStatusWithStatus: (NSArray* /* NSString */) status
287287
pathParams: pathParams
288288
queryParams: queryParams
289289
formParams: formParams
290-
files: files
290+
files: localVarFiles
291291
body: bodyParam
292292
headerParams: headerParams
293293
authSettings: authSettings
@@ -357,7 +357,7 @@ -(NSNumber*) findPetsByTagsWithTags: (NSArray* /* NSString */) tags
357357

358358
id bodyParam = nil;
359359
NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init];
360-
NSMutableDictionary *files = [[NSMutableDictionary alloc] init];
360+
NSMutableDictionary *localVarFiles = [[NSMutableDictionary alloc] init];
361361

362362

363363

@@ -368,7 +368,7 @@ -(NSNumber*) findPetsByTagsWithTags: (NSArray* /* NSString */) tags
368368
pathParams: pathParams
369369
queryParams: queryParams
370370
formParams: formParams
371-
files: files
371+
files: localVarFiles
372372
body: bodyParam
373373
headerParams: headerParams
374374
authSettings: authSettings
@@ -440,7 +440,7 @@ -(NSNumber*) getPetByIdWithPetId: (NSNumber*) petId
440440

441441
id bodyParam = nil;
442442
NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init];
443-
NSMutableDictionary *files = [[NSMutableDictionary alloc] init];
443+
NSMutableDictionary *localVarFiles = [[NSMutableDictionary alloc] init];
444444

445445

446446

@@ -451,7 +451,7 @@ -(NSNumber*) getPetByIdWithPetId: (NSNumber*) petId
451451
pathParams: pathParams
452452
queryParams: queryParams
453453
formParams: formParams
454-
files: files
454+
files: localVarFiles
455455
body: bodyParam
456456
headerParams: headerParams
457457
authSettings: authSettings
@@ -529,7 +529,7 @@ -(NSNumber*) updatePetWithFormWithPetId: (NSString*) petId
529529

530530
id bodyParam = nil;
531531
NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init];
532-
NSMutableDictionary *files = [[NSMutableDictionary alloc] init];
532+
NSMutableDictionary *localVarFiles = [[NSMutableDictionary alloc] init];
533533

534534

535535

@@ -552,7 +552,7 @@ -(NSNumber*) updatePetWithFormWithPetId: (NSString*) petId
552552
pathParams: pathParams
553553
queryParams: queryParams
554554
formParams: formParams
555-
files: files
555+
files: localVarFiles
556556
body: bodyParam
557557
headerParams: headerParams
558558
authSettings: authSettings
@@ -630,7 +630,7 @@ -(NSNumber*) deletePetWithPetId: (NSNumber*) petId
630630

631631
id bodyParam = nil;
632632
NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init];
633-
NSMutableDictionary *files = [[NSMutableDictionary alloc] init];
633+
NSMutableDictionary *localVarFiles = [[NSMutableDictionary alloc] init];
634634

635635

636636

@@ -641,7 +641,7 @@ -(NSNumber*) deletePetWithPetId: (NSNumber*) petId
641641
pathParams: pathParams
642642
queryParams: queryParams
643643
formParams: formParams
644-
files: files
644+
files: localVarFiles
645645
body: bodyParam
646646
headerParams: headerParams
647647
authSettings: authSettings
@@ -719,7 +719,7 @@ -(NSNumber*) uploadFileWithPetId: (NSNumber*) petId
719719

720720
id bodyParam = nil;
721721
NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init];
722-
NSMutableDictionary *files = [[NSMutableDictionary alloc] init];
722+
NSMutableDictionary *localVarFiles = [[NSMutableDictionary alloc] init];
723723

724724

725725

@@ -729,7 +729,7 @@ -(NSNumber*) uploadFileWithPetId: (NSNumber*) petId
729729

730730

731731

732-
files[@"file"] = file;
732+
localVarFiles[@"file"] = file;
733733

734734

735735

@@ -740,7 +740,7 @@ -(NSNumber*) uploadFileWithPetId: (NSNumber*) petId
740740
pathParams: pathParams
741741
queryParams: queryParams
742742
formParams: formParams
743-
files: files
743+
files: localVarFiles
744744
body: bodyParam
745745
headerParams: headerParams
746746
authSettings: authSettings
@@ -812,7 +812,7 @@ -(NSNumber*) petPetIdtestingByteArraytrueGetWithPetId: (NSNumber*) petId
812812

813813
id bodyParam = nil;
814814
NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init];
815-
NSMutableDictionary *files = [[NSMutableDictionary alloc] init];
815+
NSMutableDictionary *localVarFiles = [[NSMutableDictionary alloc] init];
816816

817817

818818

@@ -823,7 +823,7 @@ -(NSNumber*) petPetIdtestingByteArraytrueGetWithPetId: (NSNumber*) petId
823823
pathParams: pathParams
824824
queryParams: queryParams
825825
formParams: formParams
826-
files: files
826+
files: localVarFiles
827827
body: bodyParam
828828
headerParams: headerParams
829829
authSettings: authSettings
@@ -887,7 +887,7 @@ -(NSNumber*) addPetUsingByteArrayWithBody: (NSString*) body
887887

888888
id bodyParam = nil;
889889
NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init];
890-
NSMutableDictionary *files = [[NSMutableDictionary alloc] init];
890+
NSMutableDictionary *localVarFiles = [[NSMutableDictionary alloc] init];
891891

892892
bodyParam = body;
893893

@@ -898,7 +898,7 @@ -(NSNumber*) addPetUsingByteArrayWithBody: (NSString*) body
898898
pathParams: pathParams
899899
queryParams: queryParams
900900
formParams: formParams
901-
files: files
901+
files: localVarFiles
902902
body: bodyParam
903903
headerParams: headerParams
904904
authSettings: authSettings

samples/client/petstore/objc/SwaggerClient/SWGStoreApi.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@
1919
-(unsigned long) requestQueueSize;
2020
+(SWGStoreApi*) apiWithHeader:(NSString*)headerValue key:(NSString*)key;
2121
+(SWGStoreApi*) sharedAPI;
22+
///
23+
///
24+
/// Finds orders by status
25+
/// A single status value can be provided as a string
26+
///
27+
/// @param status Status value that needs to be considered for query
28+
///
29+
///
30+
/// @return NSArray<SWGOrder>*
31+
-(NSNumber*) findOrdersByStatusWithStatus: (NSString*) status
32+
completionHandler: (void (^)(NSArray<SWGOrder>* output, NSError* error)) handler;
33+
34+
2235
///
2336
///
2437
/// Returns pet inventories by status

0 commit comments

Comments
 (0)