From 2463c7720d91da5829e893c991459b197d9c8cbc Mon Sep 17 00:00:00 2001 From: Pierre Fenoll Date: Mon, 19 Sep 2022 17:49:00 +0200 Subject: [PATCH] wip Signed-off-by: Pierre Fenoll --- openapi3/components.go | 9 ++++++++- openapi3/loader.go | 27 ++++++++++++++++++++++++--- openapi3/testdata/lxkns.yaml | 6 +++--- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/openapi3/components.go b/openapi3/components.go index e9af26911..d2b645ef9 100644 --- a/openapi3/components.go +++ b/openapi3/components.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "regexp" + "sort" "github.com/getkin/kin-openapi/jsoninfo" ) @@ -94,7 +95,13 @@ func (components *Components) Validate(ctx context.Context) (err error) { } } - for k, v := range components.Examples { + examples := make([]string, 0, len(components.Examples)) + for name := range components.Examples { + examples = append(examples, name) + } + sort.Strings(examples) + for _, k := range examples { + v := components.Examples[k] if err = ValidateIdentifier(k); err != nil { return } diff --git a/openapi3/loader.go b/openapi3/loader.go index 87c9f8684..dabb37615 100644 --- a/openapi3/loader.go +++ b/openapi3/loader.go @@ -9,6 +9,7 @@ import ( "path" "path/filepath" "reflect" + "sort" "strconv" "strings" @@ -206,11 +207,19 @@ func (loader *Loader) ResolveRefsIn(doc *T, location *url.URL) (err error) { return } } - for _, component := range components.Examples { + + examples := make([]string, 0, len(components.Examples)) + for name := range components.Examples { + examples = append(examples, name) + } + sort.Strings(examples) + for _, name := range examples { + component := components.Examples[name] if err = loader.resolveExampleRef(doc, component, location); err != nil { return } } + for _, component := range components.Callbacks { if err = loader.resolveCallbackRef(doc, component, location); err != nil { return @@ -585,7 +594,13 @@ func (loader *Loader) resolveRequestBodyRef(doc *T, component *RequestBodyRef, d } for _, contentType := range value.Content { - for name, example := range contentType.Examples { + examples := make([]string, 0, len(contentType.Examples)) + for name := range contentType.Examples { + examples = append(examples, name) + } + sort.Strings(examples) + for _, name := range examples { + example := contentType.Examples[name] if err := loader.resolveExampleRef(doc, example, documentPath); err != nil { return err } @@ -649,7 +664,13 @@ func (loader *Loader) resolveResponseRef(doc *T, component *ResponseRef, documen if contentType == nil { continue } - for name, example := range contentType.Examples { + examples := make([]string, 0, len(contentType.Examples)) + for name := range contentType.Examples { + examples = append(examples, name) + } + sort.Strings(examples) + for _, name := range examples { + example := contentType.Examples[name] if err := loader.resolveExampleRef(doc, example, documentPath); err != nil { return err } diff --git a/openapi3/testdata/lxkns.yaml b/openapi3/testdata/lxkns.yaml index 4ffa6dde9..a4f4b5a69 100644 --- a/openapi3/testdata/lxkns.yaml +++ b/openapi3/testdata/lxkns.yaml @@ -153,8 +153,8 @@ components: - starttime - namespaces - cpucgroup - - fridgecgroup - - fridgefrozen + # - fridgecgroup + # - fridgefrozen type: object properties: pid: @@ -562,7 +562,7 @@ components: type: integer example: '4026532338': - nsid: 4026532338 + nsid: 4026532338 # | Error at "/nsid": property "nsid" is missing type: pid owner: 4026531837 reference: /proc/33536/ns/pid