Change API display order in Swagger (using Spring)

Viewed 8295

I am trying to change the displayed method order in swagger-ui page using java.

enter image description here

I need to show first welcome later hello controller method.

Below is my code. enter image description here

3 Answers

In the @ApiOperation annotation you have an attribute position that you can set to change the order. Note that the attribute is deprecated but still works.

As you can read here the core developer of spring-fox states the problem very clear:

Just to be clear, we have an internal model that totally works as expected and functional. The api descriptions and api operations will be sorted as expected from springfox's standpoint. We're only using the swagger models as DTOs to handle the serialization of our internal service models. Once the DTO's are fixed to preserve the ordering this problem will go away.

We can certainly add a note to describe the problem and the cause to the Readme. Other than waiting for swagger core to fix this, there is nothing to do here other than that I'm afraid.

So unless the Open API will fix/ enhance their models it will not work for spring-fox.

Default - {controller-name}-controller {controller-name}-controller

For Custom Name Add - @Tag(name="1. YOUR CUSTOM NAME HERE")

on the Controller Class. Remember, we have used 1 in the name so that it can be on the top.

Example -

@RestController
@Tag(name="1. Project Resource")
public class ProjectResource {...}

Add the following to the application.yml file

springdoc:
  swagger-ui:
    tagsSorter: alpha

Result -

enter image description here

Related