wI2L / fizz

:lemon: Gin wrapper with OpenAPI 3 spec generation
https://pkg.go.dev/github.com/wI2L/fizz
MIT License
214 stars 52 forks source link

Keep sorting #33

Closed ghost closed 4 years ago

ghost commented 5 years ago

How to keep sorting for tags, operations, struct fields?

wI2L commented 5 years ago

I don't understand the question, could you please elaborate on the subject ?

ghost commented 5 years ago

Ok. For example:

type Foo struct {
    name int `query:"name"`
    id       int `query:"id"`
}
// ....
tonic.Handler(func (/*...*/, *Foo) error {}, 200)

Fizz generate params in specification:

// ....
"parameters": [
  {
    "name": "id",
    // ....
  },
  {
    "name": "name",
    // ....
  }
],
// ....

It sort struct fields by name. I want to keep sorting by it position in Go struct.

Some situation in tags. For example:

fizz.Group("/b", "b", "First group")
fizz.Group("/a", "a", "Second group") 

generate:

"tags": [
  {"name":"a", "description":"Second group"},
  {"name":"b", "description":"First group"}
]
wI2L commented 5 years ago

Yup, that's an opt-in you can deactivate with the following method. https://github.com/wI2L/fizz/blob/bbaa01a9f70702e7c16baa507eefe416faaf67cb/openapi/generator.go#L130 To access the openapi.Generator instance of the Fizz object, use the following. https://github.com/wI2L/fizz/blob/bbaa01a9f70702e7c16baa507eefe416faaf67cb/fizz.go#L92

EDIT: Please close the issue if it solves the need.

ghost commented 5 years ago

For tags sort executed without any conditions https://github.com/wI2L/fizz/blob/bbaa01a9f70702e7c16baa507eefe416faaf67cb/openapi/generator.go#L203

wI2L commented 5 years ago

Sorry, I didn't read properly all the way through your first comment. The OpenAPI spec says that the ordering of the global tags section controls de default ordering in the UI, so yes, we should also provide a method to disable the auto sort, the same way we do it for parameters. Again, feel free to submit a PR for this, or I'll look at it when I have some time.