Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta
#12,666 2 commenti 1 reazione 0 assegnatari Vedi su GitHub

@Prsolver ci sta già lavorando.

Dal 20/1/2026.

  • #12675 di @Prsolver — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
java
Ambito
api, tooling

Direzione di ricerca

Inizia dalla configurazione del plugin Maven, dal JSON di input OpenAPI 3.1 e dal Doctor.java generato dopo aver eseguito mvn clean generate-sources. Segui l’avviso "String to be sanitized is null. Default to Object" e confronta i tipi delle proprietà generate con lo schema; il lavoro è completato quando le proprietà di tipo string, boolean e integer vengono generate con tipi Java corrispondenti invece di Object.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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).

Lingua principale
Mustache
Stelle
17.8k
Fork
6k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di swagger-api/swagger-codegen

Tutte le issue di swagger-api/swagger-codegen

Issue simili

Altre issue su Backend & API Design

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.