Search code examples
javaopenapispringdoc-openapi-uispringdoc-openui

How do I control tag order in Springdoc OpenAPI 3.0?


I'm switching from Springfox 3.0 to OpenAPI 3.0 + Springdoc-openapi.
In Springfox the tag order is alphabetical, but in Springdoc's Swagger UI, the order appears to be random.

How do I control the Tag order on the UI? I'd prefer an ordering of my choosing, but would be OK with ordering alphabetically by tag name.

@Tag(name = MY_CONTROLLER_TAG_NAME, description = MY_CONTROLLER_TAG_DESC)
public class MyController {

Desired Order:

  • Paginated Endpoints
  • User Access
  • Tagging
  • Tagging - Admin
  • User Management
  • User Management - Admin

Actual Order:

  • User Access
  • Tagging
  • Paginated Endpoints
  • Tagging - Admin
  • User Management - Admin
  • User Management

POM Dependencies:

        <springdoc-openapi.version>1.6.4</springdoc-openapi.version>
...
        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-ui</artifactId>
            <version>${springdoc-openapi.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-security</artifactId>
            <version>${springdoc-openapi.version}</version>
        </dependency>

Application.yml:

springdoc:
  show-actuator: ${SWAGGER_ENABLED:true}
  swagger-ui:
    doc-expansion: none
  api-docs:
    enabled: ${SWAGGER_ENABLED:true}
  model-converters:
    pageable-converter:
      enabled: true

Solution

  • try either:

    springdoc.swagger-ui.tagsSorter: alpha
    
    springdoc.writer-with-order-by-keys: true
    

    https://springdoc.org/properties.html