Skip to content

Commit

Permalink
fix: honor x-order while sorting query parameters (#806)
Browse files Browse the repository at this point in the history
Instead of always sorting parameters with name, which can surprise users
because x-order is ignored, sort them with the slice type declared in
github.com/go-openapi/spec to reuse its comparison method.
  • Loading branch information
lantw44 committed Oct 15, 2020
1 parent 01fb318 commit 6937d1c
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions operation.go
Expand Up @@ -247,13 +247,17 @@ func (operation *Operation) ParseParamComment(commentLine string, astFile *ast.F
}
return false
}
orderedNames := make([]string, 0, len(schema.Properties))
for k := range schema.Properties {
orderedNames = append(orderedNames, k)
items := make(spec.OrderSchemaItems, 0, len(schema.Properties))
for k, v := range schema.Properties {
items = append(items, spec.OrderSchemaItem{
Name: k,
Schema: v,
})
}
sort.Strings(orderedNames)
for _, name := range orderedNames {
prop := schema.Properties[name]
sort.Sort(items)
for _, item := range items {
name := item.Name
prop := item.Schema
if len(prop.Type) == 0 {
continue
}
Expand Down

0 comments on commit 6937d1c

Please sign in to comment.