Skip to content
Closed
50 changes: 2 additions & 48 deletions .github/docs/openapi3.txt
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,6 @@ func (m Callbacks) JSONLookup(token string) (any, error)
JSONLookup implements
https://pkg.go.dev/github.com/go-openapi/jsonpointer#JSONPointable

func (callbacks *Callbacks) UnmarshalJSON(data []byte) (err error)
UnmarshalJSON sets Callbacks to a copy of data.

type CommentFieldFor31Plus struct{ ValidationError }

func (e *CommentFieldFor31Plus) As(target any) bool
Expand Down Expand Up @@ -534,9 +531,6 @@ func NewContentWithSchemaRef(schema *SchemaRef, consumes []string) Content

func (content Content) Get(mime string) *MediaType

func (content *Content) UnmarshalJSON(data []byte) (err error)
UnmarshalJSON sets Content to a copy of data.

func (content Content) Validate(ctx context.Context, opts ...ValidationOption) error
Validate returns an error if Content does not comply with the OpenAPI spec.

Expand Down Expand Up @@ -569,7 +563,7 @@ type Discriminator struct {
Origin *Origin `json:"-" yaml:"-"`

PropertyName string `json:"propertyName" yaml:"propertyName"` // required
Mapping StringMap[MappingRef] `json:"mapping,omitempty" yaml:"mapping,omitempty"`
Mapping map[string]MappingRef `json:"mapping,omitempty" yaml:"mapping,omitempty"`
}
Discriminator is specified by OpenAPI/Swagger standard version 3. See
https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#discriminator-object
Expand Down Expand Up @@ -714,9 +708,6 @@ func (encoding *Encoding) WithHeaderRef(name string, ref *HeaderRef) *Encoding
type Encodings map[string]*Encoding
Encodings is a map of encoding objects keyed by field name.

func (encodings *Encodings) UnmarshalJSON(data []byte) (err error)
UnmarshalJSON sets Encodings to a copy of data.

type ExactlyOneFieldError struct {
// Fields is the set of fields, exactly one of which must be set
// (e.g. ["content", "schema"]).
Expand Down Expand Up @@ -816,9 +807,6 @@ func (m Examples) JSONLookup(token string) (any, error)
JSONLookup implements
https://pkg.go.dev/github.com/go-openapi/jsonpointer#JSONPointable

func (examples *Examples) UnmarshalJSON(data []byte) (err error)
UnmarshalJSON sets Examples to a copy of data.

type ExamplesFieldFor31Plus struct{ ValidationError }

func (e *ExamplesFieldFor31Plus) As(target any) bool
Expand Down Expand Up @@ -1059,9 +1047,6 @@ func (m Headers) JSONLookup(token string) (any, error)
JSONLookup implements
https://pkg.go.dev/github.com/go-openapi/jsonpointer#JSONPointable

func (headers *Headers) UnmarshalJSON(data []byte) (err error)
UnmarshalJSON sets Headers to a copy of data.

type IDFieldFor31Plus struct{ ValidationError }

func (e *IDFieldFor31Plus) As(target any) bool
Expand Down Expand Up @@ -1310,9 +1295,6 @@ func (m Links) JSONLookup(token string) (any, error)
JSONLookup implements
https://pkg.go.dev/github.com/go-openapi/jsonpointer#JSONPointable

func (links *Links) UnmarshalJSON(data []byte) (err error)
UnmarshalJSON sets Links to a copy of data.

type Loader struct {
// IsExternalRefsAllowed enables visiting other files. Enforced only when
// ReadFromURIFunc is nil; a custom ReadFromURIFunc bypasses this flag and
Expand Down Expand Up @@ -1529,7 +1511,7 @@ type OAuthFlow struct {
AuthorizationURL string `json:"authorizationUrl,omitempty" yaml:"authorizationUrl,omitempty"`
TokenURL string `json:"tokenUrl,omitempty" yaml:"tokenUrl,omitempty"`
RefreshURL string `json:"refreshUrl,omitempty" yaml:"refreshUrl,omitempty"`
Scopes StringMap[string] `json:"scopes" yaml:"scopes"` // required
Scopes map[string]string `json:"scopes" yaml:"scopes"` // required
}
OAuthFlow is specified by OpenAPI/Swagger standard version 3. See
https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#oauth-flow-object
Expand Down Expand Up @@ -1881,9 +1863,6 @@ func (m ParametersMap) JSONLookup(token string) (any, error)
JSONLookup implements
https://pkg.go.dev/github.com/go-openapi/jsonpointer#JSONPointable

func (parametersMap *ParametersMap) UnmarshalJSON(data []byte) (err error)
UnmarshalJSON sets ParametersMap to a copy of data.

type PathItem struct {
Extensions map[string]any `json:"-" yaml:"-"`
Origin *Origin `json:"-" yaml:"-"`
Expand Down Expand Up @@ -2129,9 +2108,6 @@ func (m RequestBodies) JSONLookup(token string) (any, error)
JSONLookup implements
https://pkg.go.dev/github.com/go-openapi/jsonpointer#JSONPointable

func (requestBodies *RequestBodies) UnmarshalJSON(data []byte) (err error)
UnmarshalJSON sets RequestBodies to a copy of data.

type RequestBody struct {
Extensions map[string]any `json:"-" yaml:"-"`
Origin *Origin `json:"-" yaml:"-"`
Expand Down Expand Up @@ -2290,9 +2266,6 @@ func (m ResponseBodies) JSONLookup(token string) (any, error)
JSONLookup implements
https://pkg.go.dev/github.com/go-openapi/jsonpointer#JSONPointable

func (responseBodies *ResponseBodies) UnmarshalJSON(data []byte) (err error)
UnmarshalJSON sets ResponseBodies to a copy of data.

type ResponseDescriptionRequired struct{ ValidationError }

func (e *ResponseDescriptionRequired) As(target any) bool
Expand Down Expand Up @@ -2925,9 +2898,6 @@ func (m Schemas) JSONLookup(token string) (any, error)
JSONLookup implements
https://pkg.go.dev/github.com/go-openapi/jsonpointer#JSONPointable

func (schemas *Schemas) UnmarshalJSON(data []byte) (err error)
UnmarshalJSON sets Schemas to a copy of data.

type SectionValidationError struct {
Section string
Cause error
Expand All @@ -2952,9 +2922,6 @@ func NewSecurityRequirement() SecurityRequirement

func (security SecurityRequirement) Authenticate(provider string, scopes ...string) SecurityRequirement

func (security *SecurityRequirement) UnmarshalJSON(data []byte) (err error)
UnmarshalJSON sets SecurityRequirement to a copy of data.

func (security *SecurityRequirement) Validate(ctx context.Context, opts ...ValidationOption) error
Validate returns an error if SecurityRequirement does not comply with the
OpenAPI spec.
Expand Down Expand Up @@ -3098,9 +3065,6 @@ func (m SecuritySchemes) JSONLookup(token string) (any, error)
JSONLookup implements
https://pkg.go.dev/github.com/go-openapi/jsonpointer#JSONPointable

func (securitySchemes *SecuritySchemes) UnmarshalJSON(data []byte) (err error)
UnmarshalJSON sets SecuritySchemes to a copy of data.

type SerializationMethod struct {
Style string
Explode bool
Expand Down Expand Up @@ -3199,9 +3163,6 @@ type ServerVariables map[string]*ServerVariable
https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#server-variable-object
ServerVariables is a map of ServerVariable objects keyed by variable name.

func (serverVariables *ServerVariables) UnmarshalJSON(data []byte) (err error)
UnmarshalJSON sets ServerVariables to a copy of data.

type Servers []*Server
Servers is specified by OpenAPI/Swagger standard version 3.

Expand Down Expand Up @@ -3241,13 +3202,6 @@ func NewRegexpFormatValidator(pattern string) StringFormatValidator
NewRegexpFormatValidator creates a new FormatValidator that uses a regular
expression to validate the value.

type StringMap[V any] map[string]V
StringMap is a map[string]string that ignores the origin in the underlying
json representation.

func (stringMap *StringMap[V]) UnmarshalJSON(data []byte) (err error)
UnmarshalJSON sets StringMap to a copy of data.

type T struct {
Extensions map[string]any `json:"-" yaml:"-"`
Origin *Origin `json:"-" yaml:"-"`
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ for _, path := range doc.Paths.InMatchingOrder() {

## CHANGELOG: Sub-v1 breaking API changes

### v0.142.0
* Removed the `openapi3.StringMap[V]` type (an internal helper for origin-aware map unmarshalling, obsolete since origin tracking moved to a separate `OriginTree` pass). `openapi3.Discriminator.Mapping` field type changed from `StringMap[MappingRef]` to `map[string]MappingRef`, and `openapi3.OAuthFlow.Scopes` from `StringMap[string]` to `map[string]string`.

### v0.137.0
* Reinstated `openapi3.*Ptr(..)` funcs for Go 1.25

Expand Down
6 changes: 0 additions & 6 deletions openapi3/callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,3 @@ func (callback *Callback) Validate(ctx context.Context, opts ...ValidationOption

return validateExtensions(ctx, callback.Extensions, callback.Origin)
}

// UnmarshalJSON sets Callbacks to a copy of data.
func (callbacks *Callbacks) UnmarshalJSON(data []byte) (err error) {
*callbacks, err = unmarshalStringMapP[CallbackRef](data)
return
}
6 changes: 0 additions & 6 deletions openapi3/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,3 @@ func (content Content) Validate(ctx context.Context, opts ...ValidationOption) e
}
return nil
}

// UnmarshalJSON sets Content to a copy of data.
func (content *Content) UnmarshalJSON(data []byte) (err error) {
*content, err = unmarshalStringMapP[MediaType](data)
return
}
2 changes: 1 addition & 1 deletion openapi3/discriminator.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Discriminator struct {
Origin *Origin `json:"-" yaml:"-"`

PropertyName string `json:"propertyName" yaml:"propertyName"` // required
Mapping StringMap[MappingRef] `json:"mapping,omitempty" yaml:"mapping,omitempty"`
Mapping map[string]MappingRef `json:"mapping,omitempty" yaml:"mapping,omitempty"`
}

// MappingRef is a ref to a Schema objects. Unlike SchemaRefs it is serialised
Expand Down
6 changes: 0 additions & 6 deletions openapi3/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ func NewEncoding() *Encoding {
// Encodings is a map of encoding objects keyed by field name.
type Encodings map[string]*Encoding

// UnmarshalJSON sets Encodings to a copy of data.
func (encodings *Encodings) UnmarshalJSON(data []byte) (err error) {
*encodings, err = unmarshalStringMapP[Encoding](data)
return
}

func (encoding *Encoding) WithHeader(name string, header *Header) *Encoding {
return encoding.WithHeaderRef(name, &HeaderRef{
Value: header,
Expand Down
6 changes: 0 additions & 6 deletions openapi3/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,3 @@ func (example *Example) Validate(ctx context.Context, opts ...ValidationOption)

return validateExtensions(ctx, example.Extensions, example.Origin)
}

// UnmarshalJSON sets Examples to a copy of data.
func (examples *Examples) UnmarshalJSON(data []byte) (err error) {
*examples, err = unmarshalStringMapP[ExampleRef](data)
return
}
6 changes: 0 additions & 6 deletions openapi3/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,3 @@ func (header *Header) Validate(ctx context.Context, opts ...ValidationOption) er
}
return nil
}

// UnmarshalJSON sets Headers to a copy of data.
func (headers *Headers) UnmarshalJSON(data []byte) (err error) {
*headers, err = unmarshalStringMapP[HeaderRef](data)
return
}
82 changes: 46 additions & 36 deletions openapi3/issue513_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package openapi3
package openapi3_test

import (
"encoding/json"
"net/url"
"strings"
"testing"

"github.com/stretchr/testify/require"

"github.com/getkin/kin-openapi/openapi3"
)

func TestExtraSiblingsInRemoteRef(t *testing.T) {
Expand Down Expand Up @@ -34,45 +37,52 @@ paths:
$ref: http://schemas.sentex.io/store/categories.json
`

// When that site fails to respond:
// see https://github.com/getkin/kin-openapi/issues/495
resolver := func(loader *openapi3.Loader, url *url.URL) (data []byte, err error) {
switch url.String() {
case "http://schemas.sentex.io/store/categories.json":
data = []byte(`
{
"$id": "http://schemas.sentex.io/store/categories.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"description": "array of category strings",
"type": "array",
"items": {
"allOf": [
{
"$ref": "http://schemas.sentex.io/store/category.json"
}
]
}
}`)

// http://schemas.sentex.io/store/categories.json
// {
// "$id": "http://schemas.sentex.io/store/categories.json",
// "$schema": "http://json-schema.org/draft-07/schema#",
// "description": "array of category strings",
// "type": "array",
// "items": {
// "allOf": [
// {
// "$ref": "http://schemas.sentex.io/store/category.json"
// }
// ]
// }
// }
case "http://schemas.sentex.io/store/category.json":
data = []byte(`
{
"$id": "http://schemas.sentex.io/store/category.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"description": "category name for products",
"type": "string",
"pattern": "^[A-Za-z0-9\\-]+$",
"minimum": 1,
"maximum": 30
}`)

// http://schemas.sentex.io/store/category.json
// {
// "$id": "http://schemas.sentex.io/store/category.json",
// "$schema": "http://json-schema.org/draft-07/schema#",
// "description": "category name for products",
// "type": "string",
// "pattern": "^[A-Za-z0-9\\-]+$",
// "minimum": 1,
// "maximum": 30
// }
default:
panic(url)
}
return
}

for _, majmin := range []string{"'3.0'", "'3.1'"} {
for _, majmin := range []string{"'3.0'", "'3.1'", "'3.2'"} {
t.Run(majmin, func(t *testing.T) {
t.Parallel()
sl := NewLoader()
sl.IsExternalRefsAllowed = true
sl := openapi3.NewLoader()
sl.ReadFromURIFunc = resolver

doc, err := sl.LoadFromData([]byte(strings.ReplaceAll(spec, "3.0.1", majmin)))
require.NoError(t, err)

err = doc.Validate(sl.Context, AllowExtraSiblingFields("$id", "$schema"))
err = doc.Validate(sl.Context, openapi3.AllowExtraSiblingFields("$id", "$schema"))
require.NoError(t, err)
})
}
Expand Down Expand Up @@ -114,7 +124,7 @@ components:
for _, majmin := range []string{"3.0", "3.1"} {
t.Run(majmin, func(t *testing.T) {
t.Parallel()
sl := NewLoader()
sl := openapi3.NewLoader()
doc, err := sl.LoadFromData([]byte(strings.ReplaceAll(spec, "3.0.3", majmin)))
require.NoError(t, err)
err = doc.Validate(sl.Context)
Expand Down Expand Up @@ -165,7 +175,7 @@ components:
for _, majmin := range []string{"3.0", "3.1"} {
t.Run(majmin, func(t *testing.T) {
t.Parallel()
sl := NewLoader()
sl := openapi3.NewLoader()
doc, err := sl.LoadFromData([]byte(strings.ReplaceAll(spec, "3.0.3", majmin)))
require.NoError(t, err)
require.Contains(t, doc.Paths.Value("/v1/operation").Delete.Responses.Default().Value.Extensions, `x-my-extension`)
Expand Down Expand Up @@ -212,7 +222,7 @@ components:
for _, majmin := range []string{"3.0", "3.1"} {
t.Run(majmin, func(t *testing.T) {
t.Parallel()
sl := NewLoader()
sl := openapi3.NewLoader()
doc, err := sl.LoadFromData([]byte(strings.ReplaceAll(spec, "3.0.3", majmin)))
require.NoError(t, err)
err = doc.Validate(sl.Context)
Expand Down Expand Up @@ -258,10 +268,10 @@ components:
for _, majmin := range []string{"3.0", "3.1"} {
t.Run(majmin, func(t *testing.T) {
t.Parallel()
sl := NewLoader()
sl := openapi3.NewLoader()
doc, err := sl.LoadFromData([]byte(strings.ReplaceAll(spec, "3.0.3", majmin)))
require.NoError(t, err)
err = doc.Validate(sl.Context, AllowExtraSiblingFields("description"))
err = doc.Validate(sl.Context, openapi3.AllowExtraSiblingFields("description"))
require.NoError(t, err)
})
}
Expand Down
6 changes: 0 additions & 6 deletions openapi3/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,3 @@ func (link *Link) Validate(ctx context.Context, opts ...ValidationOption) error

return validateExtensions(ctx, link.Extensions, link.Origin)
}

// UnmarshalJSON sets Links to a copy of data.
func (links *Links) UnmarshalJSON(data []byte) (err error) {
*links, err = unmarshalStringMapP[LinkRef](data)
return
}
1 change: 0 additions & 1 deletion openapi3/media_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ func (mediaType *MediaType) UnmarshalJSON(data []byte) error {
if len(x.Extensions) == 0 {
x.Extensions = nil
}
delete(x.Encoding, originKey)
*mediaType = MediaType(x)
return nil
}
Expand Down
1 change: 0 additions & 1 deletion openapi3/openapi3.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ func (doc *T) UnmarshalJSON(data []byte) error {
if len(x.Extensions) == 0 {
x.Extensions = nil
}
delete(x.Webhooks, originKey)
*doc = T(x)
return nil
}
Expand Down
Loading
Loading