forked from loafle/openapi-generator-original
updated 2.0 support for objc
This commit is contained in:
parent
7901d8a7c6
commit
73ad502251
@ -7,7 +7,9 @@ import java.util.*;
|
||||
|
||||
|
||||
public class CodegenOperation {
|
||||
public String path, operationId, returnType, httpMethod, returnBaseType, returnContainer;
|
||||
public Boolean hasParams, returnTypeIsPrimitive, returnSimpleType;
|
||||
public String path, operationId, returnType, httpMethod, returnBaseType, returnContainer,
|
||||
summary, notes;
|
||||
public List<Map<String, String>> consumes, produces;
|
||||
public List<CodegenParameter> allParams = new ArrayList<CodegenParameter>();
|
||||
public List<CodegenParameter> bodyParams = new ArrayList<CodegenParameter>();
|
||||
|
@ -335,6 +335,8 @@ public class DefaultCodegen {
|
||||
operationId = "fixme";
|
||||
op.path = path;
|
||||
op.operationId = operationId;
|
||||
op.summary = operation.getSummary();
|
||||
op.notes = operation.getDescription();
|
||||
|
||||
Response methodResponse = null;
|
||||
|
||||
@ -387,13 +389,23 @@ public class DefaultCodegen {
|
||||
|
||||
op.returnBaseType = innerProperty.datatype;
|
||||
}
|
||||
else
|
||||
op.returnBaseType = responseModel.datatype;
|
||||
else {
|
||||
op.returnBaseType = responseModel.complexType;
|
||||
|
||||
}
|
||||
|
||||
op.returnType = responseModel.datatype;
|
||||
if(responseModel.isContainer)
|
||||
op.returnContainer = responseModel.complexType;
|
||||
else
|
||||
op.returnSimpleType = true;
|
||||
if (languageSpecificPrimitives().contains(op.returnBaseType) || op.returnBaseType == null)
|
||||
op.returnTypeIsPrimitive = true;
|
||||
}
|
||||
|
||||
if(op.returnBaseType == null) {
|
||||
op.returnTypeIsPrimitive = true;
|
||||
op.returnSimpleType = true;
|
||||
}
|
||||
|
||||
List<Parameter> parameters = operation.getParameters();
|
||||
@ -477,6 +489,8 @@ public class DefaultCodegen {
|
||||
// legacy support
|
||||
op.nickname = operationId;
|
||||
|
||||
if(op.allParams.size() > 0)
|
||||
op.hasParams = true;
|
||||
return op;
|
||||
}
|
||||
}
|
@ -76,7 +76,6 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
public String getSwaggerType(Property p) {
|
||||
String swaggerType = super.getSwaggerType(p);
|
||||
String type = null;
|
||||
System.out.println("checking type mapping for " + swaggerType);
|
||||
if(typeMapping.containsKey(swaggerType)) {
|
||||
type = typeMapping.get(swaggerType);
|
||||
if(languageSpecificPrimitives.contains(type) && !foundationClasses.contains(type))
|
||||
|
@ -69,17 +69,15 @@ static NSString * basePath = @"{{basePath}}";
|
||||
NSString* requestContentType = @"application/json";
|
||||
NSString* responseContentType = @"application/json";
|
||||
|
||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||
{{#queryParams}}if({{paramName}} != nil)
|
||||
queryParams[@"{{baseName}}"] = {{paramName}};
|
||||
{{/queryParams}}
|
||||
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
|
||||
queryParams[@"{{baseName}}"] = {{paramName}};{{/queryParams}}
|
||||
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
|
||||
{{#headerParams}}if({{paramName}} != nil)
|
||||
headerParams[@"{{baseName}}"] = {{paramName}};
|
||||
{{/headerParams}}
|
||||
headerParams[@"{{baseName}}"] = {{paramName}};{{/headerParams}}
|
||||
|
||||
id bodyDictionary = nil;
|
||||
{{#bodyParam}}
|
||||
{{#bodyParam}}
|
||||
if(body != nil && [body isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * objs = [[NSMutableArray alloc] init];
|
||||
for (id dict in (NSArray*)body) {
|
||||
@ -170,22 +168,21 @@ static NSString * basePath = @"{{basePath}}";
|
||||
{{#returnSimpleType}}
|
||||
{{#returnTypeIsPrimitive}}
|
||||
{{#returnBaseType}}
|
||||
return [client stringWithCompletionBlock:requestUrl
|
||||
method:@"{{httpMethod}}"
|
||||
queryParams:queryParams
|
||||
body:bodyDictionary
|
||||
headerParams:headerParams
|
||||
requestContentType: requestContentType
|
||||
responseContentType: responseContentType
|
||||
completionBlock:^(NSString *data, NSError *error) {
|
||||
if (error) {
|
||||
completionBlock(nil, error);
|
||||
return;
|
||||
}
|
||||
{{returnBaseType}} *result = data ? [[{{#instantiationType}}NSClassFromString(@"{{{instantiationType}}}") {{/instantiationType}}{{^instantiationType}}{{{returnBaseType}}} {{/instantiationType}} alloc]initWithString: data] : nil;
|
||||
completionBlock(result, nil);
|
||||
}];
|
||||
{{/returnBaseType}}
|
||||
return [client stringWithCompletionBlock: requestUrl
|
||||
method: @"{{httpMethod}}"
|
||||
queryParams: queryParams
|
||||
body: bodyDictionary
|
||||
headerParams: headerParams
|
||||
requestContentType: requestContentType
|
||||
responseContentType: responseContentType
|
||||
completionBlock: ^(NSString *data, NSError *error) {
|
||||
if (error) {
|
||||
completionBlock(nil, error);
|
||||
return;
|
||||
}
|
||||
{{returnBaseType}} *result = data ? [[{{#instantiationType}}NSClassFromString(@"{{{instantiationType}}}") {{/instantiationType}}{{^instantiationType}}{{{returnBaseType}}} {{/instantiationType}} alloc]initWithString: data] : nil;
|
||||
completionBlock(result, nil);
|
||||
}];{{/returnBaseType}}
|
||||
{{^returnBaseType}}
|
||||
return [client stringWithCompletionBlock:requestUrl
|
||||
method:@"{{httpMethod}}"
|
||||
@ -201,10 +198,8 @@ static NSString * basePath = @"{{basePath}}";
|
||||
}
|
||||
completionBlock(nil);
|
||||
}];
|
||||
{{/returnBaseType}}
|
||||
{{/returnTypeIsPrimitive}}
|
||||
{{#returnBaseType}}
|
||||
{{^returnTypeIsPrimitive}}
|
||||
{{/returnBaseType}}{{/returnTypeIsPrimitive}}
|
||||
{{#returnBaseType}}{{^returnTypeIsPrimitive}}
|
||||
return [client dictionary:requestUrl
|
||||
method:@"{{httpMethod}}"
|
||||
queryParams:queryParams
|
||||
@ -226,9 +221,7 @@ static NSString * basePath = @"{{basePath}}";
|
||||
{{#returnBaseType}}completionBlock(result , nil);{{/returnBaseType}}
|
||||
{{/returnBaseType}}
|
||||
}];
|
||||
{{/returnTypeIsPrimitive}}
|
||||
{{/returnBaseType}}
|
||||
{{/returnSimpleType}}
|
||||
{{/returnTypeIsPrimitive}}{{/returnBaseType}}{{/returnSimpleType}}
|
||||
{{newline}}
|
||||
}
|
||||
|
||||
|
@ -14,22 +14,15 @@
|
||||
{{#operation}}
|
||||
/**
|
||||
|
||||
{{{summary}}}
|
||||
{{#notes}}
|
||||
{{{notes}}}
|
||||
{{/notes}}
|
||||
{{#summary}}{{{summary}}}{{/summary}}
|
||||
{{#notes}}{{{notes}}}{{/notes}}
|
||||
|
||||
{{#allParams}}
|
||||
@param {{paramName}} {{description}}
|
||||
{{#allParams}}@param {{paramName}} {{description}}
|
||||
{{/allParams}}
|
||||
|
||||
*/
|
||||
-(NSNumber*) {{nickname}}WithCompletionBlock {{^allParams}}:{{/allParams}}{{#allParams}}{{#secondaryParam}} {{paramName}}{{/secondaryParam}}:({{{dataType}}}) {{paramName}} {{#hasMore}}{{newline}} {{/hasMore}}{{/allParams}}
|
||||
{{#returnBaseType}}{{#hasParams}}{{newline}} completionHandler: {{/hasParams}}(void (^)({{returnType}} output, NSError* error))completionBlock;{{/returnBaseType}}
|
||||
{{^returnBaseType}}{{#hasParams}}{{newline}} completionHandler: {{/hasParams}}(void (^)(NSError* error))completionBlock;{{/returnBaseType}}
|
||||
|
||||
{{newline}}
|
||||
-(NSNumber*) {{nickname}}WithCompletionBlock {{^allParams}}:{{/allParams}}{{#allParams}}{{#secondaryParam}} {{paramName}}{{/secondaryParam}}: ({{{dataType}}}) {{paramName}}{{/allParams}}
|
||||
{{#returnBaseType}}{{#hasParams}} completionHandler: {{/hasParams}}(void (^)({{returnType}} output, NSError* error))completionBlock;{{/returnBaseType}}
|
||||
{{^returnBaseType}}{{#hasParams}} completionHandler: {{/hasParams}}(void (^)(NSError* error))completionBlock;{{/returnBaseType}}
|
||||
{{/operation}}
|
||||
|
||||
{{/operations}}
|
||||
@end
|
Loading…
x
Reference in New Issue
Block a user