Skip to content

Conversation

chakrit
Copy link
Contributor

@chakrit chakrit commented May 21, 2015

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 where needed.

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.
@chakrit
Copy link
Contributor Author

chakrit commented May 21, 2015

We have a copy of our own templates (modified from the work in #754) at the moment. I will try to add fixes to the master branch template files where applicable if I have the time.

@wing328
Copy link
Contributor

wing328 commented May 21, 2015

@chakrit please kindly submit the PR for the branch develop_2.0 instead of master

fehguy added a commit that referenced this pull request May 23, 2015
Adds isPrimitiveType flag to CodegenParameter.
@fehguy fehguy merged commit e3c1163 into swagger-api:master May 23, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants