angular 如何为二进制下载指定 OpenAPI
How to specify OpenAPI for binary download in angular
我有一个下载二进制文件的方法。目前在 openapi.yaml 中有以下规范:
/processing/getZippedReports:
post:
tags:
- ProcessingRest
description: Get the reports
operationId: getZippedReports
requestBody:
description: The list of items for which to get the HTML
content:
application/json:
schema:
type: array
items:
type: string
required: true
responses:
200:
description: file with zipped reports
content:
application/octet-stream: {}
生成的 typescript-angular 代码包含对 httpClient 的调用:
return this.httpClient.post<any>(`${this.configuration.basePath}/processing/getZippedReports`,
requestBody,
{
withCredentials: this.configuration.withCredentials,
headers: headers,
observe: observe,
reportProgress: reportProgress
}
);
这样,angular似乎无法接收二进制内容。我不得不更改 httpClient,使用 post
的非类型变量签名并将 responseType: blob
添加到参数
return this.httpClient.post(`${this.configuration.basePath}/processing/getZippedReports`,
requestBody,
{
withCredentials: this.configuration.withCredentials,
headers: headers,
observe: 'response',
responseType: 'blob',
reportProgress: reportProgress
}
);
这是 Swagger codegen 中的错误/缺失功能,还是我应该更改 openapi 定义以开始工作 angular 代码?
要指示响应是二进制文件,请使用具有 type: string
和 format: binary
的架构。
content:
application/octet-stream:
schema:
type: string
format: binary
似乎有一个 x-is-file
供应商扩展,我在源代码中找到了它,但没有关于它的文档。这导致 controllerService.ts
中正确的 responseType
定义
"responses": {
"default": {
"x-is-file": true,
"description": "default response",
"content": {
"application/octet-stream": {
"schema": {
"type": "file"
}
}
}
}
},
我有一个下载二进制文件的方法。目前在 openapi.yaml 中有以下规范:
/processing/getZippedReports:
post:
tags:
- ProcessingRest
description: Get the reports
operationId: getZippedReports
requestBody:
description: The list of items for which to get the HTML
content:
application/json:
schema:
type: array
items:
type: string
required: true
responses:
200:
description: file with zipped reports
content:
application/octet-stream: {}
生成的 typescript-angular 代码包含对 httpClient 的调用:
return this.httpClient.post<any>(`${this.configuration.basePath}/processing/getZippedReports`,
requestBody,
{
withCredentials: this.configuration.withCredentials,
headers: headers,
observe: observe,
reportProgress: reportProgress
}
);
这样,angular似乎无法接收二进制内容。我不得不更改 httpClient,使用 post
的非类型变量签名并将 responseType: blob
添加到参数
return this.httpClient.post(`${this.configuration.basePath}/processing/getZippedReports`,
requestBody,
{
withCredentials: this.configuration.withCredentials,
headers: headers,
observe: 'response',
responseType: 'blob',
reportProgress: reportProgress
}
);
这是 Swagger codegen 中的错误/缺失功能,还是我应该更改 openapi 定义以开始工作 angular 代码?
要指示响应是二进制文件,请使用具有 type: string
和 format: binary
的架构。
content:
application/octet-stream:
schema:
type: string
format: binary
似乎有一个 x-is-file
供应商扩展,我在源代码中找到了它,但没有关于它的文档。这导致 controllerService.ts
responseType
定义
"responses": {
"default": {
"x-is-file": true,
"description": "default response",
"content": {
"application/octet-stream": {
"schema": {
"type": "file"
}
}
}
}
},