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 29 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
105 changes: 98 additions & 7 deletions .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
1 change: 1 addition & 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
56 changes: 56 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 All @@ -110,6 +112,60 @@ func (components *Components) UnmarshalJSON(data []byte) error {
return nil
}

// UnmarshalJSON sets Callbacks to a copy of data.
func (callbacks *Callbacks) UnmarshalJSON(data []byte) (err error) {
*callbacks, _, err = unmarshalStringMapP[CallbackRef](data)
return
}

// UnmarshalJSON sets Examples to a copy of data.
func (examples *Examples) UnmarshalJSON(data []byte) (err error) {
*examples, _, err = unmarshalStringMapP[ExampleRef](data)
return
}

// UnmarshalJSON sets Headers to a copy of data.
func (headers *Headers) UnmarshalJSON(data []byte) (err error) {
*headers, _, err = unmarshalStringMapP[HeaderRef](data)
return
}

// UnmarshalJSON sets Links to a copy of data.
func (links *Links) UnmarshalJSON(data []byte) (err error) {
*links, _, err = unmarshalStringMapP[LinkRef](data)
return
}

// UnmarshalJSON sets ParametersMap to a copy of data.
func (parametersMap *ParametersMap) UnmarshalJSON(data []byte) (err error) {
*parametersMap, _, err = unmarshalStringMapP[ParameterRef](data)
return
}

// UnmarshalJSON sets RequestBodies to a copy of data.
func (requestBodies *RequestBodies) UnmarshalJSON(data []byte) (err error) {
*requestBodies, _, err = unmarshalStringMapP[RequestBodyRef](data)
return
}

// UnmarshalJSON sets ResponseBodies to a copy of data.
func (responseBodies *ResponseBodies) UnmarshalJSON(data []byte) (err error) {
*responseBodies, _, err = unmarshalStringMapP[ResponseRef](data)
return
}

// UnmarshalJSON sets Schemas to a copy of data.
func (schemas *Schemas) UnmarshalJSON(data []byte) (err error) {
*schemas, _, err = unmarshalStringMapP[SchemaRef](data)
return
}

// UnmarshalJSON sets SecuritySchemes to a copy of data.
func (securitySchemes *SecuritySchemes) UnmarshalJSON(data []byte) (err error) {
*securitySchemes, _, err = unmarshalStringMapP[SecuritySchemeRef](data)
return
}
fenollp marked this conversation as resolved.
Show resolved Hide resolved

// Validate returns an error if Components does not comply with the OpenAPI spec.
func (components *Components) Validate(ctx context.Context, opts ...ValidationOption) (err error) {
ctx = WithValidationOptions(ctx, opts...)
Expand Down
2 changes: 2 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,7 @@ 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
}
6 changes: 4 additions & 2 deletions openapi3/discriminator.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ 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 map[string]string `json:"mapping,omitempty" yaml:"mapping,omitempty"`
PropertyName string `json:"propertyName" yaml:"propertyName"` // required
Mapping StringMap `json:"mapping,omitempty" yaml:"mapping,omitempty"`
fenollp marked this conversation as resolved.
Show resolved Hide resolved
}

// MarshalJSON returns the JSON encoding of Discriminator.
Expand Down Expand Up @@ -44,6 +45,7 @@ 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
2 changes: 2 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,7 @@ 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
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
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
2 changes: 2 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,7 @@ 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 Down
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
Loading
Loading