|
15 | 15 | package openapi
|
16 | 16 |
|
17 | 17 | import (
|
| 18 | + "cmp" |
18 | 19 | "fmt"
|
19 | 20 | "math"
|
20 | 21 | "path"
|
21 | 22 | "regexp"
|
22 | 23 | "slices"
|
23 |
| - "sort" |
24 | 24 | "strings"
|
25 | 25 |
|
26 | 26 | "cuelang.org/go/cue"
|
@@ -166,11 +166,8 @@ func schemas(g *Generator, inst cue.InstanceOrValue) (schemas *ast.StructLit, er
|
166 | 166 | }
|
167 | 167 | }
|
168 | 168 |
|
169 |
| - a := c.schemas.Elts |
170 |
| - sort.Slice(a, func(i, j int) bool { |
171 |
| - x, _, _ := ast.LabelName(a[i].(*ast.Field).Label) |
172 |
| - y, _, _ := ast.LabelName(a[j].(*ast.Field).Label) |
173 |
| - return x < y |
| 169 | + slices.SortFunc(c.schemas.Elts, func(a, b ast.Decl) int { |
| 170 | + return cmp.Compare(label(a), label(b)) |
174 | 171 | })
|
175 | 172 |
|
176 | 173 | return (*ast.StructLit)(c.schemas), c.errs
|
@@ -286,15 +283,12 @@ func value(d ast.Decl) ast.Expr {
|
286 | 283 | }
|
287 | 284 |
|
288 | 285 | func sortSchema(s *ast.StructLit) {
|
289 |
| - sort.Slice(s.Elts, func(i, j int) bool { |
290 |
| - iName := label(s.Elts[i]) |
291 |
| - jName := label(s.Elts[j]) |
292 |
| - pi := fieldOrder[iName] |
293 |
| - pj := fieldOrder[jName] |
294 |
| - if pi != pj { |
295 |
| - return pi > pj |
296 |
| - } |
297 |
| - return iName < jName |
| 286 | + slices.SortFunc(s.Elts, func(a, b ast.Decl) int { |
| 287 | + aName := label(a) |
| 288 | + bName := label(b) |
| 289 | + aOrder := fieldOrder[aName] |
| 290 | + bOrder := fieldOrder[bName] |
| 291 | + return cmp.Or(-cmp.Compare(aOrder, bOrder), cmp.Compare(aName, bName)) |
298 | 292 | })
|
299 | 293 | }
|
300 | 294 |
|
|
0 commit comments