SortedSchemaKeys returns the keys of the given SchemaRef dictionary in sorted order, since Golang scrambles dictionary keys. This isn't a generic key sort, because we support an extension to grant specific orders to schemas to help control output ordering.
(dict map[string]*openapi3.SchemaRef)
| 360 | // we support an extension to grant specific orders to schemas to help control output |
| 361 | // ordering. |
| 362 | func SortedSchemaKeys(dict map[string]*openapi3.SchemaRef) []string { |
| 363 | keys := make([]string, len(dict)) |
| 364 | orders := make(map[string]int64, len(dict)) |
| 365 | i := 0 |
| 366 | |
| 367 | for key, v := range dict { |
| 368 | keys[i], orders[key] = key, int64(len(dict)) |
| 369 | i++ |
| 370 | |
| 371 | if order, ok := schemaXOrder(v); ok { |
| 372 | orders[key] = order |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | slices.SortFunc(keys, func(a, b string) int { |
| 377 | return cmp.Or( |
| 378 | cmp.Compare(orders[a], orders[b]), |
| 379 | cmp.Compare(a, b), |
| 380 | ) |
| 381 | }) |
| 382 | return keys |
| 383 | } |
| 384 | |
| 385 | func schemaXOrder(v *openapi3.SchemaRef) (int64, bool) { |
| 386 | if v == nil { |