Description
When using io.github.vpelikh:springdoc-openapi:4.0.0, the KotlinRequiredPropertyCustomizer (registered as a ModelConverter) runs Kotlin reflection over every model — not just Kotlin ones. It only skips java.* packages.
For a Java class, Kotlin reflection sees platform types, and KType.isMarkedNullable() returns false, so every property of every Java DTO gets marked required.
Impact
In the reporter's application, this caused an unintended expansion of the required fields in 142 of 150 schemas.
Workaround
Set springdoc.enable-kotlin: false in application.yaml to disable the automatic customizer, then re-register only KotlinNullablePropertyCustomizer manually:
@Configuration
class KotlinAwareModelResolverConfiguration {
@Bean
ModelResolver kotlinAwareModelResolver(SpringDocConfigProperties properties) {
var openapi31 = properties.isOpenapi31();
var base = openapi31 ? Json31.mapper() : Json.mapper();
var mapper = SpringDocHalJacksonModuleUtils.configureHalOnBuilder(
base.rebuild()
.addModule(new SpringDocSealedClassModule())
.addModule(new KotlinModule.Builder().build()))
.build();
return new ModelResolver(mapper).openapi31(openapi31);
}
@Bean
KotlinNullablePropertyCustomizer kotlinNullablePropertyCustomizer(ObjectMapperProvider objectMapperProvider) {
return new KotlinNullablePropertyCustomizer(objectMapperProvider);
}
}
Source
Reported by @mschout in the Jackson 3 migration PR:
swagger-api/swagger-core#5031 (comment)
Description
When using
io.github.vpelikh:springdoc-openapi:4.0.0, theKotlinRequiredPropertyCustomizer(registered as aModelConverter) runs Kotlin reflection over every model — not just Kotlin ones. It only skipsjava.*packages.For a Java class, Kotlin reflection sees platform types, and
KType.isMarkedNullable()returnsfalse, so every property of every Java DTO gets markedrequired.Impact
In the reporter's application, this caused an unintended expansion of the
requiredfields in 142 of 150 schemas.Workaround
Set
springdoc.enable-kotlin: falseinapplication.yamlto disable the automatic customizer, then re-register onlyKotlinNullablePropertyCustomizermanually:Source
Reported by @mschout in the Jackson 3 migration PR:
swagger-api/swagger-core#5031 (comment)