swag icon indicating copy to clipboard operation
swag copied to clipboard

[Question] Is there any way to sort the methods under a specific tag manually?

Open artaasadi opened this issue 1 year ago • 8 comments

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.

artaasadi avatar Apr 25 '23 13:04 artaasadi

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) {
    // ...
}

klaveriuzent avatar May 03 '23 04:05 klaveriuzent

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.

artaasadi avatar May 10 '23 14:05 artaasadi

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.

klaveriuzent avatar May 12 '23 04:05 klaveriuzent

@klaveriuzent how about

operationsSorter

and

tagsSorter

described here Can we somehow use them?

FluorescentTouch avatar Aug 22 '23 09:08 FluorescentTouch

Hi there,

It seems @x-order and operationsSorter don't work, any new way?

rts-gordon avatar Feb 29 '24 04:02 rts-gordon

I also ran into this problem, custom sorting does not work

8thgencore avatar Feb 29 '24 09:02 8thgencore

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.

prazian avatar May 30 '24 14:05 prazian

😭😭😭my OCD man...

Dieg0Code avatar Aug 02 '24 05:08 Dieg0Code