1

I have a problem. I am using asp.net core 3 web api. The Angular 8 app client is generated with nSwag version 13.2.1.0. The specificatio is generated Swashbuckle.AspNetCore 5.

The result I get is:

**
     * @param body (optional) 
     * @return Success
     */
    seller(body: RegisterSellerRequest | undefined): Observable<TokenResponse> {
        let url_ = this.baseUrl + "/api/register/seller";
        url_ = url_.replace(/[?&]$/, "");

        const content_ = JSON.stringify(body);

        let options_: any = {
            body: content_,
            observe: "response",
            responseType: "blob",
            headers: new HttpHeaders({
                "Content-Type": "application/json-patch+json",
                "Accept": "application/json"
            })
        };

As you can see the responseType: "blob" is generated, and that's not good for our angular app's interceptor. Is there a way to set response to be application/json?! In my controllers I set the swagger attributes like this:

[ApiExplorerSettings(GroupName = Constatns.PublicSwaggerGroup)]
[SwaggerOperation(OperationId = "registerSeller")]
[HttpPost("api/register/seller")]
[ValidateModel]
[AllowAnonymous]
[ProducesResponseType((int)HttpResponseType.OK, Type = typeof(TokenResponse))]
[ProducesResponseType((int)HttpResponseType.BadRequest)]
[Produces("application/json")]
public async Task<TokenResponse> RegisterSeller([FromBody] RegisterSellerRequest data)
{}
Wasyster
  • 2,279
  • 4
  • 26
  • 58

1 Answers1

1

I think its currently no simple way to change that. Its the simplest way to load everything as blob and then transform it to json or binary depending the response type. Changing that would mean that the generator templates get much more complicated.

Rico Suter
  • 11,548
  • 6
  • 67
  • 93
  • I'm running into this problem again but when trying to use `rel="preload"` to preload a response but unfortunately that yields `A preload for 'https://....' is found, but is not used because the new request loads the content as a blob.` I guess I'll have to just manually do a fetch? – Simon_Weaver Aug 20 '22 at 06:59