Unable to generate array return type if both StatusCodes of OK and Accepted(or Created, NoContent) specified
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
Can you try with the latest version of AutoRest 0.14?
thanks devigned, it's able to generate right return type, although the method name generated with a different suffix from 0.9.7
@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.