Skip to content

Commit

Permalink
Merge pull request #92 from Teamwork/fix-allocationId-fun
Browse files Browse the repository at this point in the history
Fix: Inconsistent sorting given same name different 'in'
  • Loading branch information
shane-tw authored Aug 22, 2022
2 parents 5bf1f9e + 7e1fc34 commit ebbbc5b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion openapi2/openapi2.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,13 @@ func write(outFormat string, w io.Writer, prog *docparse.Program) error {
// TODO: preserve order in which they were defined in the struct, but
// for now sort it like this so the output is stable.
sort.Slice(op.Parameters, func(i, j int) bool {
return op.Parameters[i].Type+op.Parameters[i].Name > op.Parameters[j].Type+op.Parameters[j].Name
left := op.Parameters[i].Type + op.Parameters[i].Name
right := op.Parameters[j].Type + op.Parameters[j].Name
if left == right {
specificOrder := map[string]int64{"path": 0, "query": 1, "formData": 2, "body": 3}
return specificOrder[op.Parameters[i].In] < specificOrder[op.Parameters[j].In]
}
return left > right
})

for code, resp := range e.Responses {
Expand Down

0 comments on commit ebbbc5b

Please sign in to comment.