我有个问题。我正在使用 asp.net core 3 web api。Angular 8 应用程序客户端是使用 nSwag 版本 13.2.1.0 生成的。生成的规范是 Swashbuckle.AspNetCore 5。
我得到的结果是:
**
* @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"
})
};
如您所见,生成了 responseType: "blob",这对我们的 Angular 应用程序的拦截器不利。有没有办法将响应设置为 application/json?!在我的控制器中,我设置了这样的招摇属性:
[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)
{}