mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-03 22:20:56 +00:00
Merge pull request #1644 from wing328/objc_special_word
[ObjC] escape objc special words with "var"
This commit is contained in:
commit
5bb444ba6d
@ -34,6 +34,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
protected String authorEmail = "apiteam@swagger.io";
|
protected String authorEmail = "apiteam@swagger.io";
|
||||||
protected String license = "MIT";
|
protected String license = "MIT";
|
||||||
protected String gitRepoURL = "https://github.com/swagger-api/swagger-codegen";
|
protected String gitRepoURL = "https://github.com/swagger-api/swagger-codegen";
|
||||||
|
protected String[] specialWords = {"new", "copy"};
|
||||||
|
|
||||||
public ObjcClientCodegen() {
|
public ObjcClientCodegen() {
|
||||||
super();
|
super();
|
||||||
@ -86,6 +87,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
typeMapping.put("object", "NSObject");
|
typeMapping.put("object", "NSObject");
|
||||||
typeMapping.put("file", "NSURL");
|
typeMapping.put("file", "NSURL");
|
||||||
|
|
||||||
|
|
||||||
// ref: http://www.tutorialspoint.com/objective_c/objective_c_basic_syntax.htm
|
// ref: http://www.tutorialspoint.com/objective_c/objective_c_basic_syntax.htm
|
||||||
reservedWords = new HashSet<String>(
|
reservedWords = new HashSet<String>(
|
||||||
Arrays.asList(
|
Arrays.asList(
|
||||||
@ -375,6 +377,12 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if name starting with special word, escape with '_'
|
||||||
|
for(int i =0; i < specialWords.length; i++) {
|
||||||
|
if (name.matches("(?i:^" + specialWords[i] + ".*)"))
|
||||||
|
name = escapeSpecialWord(name);
|
||||||
|
}
|
||||||
|
|
||||||
// camelize (lower first character) the variable name
|
// camelize (lower first character) the variable name
|
||||||
// e.g. `pet_id` to `petId`
|
// e.g. `pet_id` to `petId`
|
||||||
name = camelize(name, true);
|
name = camelize(name, true);
|
||||||
@ -384,6 +392,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
name = escapeReservedWord(name);
|
name = escapeReservedWord(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -397,6 +406,10 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
return "_" + name;
|
return "_" + name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String escapeSpecialWord(String name) {
|
||||||
|
return "var_" + name;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toOperationId(String operationId) {
|
public String toOperationId(String operationId) {
|
||||||
// throw exception if method name is empty
|
// throw exception if method name is empty
|
||||||
|
@ -450,7 +450,7 @@ static SWGPetApi* singletonAPI = nil;
|
|||||||
NSString *requestContentType = [SWGApiClient selectHeaderContentType:@[]];
|
NSString *requestContentType = [SWGApiClient selectHeaderContentType:@[]];
|
||||||
|
|
||||||
// Authentication setting
|
// Authentication setting
|
||||||
NSArray *authSettings = @[@"api_key", @"petstore_auth"];
|
NSArray *authSettings = @[@"api_key"];
|
||||||
|
|
||||||
id bodyParam = nil;
|
id bodyParam = nil;
|
||||||
NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary *formParams = [[NSMutableDictionary alloc] init];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user