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