Java OpenAPI生成器:为下载二进制文件生成正确的方法配置文件
我有一个Swagger文件(oas2),其中有一个用于下载文件的端点。我正在使用openapi生成器(通过Maven插件)生成Java/OpenFeign客户端代码 问题在于,此特定端点转换为:Java OpenAPI生成器:为下载二进制文件生成正确的方法配置文件,java,openapi-generator,openfeign,Java,Openapi Generator,Openfeign,我有一个Swagger文件(oas2),其中有一个用于下载文件的端点。我正在使用openapi生成器(通过Maven插件)生成Java/OpenFeign客户端代码 问题在于,此特定端点转换为: @RequestLine("GET /files/{id}/content") @Headers({ "Accept: application/octet-stream", }) File downloadByIdUsingGET(@Param(&
@RequestLine("GET /files/{id}/content")
@Headers({
"Accept: application/octet-stream",
})
File downloadByIdUsingGET(@Param("id") String id);
调用时返回null
。
根据,正确的方法配置文件应为:
Response downloadByIdUsingGET(@Param("id") String id);
事实上,如果我自己编写接口,我可以使用这种方法:
Response downloadResponse = api.downloadByIdUsingGET(id);
InputStream downloadInputStream = downloadResponse.body().asInputStream();
因此,问题是:如何配置生成器以使用此端点的Response
类型
我试过:
<typeMappings>file=feign.Response</typeMappings>
这样很好用
以下是Swagger文件的相关部分:
"/files/{id}/content": {
"get": {
"produces": [
"application/octet-stream"
],
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string",
}
],
"responses": {
"200": {
"description": "Successful",
"schema": {
"type": "file"
}
}
}
}
}
PS:我还尝试扩展生成的接口,以便使用响应返回类型仅添加我自己的方法,但OpenFeign仅支持一级继承,并且生成的接口已经扩展了ApiClient.Api.PS:我还尝试扩展生成的接口,以便使用响应返回类型仅添加我自己的方法,但是OpenFeign只支持一级继承,并且生成的接口已经扩展了ApiClient.Api。
"/files/{id}/content": {
"get": {
"produces": [
"application/octet-stream"
],
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string",
}
],
"responses": {
"200": {
"description": "Successful",
"schema": {
"type": "file"
}
}
}
}
}