OpenAPI Generator team implemented jackson-databind-nullable module which you should include to your project. The newest version is 0.2.6.
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>jackson-databind-nullable</artifactId>
<version>0.2.6</version>
</dependency>
If module will not be detected automatically you need to do it manually by:
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JsonNullableModule());
Or if you using Jackson in Spring project, then you can register it by:
@Bean
@Primary
public Jackson2ObjectMapperBuilder customObjectMapper() {
return new Jackson2ObjectMapperBuilder()
// other configs are possible
.modules(new JsonNullableModule());
}
Answer from Michał Ziober on Stack OverflowOpenAPI Generator team implemented jackson-databind-nullable module which you should include to your project. The newest version is 0.2.6.
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>jackson-databind-nullable</artifactId>
<version>0.2.6</version>
</dependency>
If module will not be detected automatically you need to do it manually by:
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JsonNullableModule());
Or if you using Jackson in Spring project, then you can register it by:
@Bean
@Primary
public Jackson2ObjectMapperBuilder customObjectMapper() {
return new Jackson2ObjectMapperBuilder()
// other configs are possible
.modules(new JsonNullableModule());
}
Since openapi-generator v5.1.1 you can use in your config.json:
{
"openApiNullable": false
}
To remove that dependency. Most of the time it's not needed (if you check the generated code), so it's cool to be able to not add an unwanted dependency in your class path.
Or directly in the gradle plugin in your build.gradle you can do:
openApiGenerate {
generatorName = "spring"
inputSpec = "$rootDir/specs/petstore-v3.0.yaml"
outputDir = "$buildDir/generated"
apiPackage = "org.openapi.example.api"
modelPackage = "org.openapi.example.model"
configOptions = [
openApiNullable: "false"
]
}