springdoc / springdoc-openapi

Library for OpenAPI 3 with spring-boot
https://springdoc.org
Apache License 2.0
3.3k stars 500 forks source link

Incorrect representation of Sort property and SortObject in openapi after update to Spring Boot 3 #2763

Closed mathsiv closed 1 month ago

mathsiv commented 1 month ago

I found a mismatch between the result of a call and the openapi documentation generated. The call should return a Page of MyDto, which contains a sort property.

Environment:

Here is an example of response i get with my call. No sorting is applied :

{
  "totalElements": 49,
  "totalPages": 1,
  "size": 50,
  "content": [],
  "number": 0,
  "sort": {
    "empty": true,
    "unsorted": true,
    "sorted": false
  },
  "pageable": {
    "pageNumber": 0,
    "pageSize": 50,
    "sort": {
      "empty": true,
      "unsorted": true,
      "sorted": false
    },
    "offset": 0,
    "unpaged": false,
    "paged": true
  },
  "first": true,
  "last": true,
  "numberOfElements": 49,
  "empty": false
}

As you can see, the sort property contains an object with empty, unosrted and sorted. But my openapi documentation tells me i should get something like this :

PageableObject:
  type: object
  properties:
    offset:
      type: integer
      format: int64
    sort:
      type: array
      items:
        $ref: "#/components/schemas/SortObject"
    pageSize:
      type: integer
      format: int32
    pageNumber:
      type: integer
      format: int32
    paged:
      type: boolean
    unpaged:
      type: boolean

SortObject:
  type: object
  properties:
    direction:
      type: string
    nullHandling:
      type: string
    ascending:
      type: boolean
    property:
      type: string
    ignoreCase:
      type: boolean

Pretty different. My openapi swagger used to also have the 3 properties empty, unsorted and sorted when I had spring boot 2 instead of 3 (I used springdoc-openapi-ui 1.6.11 and springdoc-openapi-maven-plugin 1.1), but then changed to this. I can't figure out why.

Expected : I'd like my openapi documentation to actually reflect the object my call responds.

Could you help me figure out what i can do to fix this ?

Additional info : While looking for a solution, i found this issue. It seems highly similar to mine.

bnasslahsen commented 1 month ago

@mathsiv,

This is duplicate of https://github.com/springdoc/springdoc-openapi/issues/2725

That should be fixed with the next release v2.7.0