【发布时间】:2020-06-15 18:27:56
【问题描述】:
我正在尝试从包含的 yaml 生成客户端
acceptParam:
name: Accept
type: string
required: true
in: header
description: Accepted Content-type. Should be set to application/json
contentTypeParam:
name: Content-Type
type: string
required: true
in: header
description: Request Content-type. Should be set to application/json
这意味着,accept 和 contentType 将出现在生成的方法签名中。
最重要的是,我已经配置了这样的插件
<plugin>
<groupId>io.swagger.codegen.v3</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>3.0.18</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/swagger.yaml</inputSpec>
<language>java</language>
<configOptions>
<dateLibrary>joda</dateLibrary>
<localVarPrefix>localVar</localVarPrefix>
</configOptions>
<library>resttemplate</library>
<output>${project.build.directory}/generated-sources</output>
<modelPackage>com.example.client.model</modelPackage>
<apiPackage>com.example.client.api</apiPackage>
<generateApiTests>false</generateApiTests>
<generateModelTests>false</generateModelTests>
</configuration>
</execution>
</executions>
</plugin>
还是在mvn clean install 之后
我来了
错误:(130,31) java: 变量accept已在方法中定义
并且生成的代码包含
public Response authorize(Request body, String accept, ...) {
....
final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
....
}
我尝试了不同版本的插件(从 2.3.0 到最新版本),在克服了许多其他问题之后,我总是这样结束。
【问题讨论】:
标签: java http yaml swagger swagger-codegen