Skip to content

Nested items in responses for Objective-C #819

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
GustavTaxen opened this issue Jun 3, 2015 · 3 comments
Closed

Nested items in responses for Objective-C #819

GustavTaxen opened this issue Jun 3, 2015 · 3 comments

Comments

@GustavTaxen
Copy link

I'm failing to use Swagger to generate an Objective-C client that have nested items in the "200" response for a POST operation.

More specifically, my server responds to a certain POST operation with the following json data:

{
"collection_of_stuff": {
"entry_1": "some_string",
"entry_2": "another_string",
"entry_3": "yet_another_string"
}
}
I describe this in Swagger like this:

    "/foo/bar": {
        "post": {
            "tags": [
                "a_tag"
            ],
            "description": "some_description",
            "operationId": "some_id",
            "parameters": [
                {
                    "name": "a_parameter",
                    "in": "body",
                    "description": "Some parameter",
                    "required": true,
                    "schema": {
                        "$ref": "#/definitions/ParametersIn"
                    }
                }
            ],
            "responses": {
                "200": {
                    "description": "Successful request",
                    "schema": {
                        "type": "object",
                        "properties": {
                            "collection_of_stuff": {
                                "$ref": "#/definitions/Output"
                            }
                        }
                    }
                },
                "400": {
                    "description": "Bad request"
                },
                "401": {
                    "description": "Unauthorized"
                },
                "403": {
                    "description": "Forbidden"
                },
                "406": {
                    "description": "invalid Content-Type header."
                }
            }
        }
    },

...
"definitions": {
"Output": {
"type": "object",
"properties": {
"entry_1": {
"type": "string"
},
"entry_2": {
"type": "string"
},
"entry_3": {
"type": "string"
}
}
}
}

Both the online editor and codegen seems to accept this definition. But the generated Objective-C code looks like this:

// primitive response
        // primitive response type
return [client stringWithCompletionBlock: requestUrl 
                                          method: @"POST" 
                                     queryParams: queryParams 
                                            body: bodyDictionary 
                                    headerParams: headerParams
                              requestContentType: requestContentType
                             responseContentType: responseContentType
                                 completionBlock: ^(NSString *data, NSError *error) {
                     if (error) {
                         completionBlock(nil, error);
                         return;
                     }
                    NSObject *result = data ? [[NSObject  alloc]initWithString: data] : nil;
                    completionBlock(result, nil);
                 }];

In other words, the generated code doesn't parse the response at all - it tries to initialize an anonymous NSObject with the raw json string. (Which produces a compilation error.)

@wing328
Copy link
Contributor

wing328 commented Jun 3, 2015

For codegen, inline schema is not supported at the moment. Please refer to #354 and #730 for more information.

To workaround the issue, you can avoid defining the inline schema by defining the model (object) in the definitions section

@fehguy
Copy link
Contributor

fehguy commented Oct 17, 2015

Will be resolved when 9508579 is merged to master

@fehguy
Copy link
Contributor

fehguy commented Oct 25, 2015

Nested items are supported now. Please reopen if you have any questions.

@fehguy fehguy closed this as completed Oct 25, 2015
@fehguy fehguy modified the milestone: v2.1.4 Oct 26, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants