-
-
Notifications
You must be signed in to change notification settings - Fork 524
Serialization to openapi of org.springframework.data.domain.Sort is not done correctly #2447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@a-locatelli Did you manage to solve this? Any workarounds? |
I have added a fix for it. |
I have the same problem, and your fix dosen't solved it. Your excpected output is: "sort": {
"$ref": "#/components/schemas/SortObject"
}, But have to be: "sort": {
"type": "array",
"items": {
"$ref": "#/components/schemas/OrderObject"
}
}, I implemented a workaround like this, with this the desired openapi.json is generated and from that working DTOs to use with Pageable and Sort. @Configuration
class CustomOpenApiConfiguration {
@Bean
fun CustomSortSchemaConverter(): SortSchemaConverter {
// Create and return the custom SortSchemaConverter
return SortSchemaConverter()
}
}
class SortSchemaConverter : ModelConverter {
override fun resolve(
type: AnnotatedType,
context: ModelConverterContext,
chain: MutableIterator<ModelConverter>
): Schema<*>? {
val javaType = type.type
return if (javaType is SimpleType && javaType.rawClass == Sort::class.java) {
val orderSchema = ObjectSchema()
.addProperty("direction", StringSchema())
.addProperty("property", StringSchema())
.addProperty("ignoreCase", BooleanSchema())
.addProperty("nullHandling", StringSchema())
.addProperty("ascending", BooleanSchema())
.addProperty("descending", BooleanSchema())
// needs to be called whenever a Model is defined which can be referenced from another
// Model or Property
context.defineModel("OrderObject", orderSchema)
ArraySchema().items(
Schema<Any>().`$ref`("#/components/schemas/OrderObject")
)
} else if (chain.hasNext()) {
chain.next().resolve(type, context, chain)
} else {
null
}
}
} |
Your proposed fix is too much lines of code, with too much assumptions that |
Hi,
There is something wrong with the serialization (to openapi) of the org.springframework.data.domain.Sort
I've a method which returns a org.springframework.data.domain.Page from a method in a RestController class.
The implementation of org.springframework.data.domain.Page is org.springframework.data.domain.PageImpl
The openapi defintion generated is:
When i call the method, the return object is (content is empty for this example):
As you can see, the "sort" property generated is not an array, and the SortObject does not contains the Sort properties like orders.
If i set the query parameter sort, the result is:
I'm using spring boot 3.1.6 and springdoc-openapi-webmvc-ui 2.3.0.
Can you help me figure out if there is a bug or if i'm doing something wrong?
Thanks
The text was updated successfully, but these errors were encountered: