go.mod: Update oapi-codegen and kin-openapi

This commit is contained in:
sanne 2022-01-11 19:00:14 +01:00 committed by Sanne Raymaekers
parent add17bba45
commit a83cf95d5b
156 changed files with 29663 additions and 2248 deletions

View file

@ -3,14 +3,18 @@ package openapi3
import (
"context"
"errors"
"fmt"
"strconv"
"github.com/getkin/kin-openapi/jsoninfo"
"github.com/go-openapi/jsonpointer"
)
// Responses is specified by OpenAPI/Swagger 3.0 standard.
type Responses map[string]*ResponseRef
var _ jsonpointer.JSONPointable = (*Responses)(nil)
func NewResponses() Responses {
r := make(Responses)
r["default"] = &ResponseRef{Value: NewResponse().WithDescription("")}
@ -25,25 +29,37 @@ func (responses Responses) Get(status int) *ResponseRef {
return responses[strconv.FormatInt(int64(status), 10)]
}
func (responses Responses) Validate(c context.Context) error {
if len(responses) == 0 {
func (value Responses) Validate(ctx context.Context) error {
if len(value) == 0 {
return errors.New("the responses object MUST contain at least one response code")
}
for _, v := range responses {
if err := v.Validate(c); err != nil {
for _, v := range value {
if err := v.Validate(ctx); err != nil {
return err
}
}
return nil
}
func (responses Responses) JSONLookup(token string) (interface{}, error) {
ref, ok := responses[token]
if ok == false {
return nil, fmt.Errorf("invalid token reference: %q", token)
}
if ref != nil && ref.Ref != "" {
return &Ref{Ref: ref.Ref}, nil
}
return ref.Value, nil
}
// Response is specified by OpenAPI/Swagger 3.0 standard.
type Response struct {
ExtensionProps
Description *string `json:"description,omitempty" yaml:"description,omitempty"`
Headers map[string]*HeaderRef `json:"headers,omitempty" yaml:"headers,omitempty"`
Content Content `json:"content,omitempty" yaml:"content,omitempty"`
Links map[string]*LinkRef `json:"links,omitempty" yaml:"links,omitempty"`
Description *string `json:"description,omitempty" yaml:"description,omitempty"`
Headers Headers `json:"headers,omitempty" yaml:"headers,omitempty"`
Content Content `json:"content,omitempty" yaml:"content,omitempty"`
Links Links `json:"links,omitempty" yaml:"links,omitempty"`
}
func NewResponse() *Response {
@ -78,13 +94,13 @@ func (response *Response) UnmarshalJSON(data []byte) error {
return jsoninfo.UnmarshalStrictStruct(data, response)
}
func (response *Response) Validate(c context.Context) error {
if response.Description == nil {
func (value *Response) Validate(ctx context.Context) error {
if value.Description == nil {
return errors.New("a short description of the response is required")
}
if content := response.Content; content != nil {
if err := content.Validate(c); err != nil {
if content := value.Content; content != nil {
if err := content.Validate(ctx); err != nil {
return err
}
}