Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre Fenoll <[email protected]>
  • Loading branch information
fenollp committed Sep 19, 2022
1 parent a759407 commit 2463c77
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
9 changes: 8 additions & 1 deletion openapi3/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"regexp"
"sort"

"github.com/getkin/kin-openapi/jsoninfo"
)
Expand Down Expand Up @@ -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
}
Expand Down
27 changes: 24 additions & 3 deletions openapi3/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"path"
"path/filepath"
"reflect"
"sort"
"strconv"
"strings"

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions openapi3/testdata/lxkns.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ components:
- starttime
- namespaces
- cpucgroup
- fridgecgroup
- fridgefrozen
# - fridgecgroup
# - fridgefrozen
type: object
properties:
pid:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2463c77

Please sign in to comment.