Nswag: Possible bug: Incorrect mapping IActionResult -> FileResponse

Created on 2 Nov 2017  路  6Comments  路  Source: RicoSuter/NSwag

Hi,
I have a ASP.NET Core Web API action as follows:
````
[HttpPost("RemoveAccessRights")]
public async Task RemoveAccessRights([FromBody]List input)
{
// Get vbc workspace
var workspace = GetWorkspace();

        foreach (var record in input)
        {
            await Task.Run(() => RemoveUserAccessRights(record, workspace));
        }

        return Ok();
    }

The swagger json is:
"/api/Users/RemoveAccessRights": {
"post": {
"tags": [
"Users"
],
"operationId": "Users_RemoveAccessRights",
"parameters": [
{
"name": "input",
"in": "body",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/CreateOrUpdateUserAccessDto"
}
},
"x-nullable": true
}
],
"responses": {
"200": {
"description": "",
"schema": {
"type": "file"
},
"x-nullable": true
}
}
}
},
The client-side generation is:
public removeAccessRights(input: CreateOrUpdateUserAccessDto[]): Observable {}
````
How come IActionResult is transformed to FileResponse?

Thanks
Bilal

Most helpful comment

Add

[SwaggerResponse(typeof(void))]

All 6 comments

NSwag uses reflection to determine the response type - if the return type is IActionResult it does not know what the response type is and will fallback to file which is the most flexible type...

See https://github.com/RSuter/NSwag/wiki/WebApiToSwaggerGenerator#specify-the-response-type-of-an-action

So what will be the best workaround to return for example nothing?

Add

[SwaggerResponse(typeof(void))]

Or use the signature

    public async Task RemoveAccessRights([FromBody]List<CreateOrUpdateUserAccessDto> input)

Thanks @RSuter :)

Thank you for logging this issue. It saved me a ton of time.

Was this page helpful?
0 / 5 - 0 ratings