forked from loafle/openapi-generator-original
escape objc special word with var
This commit is contained in:
parent
a78f33581a
commit
c64f352ba6
@ -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
|
||||||
|
@ -944,6 +944,14 @@
|
|||||||
"type": "integer",
|
"type": "integer",
|
||||||
"format": "int64"
|
"format": "int64"
|
||||||
},
|
},
|
||||||
|
"CopyPassword": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int64"
|
||||||
|
},
|
||||||
|
"newPassword": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int64"
|
||||||
|
},
|
||||||
"petId": {
|
"petId": {
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"format": "int64"
|
"format": "int64"
|
||||||
|
@ -17,6 +17,10 @@
|
|||||||
|
|
||||||
@property(nonatomic) NSNumber* _id;
|
@property(nonatomic) NSNumber* _id;
|
||||||
|
|
||||||
|
@property(nonatomic) NSNumber* varCopyPassword;
|
||||||
|
|
||||||
|
@property(nonatomic) NSNumber* varNewPassword;
|
||||||
|
|
||||||
@property(nonatomic) NSNumber* petId;
|
@property(nonatomic) NSNumber* petId;
|
||||||
|
|
||||||
@property(nonatomic) NSNumber* quantity;
|
@property(nonatomic) NSNumber* quantity;
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
+ (JSONKeyMapper *)keyMapper
|
+ (JSONKeyMapper *)keyMapper
|
||||||
{
|
{
|
||||||
return [[JSONKeyMapper alloc] initWithDictionary:@{ @"id": @"_id", @"petId": @"petId", @"quantity": @"quantity", @"shipDate": @"shipDate", @"status": @"status", @"complete": @"complete" }];
|
return [[JSONKeyMapper alloc] initWithDictionary:@{ @"id": @"_id", @"CopyPassword": @"varCopyPassword", @"newPassword": @"varNewPassword", @"petId": @"petId", @"quantity": @"quantity", @"shipDate": @"shipDate", @"status": @"status", @"complete": @"complete" }];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -18,7 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
+ (BOOL)propertyIsOptional:(NSString *)propertyName
|
+ (BOOL)propertyIsOptional:(NSString *)propertyName
|
||||||
{
|
{
|
||||||
NSArray *optionalProperties = @[@"_id", @"petId", @"quantity", @"shipDate", @"status", @"complete"];
|
NSArray *optionalProperties = @[@"_id", @"varCopyPassword", @"varNewPassword", @"petId", @"quantity", @"shipDate", @"status", @"complete"];
|
||||||
|
|
||||||
if ([optionalProperties containsObject:propertyName]) {
|
if ([optionalProperties containsObject:propertyName]) {
|
||||||
return YES;
|
return YES;
|
||||||
|
@ -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