MCPcopy Index your code
hub / github.com/oapi-codegen/oapi-codegen / SortedSchemaKeys

Function SortedSchemaKeys

pkg/codegen/utils.go:362–383  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

360// we support an extension to grant specific orders to schemas to help control output
361// ordering.
362func 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
385func schemaXOrder(v *openapi3.SchemaRef) (int64, bool) {
386 if v == nil {

Callers 5

GenerateGoSchemaFunction · 0.85
gatherComponentSchemasFunction · 0.85
GenerateTypesForSchemasFunction · 0.85

Calls 1

schemaXOrderFunction · 0.85