[Bug]: String and Boolean and Int properties are being turned into Objects in OpenAPI 3.1.0
评估
调研方向
从 Maven 插件配置、OpenAPI 3.1 输入 JSON 以及运行 mvn clean generate-sources 后生成的 Doctor.java 开始。跟踪警告 "String to be sanitized is null. Default to Object",并将生成的属性类型与 schema 进行比较;当 string、boolean 和 integer 属性生成的 Java 类型与之匹配,而不是 Object 时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
This is an issue specifically with OpenAPI Version 3.1.0. I am not having this issue with OpenAPI Version 3.0.X. My current workaround is to use OpenAPI 3.0.1.
I am using the Swagger Codegen Maven Plugin V3, version 3.0.71. I am using Java 21, Spring Boot 3.5.8. In my pom file I have the following configuration:
<plugin>
<groupId>io.swagger.codegen.v3</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>3.0.71</version>
<executions>
<execution>
<id>my-project</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.baseUri}/src/main/resources/myproject.json</inputSpec>
<language>java</language>
<library>resttemplate</library>
<generateApis>false</generateApis>
<modelPackage>com.my.project.model</modelPackage>
<generateApiTests>false</generateApiTests>
<generateApiDocumentation>false</generateApiDocumentation>
<generateModelTests>false</generateModelTests>
<generateModelDocumentation>false</generateModelDocumentation>
<generateSupportingFiles>false</generateSupportingFiles>
<configOptions>
<interfaceOnly>true</interfaceOnly>
<dateLibrary>legacy</dateLibrary>
<hideGenerationTimestamp>true</hideGenerationTimestamp>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
I am expecting the input JSON file to generate Java files that will match the json. However, upon running mvn clean generate-sources, I keep seeing the following warning: "[WARNING] String to be sanitized is null. Default to Object"
Here is an example of one of the objects in the JSON schema:
"Doctor": {
"type": "object",
"properties": {
"code": {
"type": "string",
"format": "uuid"
},
"practiceName": {
"type": "string"
},
"address1": {
"type": "string"
},
"address2": {
"type": "string"
},
"address3": {
"type": "string"
},
"postalCode": {
"type": "string"
},
"townCity": {
"type": "string"
},
"regionCounty": {
"type": "string"
},
"country": {
"type": "string"
},
"email": {
"type": "string"
},
"phoneNumber": {
"type": "string"
},
"approved": {
"type": "boolean"
},
"externalId": {
"type": "integer",
"format": "int32"
},
"languageTag": {
"type": "string"
}
}
}
Okay, so you'd think that would product a Java object with properties matching the types described (strings, booleans). Instead, in the resulting Java object, every single property is just an Object.
public class Doctor {
@JsonProperty("code")
private Object code = null;
@JsonProperty("practiceName")
private Object practiceName = null;
@JsonProperty("address1")
private Object address1 = null;
@JsonProperty("address2")
private Object address2 = null;
@JsonProperty("address3")
private Object address3 = null;
@JsonProperty("postalCode")
private Object postalCode = null;
@JsonProperty("townCity")
private Object townCity = null;
@JsonProperty("regionCounty")
private Object regionCounty = null;
@JsonProperty("country")
private Object country = null;
@JsonProperty("email")
private Object email = null;
@JsonProperty("phoneNumber")
private Object phoneNumber = null;
@JsonProperty("approved")
private Object approved = null;
@JsonProperty("externalId")
private Object externalVetId = null;
@JsonProperty("languageTag")
private Object languageTag = null;
public Doctor code(Object code) {
this.code = code;
return this;
}
I want the properties (i.e. practiceName, country, etc.) to actually match what the schema has (i.e. both practiceName and country should be Strings).
- 主要语言
- Mustache
- 星标
- 17.8k
- 派生
- 6k
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
swagger-api/swagger-codegen 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
swagger-api/swagger-codegen#12755 ·
-
难度 2/5 1-3 小时 新手友好度 62/100
swagger-api/swagger-codegen#12445 ·
-
security vulnerability
难度 1/5 1 小时以内 新手友好度 62/100
swagger-api/swagger-codegen#11942 ·
-
[JAVA] Non compilable enums generated with property errorOnUnknownEnum=true可能已有人在做 @HiagoW 于 1462 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 68/100
swagger-api/swagger-codegen#11812 · 1 个 reaction ·
-
security vulnerability
难度 2/5 1-3 小时 新手友好度 65/100
swagger-api/swagger-codegen#11594 ·
查看 swagger-api/swagger-codegen 的全部 Issue
相似的 Issue
-
Object parameters lose their structure when resources is enabled可能已有人在做 @asts-top 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
temporalio/sdk-ruby#625 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
registrystack/registry-stack#2168 ·
维护者通常 1 天内回复
-
难度 1/5 1-3 小时 新手友好度 92/100