Nswag: swaggerToTypeScriptClient generates unused variable when introducing ProducesResponseType

Created on 29 Nov 2018  路  1Comment  路  Source: RicoSuter/NSwag

Adding [ProducesResponseType(200)] to the controller will generate unused variable, and cause the typescript throwing the following error:

'_responseText' is declared but its value is never read.

controller:

        [HttpPost("UpdateFileInfo")]
        [ProducesResponseType(204)]
        [ProducesResponseType(200)]
        public async Task<IActionResult> UpdateFileInfo([FromBody]FileInformation fileInfo)
        {
            if (!await _storageService.FileExist(fileInfo.Guid))
                return NoContent();

            _storageService.UpdateFileInfo(fileInfo);

            return Ok();
        }

Generatd typescript:

    protected processUpdateFileInfo(xhr: any): void | null {
        const status = xhr.status; 

        let _headers: any = {};
        if (status === 204) {
            const _responseText = xhr.responseText;  <======
            return;
        } else if (status === 200) {
            const _responseText = xhr.responseText;  <======
            return;
        } else if (status !== 200 && status !== 204) {
            const _responseText = xhr.responseText;
            return throwException("An unexpected server error occurred.", status, _responseText, _headers);
        }
        return;
    }

i am using 'JQueryPromises' template.

Any suggestions?
Thanks

NSwag.CodeGeneration.TypeScript enhancement

Most helpful comment

This has to be fixed/improved in the TypeScript templates...

>All comments

This has to be fixed/improved in the TypeScript templates...

Was this page helpful?
0 / 5 - 0 ratings