gpt4 book ai didi

java - openapi-generator/maven 插件生成带有 «, » 字符的无效 java 代码

转载 作者:行者123 更新时间:2023-12-04 15:27:53 24 4
gpt4 key购买 nike

我只是将我的代码从 swagger-code generator 迁移到 open-api code generator。我正在通过 maven plugin 使用生成器.我需要它为外部 API(在我的控制之外)生成客户端,给出了使用的 swagger 文件。

我的插件设置如下:

<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>4.3.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<generateApiTests>false</generateApiTests>
<generateModelTests>false</generateModelTests>
<generateSupportingFiles>false</generateSupportingFiles>
<environmentVariables>
<supportingFiles>
ApiClient.java,Authentication.java,OAuth.java,ApiKeyAuth.java,HttpBasicAuth.java,RFC3339DateFormat.java
</supportingFiles>
</environmentVariables>
<inputSpec>${project.basedir}/src/main/resources/api-tpz.json</inputSpec>
<generatorName>java</generatorName>
<configOptions>
<library>resttemplate</library>
<dateLibrary>java8</dateLibrary>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>

为了举一个最小的例子,我将 swagger 的来源剥离为:

{
"swagger": "2.0",
"info": {
"description": "Api Documentation",
"version": "1.0",
"title": "Api Documentation",
"termsOfService": "urn:tos",
"contact": {

},
"license": {
"name": "Apache 2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0"
}
},
"securityDefinitions": {
"basicAuth": {
"type": "basic"
}
},
"security": [
{
"basicAuth": []
}
],
"host": "example.com",
"basePath": "/api",
"tags": [
],
"paths": {
},
"definitions": {
"GenericRow": {
"type": "object",
"title": "GenericRow",
"additionalProperties": {
"type": "object"
}
},
"ResultList«GenericRow»": {
"type": "object",
"properties": {
"offset": {
"type": "integer",
"format": "int64"
},
"overallCount": {
"type": "integer",
"format": "int64"
},
"results": {
"type": "array",
"items": {
"$ref": "#/definitions/GenericRow"
}
}
},
"title": "ResultList«GenericRow»"
}
}
}

虽然生成器运行良好,但代码无效

@Override
public boolean equals(java.lang.Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ResultListGenericRow resultList«GenericRow» = (ResultListGenericRow) o;
return Objects.equals(this.offset, resultList«GenericRow».offset) &&
Objects.equals(this.overallCount, resultList«GenericRow».overallCount) &&
Objects.equals(this.results, resultList«GenericRow».results);
}

resultList«GenericRow» 是错误的。

另一方面,类的名称正确生成 ResultListGenericRow 只有变量名称处理错误。

如何解决这个问题?

编辑:

我无法控制给定的规范文件。我需要生成一个有效的客户端。 swagger code gen 工作正常(只是删除了特殊字符)。迁移指南中对此没有任何提示。如何使用新生成器获得等效代码?

最佳答案

从 swagger-codegen-cli 切换到 openapi-generator-cli 时,我遇到了类似的问题。在我的例子中,像这样在 Swagger 配置中添加 forCodeGeneration 有帮助:

@Configuration
@EnableSwagger2
public class SwaggerConfig {

@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.forCodeGeneration(true);
}
}

关于java - openapi-generator/maven 插件生成带有 «, » 字符的无效 java 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61893386/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com