Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openapi3: reference originating locations in YAML specs - step 1 #1007

Merged
merged 46 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
20a9abd
add origin - step 1
reuvenharrison Aug 19, 2024
f90371a
delete origin from content
reuvenharrison Aug 20, 2024
7d41bd0
point to Origin
reuvenharrison Aug 21, 2024
77f909b
make include origin configurable
reuvenharrison Aug 22, 2024
15e7cab
generic unmarshalStringMap
reuvenharrison Aug 23, 2024
450e4d0
add origin to more components
reuvenharrison Aug 25, 2024
6b52b19
revert comments
reuvenharrison Aug 25, 2024
775ab17
use const originKey
reuvenharrison Aug 25, 2024
d241445
comment to Scopes
reuvenharrison Aug 26, 2024
206c1be
test more specs
reuvenharrison Aug 26, 2024
032ff76
Fix Discriminator
reuvenharrison Sep 17, 2024
4304772
update docs
reuvenharrison Sep 17, 2024
67ee9fa
test on a decent set of dedicated specs
reuvenharrison Sep 17, 2024
8095459
remove trainling spaces
reuvenharrison Sep 17, 2024
d24b68a
add comments
reuvenharrison Sep 17, 2024
c5cf284
remove trailing whitespace
reuvenharrison Sep 17, 2024
98ace80
update docs
reuvenharrison Sep 17, 2024
c981f30
dedicated tests
reuvenharrison Sep 17, 2024
6daf324
update docs
reuvenharrison Sep 17, 2024
17db6ab
remove whitespace
reuvenharrison Sep 17, 2024
015b63e
rm empty line
reuvenharrison Sep 17, 2024
34f95b7
rm last newline
reuvenharrison Sep 17, 2024
020e44b
add tests
reuvenharrison Sep 19, 2024
07a3b25
rm unused test files
reuvenharrison Sep 20, 2024
cba19cf
update deps
reuvenharrison Sep 20, 2024
2d5e393
fix paths test
reuvenharrison Sep 20, 2024
b9f7dd6
test components/security
reuvenharrison Sep 20, 2024
aa8c5b1
fix LF
reuvenharrison Sep 20, 2024
8a00ba0
include origin in unmarshal maps
reuvenharrison Sep 21, 2024
3aca4e0
move component unmarshallers to respective files
reuvenharrison Oct 14, 2024
7ea36a0
fix test (json-schema 301)
reuvenharrison Oct 14, 2024
929edf0
Add github.com/pb33f/libopenapi (#1004)
Jille Aug 22, 2024
d2c2b3c
Introduce an option to override the regex implementation (#1006)
alexbakker Aug 26, 2024
0125b1b
make form required field order deterministic (#1008)
jlsherrill Aug 30, 2024
45f4435
openapi2: fix un/marshalling discriminator field (#1011)
reversearrow Oct 1, 2024
cfdf905
README: add Fuego to dependents (#1017)
EwenQuim Oct 8, 2024
dd25946
openapi3: skip a test in CI to avoid 403s from some remote server (#1…
fenollp Oct 14, 2024
8113413
revert fix test (json-schema 301)
reuvenharrison Oct 16, 2024
4f2e185
openapi3: introduce StringMap type to enable unmarshalling of maps wi…
reuvenharrison Oct 16, 2024
e3b2867
add origin to more components
reuvenharrison Aug 25, 2024
3cba697
Fix Discriminator
reuvenharrison Sep 17, 2024
74dcf9e
update docs
reuvenharrison Sep 17, 2024
712c943
update doccs
reuvenharrison Oct 16, 2024
9aadd59
merge with stringmap
reuvenharrison Oct 16, 2024
184fa8c
remove unused Scopes
reuvenharrison Oct 16, 2024
5df8e49
Merge branch 'master' into master
reuvenharrison Oct 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 88 additions & 1 deletion .github/docs/openapi3.txt

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
module github.com/getkin/kin-openapi

go 1.20
go 1.22.5

replace gopkg.in/yaml.v3 => github.com/oasdiff/yaml3 v0.0.0-20240920135353-c185dc6ea7c6

replace github.com/invopop/yaml => github.com/oasdiff/yaml v0.0.0-20240920191703-3e5a9fb5bdf3

require (
github.com/go-openapi/jsonpointer v0.21.0
Expand Down
14 changes: 9 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,23 @@ github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kO
github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE=
github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ=
github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM=
github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/invopop/yaml v0.3.1 h1:f0+ZpmhfBSS4MhG+4HYseMdJhoeeopbSKbq5Rpeelso=
github.com/invopop/yaml v0.3.1/go.mod h1:PMOp3nn4/12yEZUFfmOuNHJsZToEEOwoWsT+D81KkeA=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
github.com/oasdiff/yaml v0.0.0-20240920191703-3e5a9fb5bdf3 h1:nqCxALSUgWobWkFGIrhLRzR/bpImQdGj+3JS4/scTJo=
github.com/oasdiff/yaml v0.0.0-20240920191703-3e5a9fb5bdf3/go.mod h1:AOyUNV9ElKz7EEZeBm/48U54UtjtgCMT9fFbZEsClQc=
github.com/oasdiff/yaml3 v0.0.0-20240920135353-c185dc6ea7c6 h1:+ZsuDTdapTJxfMQk7SOJiNMg0v36pui01L7FEO615r8=
github.com/oasdiff/yaml3 v0.0.0-20240920135353-c185dc6ea7c6/go.mod h1:lqlOfJRrYpgeWHQj+ky2tf7UJ3PzgHTHRQEpc90nbp0=
github.com/perimeterx/marshmallow v1.1.5 h1:a2LALqQ1BlHM8PZblsDdidgv1mWi1DgC2UmX50IvK2s=
github.com/perimeterx/marshmallow v1.1.5/go.mod h1:dsXbUu8CRzfYP5a87xpp0xq9S3u0Vchtcl8we9tYaXw=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand All @@ -26,7 +31,6 @@ github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
11 changes: 11 additions & 0 deletions maps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,17 @@ func (${name} ${type}) UnmarshalJSON(data []byte) (err error) {
continue
}

if k == originKey {
var data []byte
if data, err = json.Marshal(v); err != nil {
return
}
if err = json.Unmarshal(data, &x.Origin); err != nil {
return
}
continue
}

var data []byte
if data, err = json.Marshal(v); err != nil {
return
Expand Down
7 changes: 7 additions & 0 deletions openapi3/callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#callback-object
type Callback struct {
Extensions map[string]any `json:"-" yaml:"-"`
Origin *Origin `json:"origin,omitempty" yaml:"origin,omitempty"`

m map[string]*PathItem
}
Expand Down Expand Up @@ -52,3 +53,9 @@ func (callback *Callback) Validate(ctx context.Context, opts ...ValidationOption

return validateExtensions(ctx, callback.Extensions)
}

// UnmarshalJSON sets Callbacks to a copy of data.
func (callbacks *Callbacks) UnmarshalJSON(data []byte) (err error) {
*callbacks, _, err = unmarshalStringMapP[CallbackRef](data)
return
}
2 changes: 2 additions & 0 deletions openapi3/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type (
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#components-object
type Components struct {
Extensions map[string]any `json:"-" yaml:"-"`
Origin *Origin `json:"origin,omitempty" yaml:"origin,omitempty"`

Schemas Schemas `json:"schemas,omitempty" yaml:"schemas,omitempty"`
Parameters ParametersMap `json:"parameters,omitempty" yaml:"parameters,omitempty"`
Expand Down Expand Up @@ -94,6 +95,7 @@ func (components *Components) UnmarshalJSON(data []byte) error {
return unmarshalError(err)
}
_ = json.Unmarshal(data, &x.Extensions)
delete(x.Extensions, originKey)
delete(x.Extensions, "schemas")
delete(x.Extensions, "parameters")
delete(x.Extensions, "headers")
Expand Down
3 changes: 3 additions & 0 deletions openapi3/contact.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#contact-object
type Contact struct {
Extensions map[string]any `json:"-" yaml:"-"`
Origin *Origin `json:"origin,omitempty" yaml:"origin,omitempty"`

Name string `json:"name,omitempty" yaml:"name,omitempty"`
URL string `json:"url,omitempty" yaml:"url,omitempty"`
Expand Down Expand Up @@ -50,6 +51,8 @@ func (contact *Contact) UnmarshalJSON(data []byte) error {
return unmarshalError(err)
}
_ = json.Unmarshal(data, &x.Extensions)

delete(x.Extensions, originKey)
delete(x.Extensions, "name")
delete(x.Extensions, "url")
delete(x.Extensions, "email")
Expand Down
6 changes: 6 additions & 0 deletions openapi3/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,9 @@ 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
}
3 changes: 3 additions & 0 deletions openapi3/discriminator.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#discriminator-object
type Discriminator struct {
Extensions map[string]any `json:"-" yaml:"-"`
Origin *Origin `json:"origin,omitempty" yaml:"origin,omitempty"`

PropertyName string `json:"propertyName" yaml:"propertyName"` // required
Mapping StringMap `json:"mapping,omitempty" yaml:"mapping,omitempty"`
Expand Down Expand Up @@ -44,6 +45,8 @@ func (discriminator *Discriminator) UnmarshalJSON(data []byte) error {
return unmarshalError(err)
}
_ = json.Unmarshal(data, &x.Extensions)

delete(x.Extensions, originKey)
delete(x.Extensions, "propertyName")
delete(x.Extensions, "mapping")
if len(x.Extensions) == 0 {
Expand Down
3 changes: 3 additions & 0 deletions openapi3/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#encoding-object
type Encoding struct {
Extensions map[string]any `json:"-" yaml:"-"`
Origin *Origin `json:"origin,omitempty" yaml:"origin,omitempty"`

ContentType string `json:"contentType,omitempty" yaml:"contentType,omitempty"`
Headers Headers `json:"headers,omitempty" yaml:"headers,omitempty"`
Expand Down Expand Up @@ -80,6 +81,8 @@ func (encoding *Encoding) UnmarshalJSON(data []byte) error {
return unmarshalError(err)
}
_ = json.Unmarshal(data, &x.Extensions)

delete(x.Extensions, originKey)
delete(x.Extensions, "contentType")
delete(x.Extensions, "headers")
delete(x.Extensions, "style")
Expand Down
6 changes: 6 additions & 0 deletions openapi3/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,9 @@ func (example *Example) Validate(ctx context.Context, opts ...ValidationOption)

return validateExtensions(ctx, example.Extensions)
}

// UnmarshalJSON sets Examples to a copy of data.
func (examples *Examples) UnmarshalJSON(data []byte) (err error) {
*examples, _, err = unmarshalStringMapP[ExampleRef](data)
return
}
2 changes: 2 additions & 0 deletions openapi3/external_docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#external-documentation-object
type ExternalDocs struct {
Extensions map[string]any `json:"-" yaml:"-"`
Origin *Origin `json:"origin,omitempty" yaml:"origin,omitempty"`

Description string `json:"description,omitempty" yaml:"description,omitempty"`
URL string `json:"url,omitempty" yaml:"url,omitempty"`
Expand Down Expand Up @@ -49,6 +50,7 @@ func (e *ExternalDocs) UnmarshalJSON(data []byte) error {
return unmarshalError(err)
}
_ = json.Unmarshal(data, &x.Extensions)
delete(x.Extensions, originKey)
delete(x.Extensions, "description")
delete(x.Extensions, "url")
if len(x.Extensions) == 0 {
Expand Down
6 changes: 6 additions & 0 deletions openapi3/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,9 @@ 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
}
2 changes: 2 additions & 0 deletions openapi3/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#info-object
type Info struct {
Extensions map[string]any `json:"-" yaml:"-"`
Origin *Origin `json:"origin,omitempty" yaml:"origin,omitempty"`

Title string `json:"title" yaml:"title"` // Required
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Expand Down Expand Up @@ -62,6 +63,7 @@ func (info *Info) UnmarshalJSON(data []byte) error {
return unmarshalError(err)
}
_ = json.Unmarshal(data, &x.Extensions)
delete(x.Extensions, originKey)
delete(x.Extensions, "title")
delete(x.Extensions, "description")
delete(x.Extensions, "termsOfService")
Expand Down
2 changes: 2 additions & 0 deletions openapi3/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#license-object
type License struct {
Extensions map[string]any `json:"-" yaml:"-"`
Origin *Origin `json:"origin,omitempty" yaml:"origin,omitempty"`

Name string `json:"name" yaml:"name"` // Required
URL string `json:"url,omitempty" yaml:"url,omitempty"`
Expand Down Expand Up @@ -45,6 +46,7 @@ func (license *License) UnmarshalJSON(data []byte) error {
return unmarshalError(err)
}
_ = json.Unmarshal(data, &x.Extensions)
delete(x.Extensions, originKey)
delete(x.Extensions, "name")
delete(x.Extensions, "url")
if len(x.Extensions) == 0 {
Expand Down
9 changes: 9 additions & 0 deletions openapi3/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#link-object
type Link struct {
Extensions map[string]any `json:"-" yaml:"-"`
Origin *Origin `json:"origin,omitempty" yaml:"origin,omitempty"`

OperationRef string `json:"operationRef,omitempty" yaml:"operationRef,omitempty"`
OperationID string `json:"operationId,omitempty" yaml:"operationId,omitempty"`
Expand Down Expand Up @@ -66,6 +67,8 @@ func (link *Link) UnmarshalJSON(data []byte) error {
return unmarshalError(err)
}
_ = json.Unmarshal(data, &x.Extensions)

delete(x.Extensions, originKey)
delete(x.Extensions, "operationRef")
delete(x.Extensions, "operationId")
delete(x.Extensions, "description")
Expand All @@ -92,3 +95,9 @@ func (link *Link) Validate(ctx context.Context, opts ...ValidationOption) error

return validateExtensions(ctx, link.Extensions)
}

// UnmarshalJSON sets Links to a copy of data.
func (links *Links) UnmarshalJSON(data []byte) (err error) {
*links, _, err = unmarshalStringMapP[LinkRef](data)
return
}
11 changes: 7 additions & 4 deletions openapi3/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ type Loader struct {
// IsExternalRefsAllowed enables visiting other files
IsExternalRefsAllowed bool

// IncludeOrigin specifies whether to include the origin of the OpenAPI elements
IncludeOrigin bool

// ReadFromURIFunc allows overriding the any file/URL reading func
ReadFromURIFunc ReadFromURIFunc

Expand Down Expand Up @@ -103,7 +106,7 @@ func (loader *Loader) loadSingleElementFromURI(ref string, rootPath *url.URL, el
if err != nil {
return nil, err
}
if err := unmarshal(data, element); err != nil {
if err := unmarshal(data, element, loader.IncludeOrigin); err != nil {
return nil, err
}

Expand Down Expand Up @@ -139,7 +142,7 @@ func (loader *Loader) LoadFromIoReader(reader io.Reader) (*T, error) {
func (loader *Loader) LoadFromData(data []byte) (*T, error) {
loader.resetVisitedPathItemRefs()
doc := &T{}
if err := unmarshal(data, doc); err != nil {
if err := unmarshal(data, doc, loader.IncludeOrigin); err != nil {
return nil, err
}
if err := loader.ResolveRefsIn(doc, nil); err != nil {
Expand Down Expand Up @@ -168,7 +171,7 @@ func (loader *Loader) loadFromDataWithPathInternal(data []byte, location *url.UR
doc := &T{}
loader.visitedDocuments[uri] = doc

if err := unmarshal(data, doc); err != nil {
if err := unmarshal(data, doc, loader.IncludeOrigin); err != nil {
return nil, err
}

Expand Down Expand Up @@ -422,7 +425,7 @@ func (loader *Loader) resolveComponent(doc *T, ref string, path *url.URL, resolv
if err2 != nil {
return nil, nil, err
}
if err2 = unmarshal(data, &cursor); err2 != nil {
if err2 = unmarshal(data, &cursor, loader.IncludeOrigin); err2 != nil {
return nil, nil, err
}
if cursor, err2 = drill(cursor); err2 != nil || cursor == nil {
Expand Down
33 changes: 33 additions & 0 deletions openapi3/maplike.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,17 @@ func (responses *Responses) UnmarshalJSON(data []byte) (err error) {
continue
}

if k == originKey {
var data []byte
if data, err = json.Marshal(v); err != nil {
return
}
if err = json.Unmarshal(data, &x.Origin); err != nil {
return
}
continue
}

var data []byte
if data, err = json.Marshal(v); err != nil {
return
Expand Down Expand Up @@ -256,6 +267,17 @@ func (callback *Callback) UnmarshalJSON(data []byte) (err error) {
continue
}

if k == originKey {
var data []byte
if data, err = json.Marshal(v); err != nil {
return
}
if err = json.Unmarshal(data, &x.Origin); err != nil {
return
}
continue
}

var data []byte
if data, err = json.Marshal(v); err != nil {
return
Expand Down Expand Up @@ -387,6 +409,17 @@ func (paths *Paths) UnmarshalJSON(data []byte) (err error) {
continue
}

if k == originKey {
var data []byte
if data, err = json.Marshal(v); err != nil {
return
}
if err = json.Unmarshal(data, &x.Origin); err != nil {
return
}
continue
}

var data []byte
if data, err = json.Marshal(v); err != nil {
return
Expand Down
4 changes: 2 additions & 2 deletions openapi3/marsh.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func unmarshalError(jsonUnmarshalErr error) error {
return jsonUnmarshalErr
}

func unmarshal(data []byte, v any) error {
func unmarshal(data []byte, v any, includeOrigin bool) error {
var jsonErr, yamlErr error

// See https://github.com/getkin/kin-openapi/issues/680
Expand All @@ -25,7 +25,7 @@ func unmarshal(data []byte, v any) error {
}

// UnmarshalStrict(data, v) TODO: investigate how ymlv3 handles duplicate map keys
if yamlErr = yaml.Unmarshal(data, v); yamlErr == nil {
if yamlErr = yaml.UnmarshalWithOrigin(data, v, includeOrigin); yamlErr == nil {
return nil
}

Expand Down
2 changes: 2 additions & 0 deletions openapi3/media_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#media-type-object
type MediaType struct {
Extensions map[string]any `json:"-" yaml:"-"`
Origin *Origin `json:"origin,omitempty" yaml:"origin,omitempty"`

Schema *SchemaRef `json:"schema,omitempty" yaml:"schema,omitempty"`
Example any `json:"example,omitempty" yaml:"example,omitempty"`
Expand Down Expand Up @@ -101,6 +102,7 @@ func (mediaType *MediaType) UnmarshalJSON(data []byte) error {
return unmarshalError(err)
}
_ = json.Unmarshal(data, &x.Extensions)
delete(x.Extensions, originKey)
delete(x.Extensions, "schema")
delete(x.Extensions, "example")
delete(x.Extensions, "examples")
Expand Down
Loading
Loading