swag
swag copied to clipboard
[Question] Is there any way to sort the methods under a specific tag manually?
It seems like that swaggo generates the routes and their methods in a random order. The tags shown in my redoc page is in the specified order but the methods under them does not have the order I expected. Is there any way that swaggo generates the methods in the code order? Or maybe I can use a tag to specify the order manually. I have already tested @x-sort but it didn't work.
It seems like that swaggo generates the routes and their methods in a random order. The tags shown in my redoc page is in the specified order but the methods under them does not have the order I expected. Is there any way that swaggo generates the methods in the code order? Or maybe I can use a tag to specify the order manually. I have already tested @x-sort but it didn't work.
If you want to display the methods in a specific order, you can use the @x-order
annotation in your Swagger annotations.
like :
// @Summary Get user by ID
// @Description Get user by ID
// ...
// @x-order 1
// ...
func getUserByID(c *gin.Context) {
// ...
}
// @Summary Update user
// @Description Update user
// ...
// @x-order 2
// ...
func updateUser(c *gin.Context) {
// ...
}
It seems like that swaggo generates the routes and their methods in a random order. The tags shown in my redoc page is in the specified order but the methods under them does not have the order I expected. Is there any way that swaggo generates the methods in the code order? Or maybe I can use a tag to specify the order manually. I have already tested @x-sort but it didn't work.
If you want to display the methods in a specific order, you can use the
@x-order
annotation in your Swagger annotations.like :
// @Summary Get user by ID // @Description Get user by ID // ... // @x-order 1 // ... func getUserByID(c *gin.Context) { // ... } // @Summary Update user // @Description Update user // ... // @x-order 2 // ... func updateUser(c *gin.Context) { // ... }
I have tested @x-order
but unfortunately it didn't work.
Just to make sure I'm clear, in Swagger UI, you can only set the display order of methods using tags and x-order. You can use both of these options to arrange the methods in the desired order.
It seems like that swaggo generates the routes and their methods in a random order. The tags shown in my redoc page is in the specified order but the methods under them does not have the order I expected. Is there any way that swaggo generates the methods in the code order? Or maybe I can use a tag to specify the order manually. I have already tested @x-sort but it didn't work.
If you want to display the methods in a specific order, you can use the
@x-order
annotation in your Swagger annotations. like :// @Summary Get user by ID // @Description Get user by ID // ... // @x-order 1 // ... func getUserByID(c *gin.Context) { // ... } // @Summary Update user // @Description Update user // ... // @x-order 2 // ... func updateUser(c *gin.Context) { // ... }
I have tested
@x-order
but unfortunately it didn't work.
Just to make sure I'm clear, in Swagger UI, you can only set the display order of methods using tags and x-order. You can use both of these options to arrange the methods in the desired order.
Hi there,
It seems @x-order
and operationsSorter
don't work, any new way?
I also ran into this problem, custom sorting does not work
I just encountered this problem, and @x-order
did not work.
For example:
// handleSignUpUser SignUp
// @x-order 1
// @Summary Sign up a user
and then, even though I can see the x-order
values in the swager.json file:
"x-order": 2
But it doesn't sort based on them. :/ I tried bot number and string values, and neither worked.
😭😭😭my OCD man...