Migrating from springfox - springdoc
springfox generated an openApi definition that ordered all the parameters in alphabetical order, I've migrated to springdoc, but have been unable to find a way to keep the springfox ordering(alpha) of the parameters, e.g.
Controller:
getPerson(name, address, mobile)
springfox generated openApi definition:
getPersonService(address, mobile, name)
springdoc generated openApi definition:
getPersonService(name, address, mobile)
There are properties to order other aspects of the generated definition with:
springdoc.swagger-ui.operationsSorter=method
springdoc.swagger-ui.tagsSorter=alpha
springdoc.writer-with-order-by-keys: true
I have been unable to find a property to order the operation parameters, is there a setting to accomplish this? or can it be achieved cleanly with:
OpenApiCustomiser or OperationCustomizer
Here's a solution using the OperationCustomizer (Kotlin Syntax):
@Bean
fun parameterOrderCustomizer(): OperationCustomizer {
return OperationCustomizer { operation, _ ->
operation.apply {
parameters = parameters?.sortedBy { it.name }
}
}
}
and in case youre using grouped apis, dont forget to also add them to the groups via .addOperationCustomizer(parameterOrderCustomizer())
Update your application.property file with:
springdoc.writer-with-order-by-keys=true
or in application.yaml file
springdoc
writer-with-order-by-keys: true
Paths, schemas and properties is sorted ascending alphabetically perfectly fine
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With