[英]Open API Maven Plugin - Generate only specifc API model classes
[英]Open API Maven Plugin: how to generate code for File upload
我無法為文件上傳生成開放 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 Generator v6.0.0 版本中得到修復: https ://github.com/OpenAPITools/openapi-generator/releases/tag/v6.0.0。 請試一試。
似乎 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'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.