Skip to content

Commit 89e3bcc

Browse files
committed
Adds isPrimitiveType flag to CodegenParameter.
This is required in some languages like Obj-C where there is no automatic value boxing and handling of primitive types require extra work compared to non-primitive types. Case in point: BOOL type. To assign BOOL into a dictionary, one needs to box it into an (NSValue *) instance, so to build a dictionary for sending form data, for example, you cannot do this in the template: dict["{{paramName}}"] = {{paramName}}; Because if the parameter ends up being of type BOOL, an error about boxing values will be generated: BOOL boolValue = NO; dict["boolValue"] = boolValue; ^---------------- Cannot do the assignment here. The fix is to wrap it in @() like so: BOOL boolValue = NO; dict["boolValue"] = @(boolValue); So a flag is needed in CodegenParameter so we can selectively emit the right boxing or non-boxing assignment in the templates.
1 parent e592d1b commit 89e3bcc

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/CodegenParameter.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
public class CodegenParameter {
44
public Boolean isFormParam, isQueryParam, isPathParam, isHeaderParam,
5-
isCookieParam, isBodyParam, isFile, notFile, hasMore, isContainer, secondaryParam;
5+
isCookieParam, isBodyParam, isFile, notFile, hasMore, isContainer, secondaryParam,
6+
isPrimitiveType, notPrimitiveType;
67
public String baseName, paramName, dataType, collectionFormat, description, baseType;
78
public String jsonSchema;
89

@@ -34,6 +35,8 @@ public CodegenParameter copy() {
3435
output.isBodyParam = this.isBodyParam;
3536
output.required = this.required;
3637
output.jsonSchema = this.jsonSchema;
38+
output.isPrimitiveType = this.isPrimitiveType;
39+
output.notPrimitiveType = this.notPrimitiveType;
3740

3841
return output;
3942
}

modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/DefaultCodegen.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,8 @@ public CodegenParameter fromParameter(Parameter param, Set<String> imports) {
928928
CodegenProperty model = fromProperty(qp.getName(), property);
929929
p.collectionFormat = collectionFormat;
930930
p.dataType = model.datatype;
931+
p.isPrimitiveType = languageSpecificPrimitives.contains(p.dataType);
932+
p.notPrimitiveType = !p.isPrimitiveType;
931933
p.paramName = toParamName(qp.getName());
932934

933935
if(model.complexType != null) {

0 commit comments

Comments
 (0)