[Bug]: String and Boolean and Int properties are being turned into Objects in OpenAPI 3.1.0
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 35/100
Línea de trabajo
Comienza con la configuración del plugin de Maven, el JSON de entrada de OpenAPI 3.1 y el Doctor.java generado después de ejecutar mvn clean generate-sources. Rastrea la advertencia "String to be sanitized is null. Default to Object" y compara los tipos de las propiedades generadas con el esquema; se considera completado cuando las propiedades de tipo string, boolean e integer se generan con tipos Java coincidentes en lugar de Object.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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).
- Lenguaje dominante
- Mustache
- Estrellas
- 17.8k
- Forks
- 6k
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
- Incluye un Dockerfile o un archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de swagger-api/swagger-codegen
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
swagger-api/swagger-codegen#12755 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
swagger-api/swagger-codegen#12445 ·
-
security vulnerability
Dificultad 1/5 Menos de una hora Aptitud para principiantes 62/100
swagger-api/swagger-codegen#11942 ·
-
[JAVA] Non compilable enums generated with property errorOnUnknownEnum=truePosiblemente ocupada @HiagoW la tomó hace 1453 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
swagger-api/swagger-codegen#11812 · 1 reacción ·
-
security vulnerability
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
swagger-api/swagger-codegen#11594 ·
Todos los issues de swagger-api/swagger-codegen
Issues similares
-
raised-by:worker
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
medici-finance/assay#2486 ·
Los mantenedores suelen responder en 1 día
-
area:core area:runtime type:security
Dificultad 2/5 Medio día Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
openimsdk/openim-sdk-core#1127 ·
-
good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
zmo2s/agent-toolbox#11 ·
-
mp: /status reports the server class name as engine_type, not the configured enginePosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 2 días