autorest icon indicating copy to clipboard operation
autorest copied to clipboard

Unable to generate array return type if both StatusCodes of OK and Accepted(or Created, NoContent) specified

Open hotants opened this issue 10 years ago • 3 comments

Hi guys, Could I get some help or clarified on what I have faced? Thanks I have a Json file, which has 200(ok) and 202(accepted) status code specified, which the return type is an array of "Person". When I used autorest 0.9.7 to generate code, it generated wrong code as below(return type is object, instead an array of Person). If I remove 202 section, the return type will be generated correctly.

{
    "swagger": "2.0",
    "info": {
        "version": "v1",
        "title": "My Sample WebAPIs"
    },
    "host": "localhost:19000",
    "schemes": ["http"],
    "paths": {
        "/api/persons/create": {
            "post": {
                "tags": ["PersonApi"],
                "summary": "Create Persons",
                "operationId": "PersonApi_CreatePersons",
                "consumes": ["application/json",
                "text/json",
                "application/xml",
                "text/xml",
                "application/x-www-form-urlencoded"],
                "produces": ["application/json",
                "text/json",
                "application/xml",
                "text/xml"],
                "parameters": [{
                    "name": "personsCreateRequest",
                    "in": "body",
                    "required": true,
                    "schema": {
                        "$ref": "#/definitions/WebApiPersonsCreateRequest"
                    }
                }],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "array",
                            "items": {
                                "$ref": "#/definitions/Person"
                            }
                        }
                    },
                    "202": {
                        "description": "Accept",
                        "schema": {
                            "type": "array",
                            "items": {
                                "$ref": "#/definitions/Person"
                            }
                        }
                    },
                    "403": {
                        "description": "Forbidden"
                    },
                    "401": {
                        "description": "Unauthorized Request"
                    },
                    "500": {
                        "description": "Other Error"
                    }
                },
                "deprecated": false
            }
        }
    },
    "definitions": {
        "WebApiPersonsCreateRequest": {
            "type": "object",
            "properties": {
                "Names": {
                    "type": "array",
                    "items": {
                        "type": "string"
                    }
                }
            }
        },
        "Person": {
            "type": "object",
            "properties": {
                "Name": {
                    "type": "string"
                },
                "Description": {
                    "type": "string"
                }
            }
        }
    }
}

The code generated has the wrong return type HttpOperationResponse<object>, instead of "HttpOperationResponse<IList<Person>>": public async Task<HttpOperationResponse<object>> CreatePersonsWithOperationResponseAsync(WebApiPersonsCreateRequest personsCreateRequest, CancellationToken cancellationToken = default(System.Threading.CancellationToken)) Any suggestion? Thanks

hotants avatar Feb 29 '16 09:02 hotants

Can you try with the latest version of AutoRest 0.14?

devigned avatar Feb 29 '16 18:02 devigned

thanks devigned, it's able to generate right return type, although the method name generated with a different suffix from 0.9.7

hotants avatar Mar 01 '16 02:03 hotants

@hotants I believe that is expected. There have been quite a bit of change since 0.9.7.

I'm going to close this as I think the original issue is solved.

azuresdkci avatar Mar 02 '16 00:03 azuresdkci