如何解决Open API Maven插件:如何生成文件上传代码
我无法为文件上传生成开放式api生成的Feign客户端。
这是我试图用来上传文件数组的开放api requestBodies 组件的片段
requestBodies:
FilesRequestBody:
description: Array of files
content:
multipart/form-data:
schema:
type: object
properties:
files:
type: array
items:
type: file
我的pom文件包含以下插件设置
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>4.2.3</version>
<executions>
<execution>
<id>generate-feign-client</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.build.directory}/contract/api.yaml</inputSpec>
<language>java</language>
<output>${project.build.directory}/generated-sources</output>
<library>feign</library>
<typeMappings>
<mapping>file=File</mapping>
</typeMappings>
</configuration>
</execution>
请注意 typeMappings 配置-这不起作用。
理想情况下,我想要一个生成的Feign客户程序,它看起来像..
import feign.Param;
import feign.RequestLine;
import java.io.File;
public interface ImagesApi {
@RequestLine("POST /api/images")
@Headers({
"Content-Type: multipart/form-data","Accept: application/json"
})
List<Image> uploadImages(@Param("config") List<File> files);
}
但是,这是生成的,显然不会编译
@RequestLine("POST /api/images")
@Headers({
"Content-Type: multipart/form-data","Accept: application/json",})
List<Image> uploadImages(UNKNOWN_BASE_TYPE UNKNOWN_BASE_TYPE);
关于如何使Maven插件使用java.io.File之类的Java类型的任何想法?
解决方法
似乎openapi生成器中存在错误。它无法处理
$ref '#/components/requestBodies/FilesRequestBody'
因此,要使其正常运行,请不要使用组件引用。内联请求正文
/api/images:
post:
tags:
- image
summary: uploadImage
operationId: uploadImage
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
file_list:
type: array
items:
type: string
format: binary
responses:
"201":
$ref: '#/components/responses/ImagesResponse'
default:
$ref: '#/components/responses/ErrorResponse'
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。