From 12b90264a0e06e4d89ec0ca2d262cfa9e01fff5d Mon Sep 17 00:00:00 2001 From: Pierre Fenoll Date: Mon, 19 Sep 2022 18:11:19 +0200 Subject: [PATCH] moar Signed-off-by: Pierre Fenoll --- openapi3/media_type.go | 9 ++++++++- openapi3/parameter.go | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/openapi3/media_type.go b/openapi3/media_type.go index b1a3417eb..0be50e041 100644 --- a/openapi3/media_type.go +++ b/openapi3/media_type.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "sort" "github.com/go-openapi/jsonpointer" @@ -93,7 +94,13 @@ func (mediaType *MediaType) Validate(ctx context.Context) error { return err } } else if examples := mediaType.Examples; examples != nil { - for k, v := range examples { + names := make([]string, 0, len(examples)) + for name := range examples { + names = append(names, name) + } + sort.Strings(names) + for _, k := range names { + v := examples[k] if err := v.Validate(ctx); err != nil { return fmt.Errorf("%s: %w", k, err) } diff --git a/openapi3/parameter.go b/openapi3/parameter.go index 64092538f..7630aa417 100644 --- a/openapi3/parameter.go +++ b/openapi3/parameter.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "sort" "strconv" "github.com/go-openapi/jsonpointer" @@ -325,7 +326,13 @@ func (parameter *Parameter) Validate(ctx context.Context) error { return err } } else if examples := parameter.Examples; examples != nil { - for k, v := range examples { + names := make([]string, 0, len(examples)) + for name := range examples { + names = append(names, name) + } + sort.Strings(names) + for _, k := range names { + v := examples[k] if err := v.Validate(ctx); err != nil { return fmt.Errorf("%s: %w", k, err) }