Skip to content
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 @@ -745,6 +745,8 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
op.isMapContainer = Boolean.TRUE;
else if ("list".equalsIgnoreCase(cm.containerType))
op.isListContainer = Boolean.TRUE;
else if ("array".equalsIgnoreCase(cm.containerType))
op.isListContainer = Boolean.TRUE;
}
else
op.returnSimpleType = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public ObjcClientCodegen() {
"NSObject",
"NSArray",
"NSNumber",
"NSDate",
"NSDictionary",
"NSMutableArray",
"NSMutableDictionary")
Expand All @@ -57,7 +56,6 @@ public ObjcClientCodegen() {
Arrays.asList(
"NSNumber",
"NSString",
"NSDate",
"NSObject",
"bool")
);
Expand All @@ -72,8 +70,9 @@ public ObjcClientCodegen() {

typeMapping = new HashMap<String, String>();
typeMapping.put("enum", "NSString");
typeMapping.put("Date", "NSDate");
typeMapping.put("DateTime", "NSDate");
typeMapping.put("Date", "SWGDate");
typeMapping.put("DateTime", "SWGDate");
// typeMapping.put("Date", "SWGDate");
typeMapping.put("boolean", "NSNumber");
typeMapping.put("string", "NSString");
typeMapping.put("integer", "NSNumber");
Expand All @@ -88,13 +87,13 @@ public ObjcClientCodegen() {
typeMapping.put("object", "NSObject");

importMapping = new HashMap<String, String> ();
importMapping.put("Date", "SWGDate");

foundationClasses = new HashSet<String> (
Arrays.asList(
"NSNumber",
"NSObject",
"NSString",
"NSDate",
"NSDictionary")
);

Expand Down Expand Up @@ -152,45 +151,11 @@ public String getSwaggerType(Property p) {

@Override
public String getTypeDeclaration(Property p) {
if (p instanceof ArrayProperty) {
ArrayProperty ap = (ArrayProperty) p;
Property inner = ap.getItems();
String innerType = getSwaggerType(inner);

// In this codition, type of property p is array of primitive,
// return container type with pointer, e.g. `NSArray*'
if (languageSpecificPrimitives.contains(innerType))
return getSwaggerType(p) + "*";

// In this codition, type of property p is array of model,
// return container type combine inner type with pointer, e.g. `NSArray<SWGTag>*'
String innerTypeDeclaration = getTypeDeclaration(inner);

if (innerTypeDeclaration.endsWith("*"))
innerTypeDeclaration = innerTypeDeclaration.substring(0, innerTypeDeclaration.length() - 1);

return getSwaggerType(p) + "<" + innerTypeDeclaration + ">*";
}
else {
String swaggerType = getSwaggerType(p);

// In this codition, type of p is objective-c primitive type, e.g. `NSSNumber',
// return type of p with pointer, e.g. `NSNumber*'
if (languageSpecificPrimitives.contains(swaggerType) &&
foundationClasses.contains(swaggerType)) {
return swaggerType + "*";
}
// In this codition, type of p is c primitive type, e.g. `bool',
// return type of p, e.g. `bool'
else if (languageSpecificPrimitives.contains(swaggerType)) {
return swaggerType;
}
// In this codition, type of p is objective-c object type, e.g. `SWGPet',
// return type of p with pointer, e.g. `'
else {
return swaggerType + "*";
}
}
String swaggerType = getSwaggerType(p);
if(languageSpecificPrimitives.contains(swaggerType) && !foundationClasses.contains(swaggerType))
return toModelName(swaggerType);
else
return swaggerType + "*";
}

@Override
Expand Down
34 changes: 28 additions & 6 deletions modules/swagger-codegen/src/main/resources/objc/api-body.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,25 @@ static NSString * basePath = @"{{basePath}}";
}
{{/bodyParam}}
{{^bodyParam}}
bodyDictionary = [[NSMutableArray alloc] init];

NSMutableDictionary * formParams = [[NSMutableDictionary alloc]init];

{{#formParams}}{{#notFile}}
{{#formParams}}
{{#notFile}}
formParams[@"{{paramName}}"] = {{paramName}};
{{/notFile}}{{#isFile}}
requestContentType = @"multipart/form-data";
if(bodyDictionary == nil) {
bodyDictionary = [[NSMutableArray alloc] init];
}
[bodyDictionary addObject:{{paramName}}];
{{paramName}}.paramName = @"{{baseName}}";
{{/isFile}}{{/formParams}}
{{/isFile}}
if(bodyDictionary == nil) {
bodyDictionary = [[NSMutableArray alloc] init];
}
[bodyDictionary addObject:formParams];
{{/formParams}}
{{/bodyParam}}

{{#requiredParamCount}}
Expand All @@ -134,11 +141,26 @@ static NSString * basePath = @"{{basePath}}";

SWGApiClient* client = [SWGApiClient sharedClientFromPool:basePath];

{{#returnContainer}}{{>apiBodyResponseWithContainer}}{{/returnContainer}}
{{#returnContainer}}
// response is in a container
{{>apiBodyResponseWithContainer}}{{/returnContainer}}

{{#returnSimpleType}}
{{#returnTypeIsPrimitive}}{{>apiPrimitiveResponse}}{{/returnTypeIsPrimitive}}
{{#returnBaseType}}{{>apiNonPrimitiveResponse}}{{/returnBaseType}}
// non container response

{{#returnTypeIsPrimitive}}
// primitive response
{{>apiPrimitiveResponse}}{{/returnTypeIsPrimitive}}

{{#returnBaseType}}
// complex response
{{>apiNonPrimitiveResponse}}{{/returnBaseType}}
{{/returnSimpleType}}

{{^returnSimpleType}}{{^returnContainer}}
// it's void
{{>voidResponse}}
{{/returnContainer}}{{/returnSimpleType}}
}

{{/operation}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@
{{^returnBaseType}}completionBlock(error);{{/returnBaseType}}
return;
}
{{#returnBaseType}}
{{returnBaseType}} *result = nil;
{{#returnType}}{{returnType}} result = nil;
if (data) {
result = [[{{#instantiationType}}NSClassFromString(@"{{{instantiationType}}}") {{/instantiationType}}{{^instantiationType}}{{{returnBaseType}}} {{/instantiationType}} alloc]initWithValues: data];
result = [[{{#instantiationType}}NSClassFromString(@"{{{instantiationType}}}") {{/instantiationType}}{{^instantiationType}}{{{returnBaseType}}} {{/instantiationType}} alloc] {{#returnContainer}}{{#isMapContainer}}initWithDictionary{{/isMapContainer}}{{#isListContainer}}initWithValues{{/isListContainer}}{{/returnContainer}}{{^returnContainer}}initWithValues {{/returnContainer}}: data];
}
{{#returnBaseType}}completionBlock(result , nil);{{/returnBaseType}}
{{/returnBaseType}}
{{#returnType}}completionBlock(result , nil);{{/returnType}}
{{/returnType}}
}];
{{/returnTypeIsPrimitive}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
return [client stringWithCompletionBlock: requestUrl
method: @"{{httpMethod}}"
queryParams: queryParams
body: bodyDictionary
headerParams: headerParams
requestContentType: requestContentType
responseContentType: responseContentType
completionBlock: ^(NSString *data, NSError *error) {
if (error) {
completionBlock(error);
return;
}
completionBlock(nil);
}];
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ - (void)viewDidLoad

SWGPetApi * api = [[SWGPetApi alloc] init];

// [api getPetByIdWithCompletionBlock:@10 completionHandler:^(SWGPet *output, NSError *error) {
// NSLog(@"%@", [output asDictionary]);
// [output set_id:@101];
// [api addPetWithCompletionBlock:output completionHandler:^(NSError *error) {
// NSLog(@"Done!");
// }];

// load data into file
// }];
[api getPetByIdWithCompletionBlock:@10 completionHandler:^(SWGPet *output, NSError *error) {
NSLog(@"%@", [output asDictionary]);
[output set_id:@101];
[api addPetWithCompletionBlock:output completionHandler:^(NSError *error) {
NSLog(@"Done!");
}];

// load data into file
}];
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"test-1" ofType:@"png"];
NSData *myData = [NSData dataWithContentsOfFile:filePath];

Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/objc/Podfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
platform :ios, '6.0'
xcodeproj 'swaggerClient/swaggerClient.xcodeproj'
xcodeproj 'PetstoreClient/PetstoreClient.xcodeproj'
pod 'AFNetworking', '~> 2.1'
2 changes: 1 addition & 1 deletion samples/client/petstore/objc/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ DEPENDENCIES:
SPEC CHECKSUMS:
AFNetworking: 8bee59492a6ff15d69130efa4d0dc67e0094a52a

COCOAPODS: 0.35.0
COCOAPODS: 0.36.0
Loading