NSwagStudio deserializing error when return type is string

517 Views Asked by At

I am experiencing the following error: NSwagStudio generates a typescript client which is trying to deserializing json when api return type is plain string. I am using .netCore 2.2 and NSwagStudio 13.16.1 The client generated is:

  if (status === 400) {
        return blobToText(responseBlob).pipe(_observableMergeMap(_responseText => {
        let result400: any = null;
        result400 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as string;
        return throwException("A server side error occurred.", status, _responseText, _headers, result400);
        }));

while the API has the following decorator:

        [ProducesResponseType(typeof(string),StatusCodes.Status400BadRequest)]

As you can see, the client is trying to parse the _responseText, which causes the error. The _responseText is a plain string.

How can i solve this problem?

1

There are 1 best solutions below

0
M.G.M. On

I think it's a Front End problem. Please, don't minimize.

if (status === 400) {
    return blobToText(responseBlob).pipe(_observableMergeMap(_responseText => {
        let result400: any = null;
        result400 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as string;
        return throwException("A server side error occurred.", status, _responseText, _headers, 
    }));
}