Java Swagger codegen生成重复的变量
我正在尝试从包含Java Swagger codegen生成重复的变量,java,http,yaml,swagger,swagger-codegen,Java,Http,Yaml,Swagger,Swagger Codegen,我正在尝试从包含 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 i
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>
我尝试了不同版本的插件(从2.3.0到最新版本),在克服了许多其他问题后,我总是这样结束 在OpenAPI 2.0中,
接受
和内容类型
标题应该使用消费
和产生
而不是参数来定义。在OpenAPI 3.0中,这些头被定义为请求/响应媒体类型
按如下方式更改操作定义:
swagger:'2.0'
路径:
/傅:
职位:
消耗:
-应用程序/json
生产:
-应用程序/json
...
或者,如果您使用OpenAPI 3.0:
openapi:3.0.0
路径:
/傅:
职位:
请求主体:
内容:
application/json:#有点晚了,但我在使用第三方API时遇到了同样的问题,这是搜索中出现的第一个问题。openapi yaml在我的案例中似乎是有效的,因为它是第三方的,所以改变它是不可行的。我必须使用localVariablePrefix(完全拼写变量)
因此,要修改pom.xml,请执行以下操作:
<configOptions>
<dateLibrary>joda</dateLibrary>
<localVariablePrefix>localVar</localVariablePrefix>
</configOptions>
...
乔达
局部变量
...
这解释了很多,可惜这不是我的API。希望,一旦我联系到它的开发人员,他会修复…答案中缺少的一些细节,这会有所帮助<代码>配置选项
是配置
的子项。
<configOptions>
<dateLibrary>joda</dateLibrary>
<localVariablePrefix>localVar</localVariablePrefix>
</configOptions>
...