Issue
I am using springdoc
. It works flawlessly, except I am trying to change the default camelCase to PascalCase requests mapping.
I searched through the docs and cannot find a configuration to adjust property naming.
How can I change property naming when working with springdoc
?
Solution
As @Debargha Roy mentioned in his answer, there is no clear way to do it via springdoc
properties.
I propose my solution for Kotlin based on GitHub thread.
To get PascalCase
or UpperCamelCase
in Swagger, you can use ModelResolver
:
@Bean
fun modelResolver(objectMapper: ObjectMapper): ModelResolver {
return ModelResolver(jacksonObjectMapper().registerModule(KotlinModule()).setPropertyNamingStrategy(PropertyNamingStrategy.UPPER_CAMEL_CASE))
}
It doesn't resolve the output response from Spring @RestController
.
By default, Spring uses Jackson mapper to make responses follow UpperCamelCase, use this property spring.jackson.property-naming-strategy=UPPER_CAMEL_CASE
in properties/yaml file.
After these 2 changes, both your Swagger and RestController will follow the UpperCamelCase style.
NOTE:
Beware, if you decided to reuse incoming objectMapper
(see the snippet below), you may get duplicated payload with mixed camelCase:
@Bean
fun modelResolver(objectMapper: ObjectMapper): ModelResolver {
return ModelResolver(objectMapper.registerModule(KotlinModule()).setPropertyNamingStrategy(PropertyNamingStrategy.UPPER_CAMEL_CASE))
}
Answered By - Dmytro Chasovskyi
Answer Checked By - Pedro (JavaFixing Volunteer)