Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

[Bug]: String and Boolean and Int properties are being turned into Objects in OpenAPI 3.1.0

未关闭
#12,666 2 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

@Prsolver 已经在做这个了。

开始于 2026年1月20日。

  • #12675 来自 @Prsolver —— 未关闭

评估

难度
3/5
预计耗时
1-2 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
java
领域
api, tooling

调研方向

从 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 内容生成。

描述

Bug

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

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

swagger-api/swagger-codegen 的其他 Issue

查看 swagger-api/swagger-codegen 的全部 Issue

相似的 Issue

更多 Backend & API Design Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。