swaggo / gin-swagger

gin middleware to automatically generate RESTful API documentation with Swagger 2.0.
MIT License
3.76k stars 270 forks source link

struct with default order #219

Open kchojn opened 2 years ago

kchojn commented 2 years ago

Hello, Is it possible to keep the default order of the structure in the documentation?

Example:

type EventsQuery struct {
    ChainId       string       
    FromBlock     string              `validate:"required"`           
    ToBlock       string              `validate:"required"`                  
    FromTimestamp time.Time           `format:"date-time"`      
    ToTimestamp   time.Time           `format:"date-time" `                     
    Contract      ContractArrayString 
    Name          NameArrayString   
    Keys          KeysArrayString   
    PageSize      int                 `validate:"required" minimum:"1" maximum:"100"` 
    PageNumber    int                 `validate:"required" minimum:"1"`      
}

Unfortunately, in the documentation, it displays alphabetically to me (why?). Is it possible to change this? image

Regards!

Jagerente commented 1 year ago

In case someone is still looking for solution. You have to add extensions:"x-order=N" tag next to the field:

type Character struct {
    Name           map[languages.Language]string `json:"name" extensions:"x-order=0"`
    Description    map[languages.Language]string `json:"desctiption" extensions:"x-order=1"`
        // etc...
}