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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
point to Origin
  • Loading branch information
reuvenharrison committed Aug 21, 2024
commit 7d41bd043950dffdb888a53d2b38f2a592876e6b
2 changes: 1 addition & 1 deletion openapi3/callback.go
Original file line number Diff line number Diff line change
@@ -9,7 +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:"-" yaml:"-"`
Origin *Origin `json:"origin,omitempty" yaml:"origin,omitempty"`

m map[string]*PathItem
}
102 changes: 102 additions & 0 deletions openapi3/components.go
Original file line number Diff line number Diff line change
@@ -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"`
@@ -94,6 +95,7 @@ func (components *Components) UnmarshalJSON(data []byte) error {
return unmarshalError(err)
}
_ = json.Unmarshal(data, &x.Extensions)
delete(x.Extensions, "origin")
delete(x.Extensions, "schemas")
delete(x.Extensions, "parameters")
delete(x.Extensions, "headers")
@@ -110,6 +112,106 @@ func (components *Components) UnmarshalJSON(data []byte) error {
return nil
}

// TODO: replace these unmarshallers with a generic one
func (callbacks *Callbacks) UnmarshalJSON(data []byte) error {
type CallbacksBis Callbacks
var x CallbacksBis
if err := json.Unmarshal(data, &x); err != nil {
return unmarshalError(err)
}
delete(x, "origin")
*callbacks = Callbacks(x)
return nil
}

func (examples *Examples) UnmarshalJSON(data []byte) error {
type ExamplesBis Examples
var x ExamplesBis
if err := json.Unmarshal(data, &x); err != nil {
return unmarshalError(err)
}
delete(x, "origin")
*examples = Examples(x)
return nil
}

func (headers *Headers) UnmarshalJSON(data []byte) error {
type HeadersBis Headers
var x HeadersBis
if err := json.Unmarshal(data, &x); err != nil {
return unmarshalError(err)
}
delete(x, "origin")
*headers = Headers(x)
return nil
}

func (links *Links) UnmarshalJSON(data []byte) error {
type LinksBis Links
var x LinksBis
if err := json.Unmarshal(data, &x); err != nil {
return unmarshalError(err)
}
delete(x, "origin")
*links = Links(x)
return nil
}

func (parametersMap *ParametersMap) UnmarshalJSON(data []byte) error {
type ParametersMapBis ParametersMap
var x ParametersMapBis
if err := json.Unmarshal(data, &x); err != nil {
return unmarshalError(err)
}
delete(x, "origin")
*parametersMap = ParametersMap(x)
return nil
}

func (requestBodies *RequestBodies) UnmarshalJSON(data []byte) error {
type RequestBodiesBis RequestBodies
var x RequestBodiesBis
if err := json.Unmarshal(data, &x); err != nil {
return unmarshalError(err)
}
delete(x, "origin")
*requestBodies = RequestBodies(x)
return nil
}

func (responseBodies *ResponseBodies) UnmarshalJSON(data []byte) error {
type ResponseBodiesBis ResponseBodies
var x ResponseBodiesBis
if err := json.Unmarshal(data, &x); err != nil {
return unmarshalError(err)
}
delete(x, "origin")
*responseBodies = ResponseBodies(x)
return nil
}

func (schemas *Schemas) UnmarshalJSON(data []byte) error {
type SchemasBis Schemas
var x SchemasBis
if err := json.Unmarshal(data, &x); err != nil {
return unmarshalError(err)
}
delete(x, "origin")
*schemas = Schemas(x)
return nil
}

func (securitySchemes *SecuritySchemes) UnmarshalJSON(data []byte) error {
type SecuritySchemesBis SecuritySchemes
var x SecuritySchemesBis
if err := json.Unmarshal(data, &x); err != nil {
return unmarshalError(err)
}
delete(x, "origin")
*securitySchemes = SecuritySchemes(x)
return nil
}

// 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...)
2 changes: 1 addition & 1 deletion openapi3/info.go
Original file line number Diff line number Diff line change
@@ -10,7 +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"`
Origin *Origin `json:"origin,omitempty" yaml:"origin,omitempty"`

Title string `json:"title" yaml:"title"` // Required
Description string `json:"description,omitempty" yaml:"description,omitempty"`
2 changes: 2 additions & 0 deletions openapi3/license.go
Original file line number Diff line number Diff line change
@@ -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"`
@@ -45,6 +46,7 @@ func (license *License) UnmarshalJSON(data []byte) error {
return unmarshalError(err)
}
_ = json.Unmarshal(data, &x.Extensions)
delete(x.Extensions, "origin")
delete(x.Extensions, "name")
delete(x.Extensions, "url")
if len(x.Extensions) == 0 {
2 changes: 1 addition & 1 deletion openapi3/media_type.go
Original file line number Diff line number Diff line change
@@ -14,7 +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"`
Origin *Origin `json:"origin,omitempty" yaml:"origin,omitempty"`

Schema *SchemaRef `json:"schema,omitempty" yaml:"schema,omitempty"`
Example any `json:"example,omitempty" yaml:"example,omitempty"`
2 changes: 1 addition & 1 deletion openapi3/operation.go
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ import (
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#operation-object
type Operation struct {
Extensions map[string]any `json:"-" yaml:"-"`
Origin Origin `json:"origin,omitempty" yaml:"origin,omitempty"`
Origin *Origin `json:"origin,omitempty" yaml:"origin,omitempty"`

// Optional tags for documentation.
Tags []string `json:"tags,omitempty" yaml:"tags,omitempty"`
2 changes: 1 addition & 1 deletion openapi3/origin.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package openapi3

type Origin struct {
Key Location `json:"key,omitempty" yaml:"key,omitempty"`
Key *Location `json:"key,omitempty" yaml:"key,omitempty"`
Fields map[string]Location `json:"fields,omitempty" yaml:"fields,omitempty"`
}

2 changes: 1 addition & 1 deletion openapi3/parameter.go
Original file line number Diff line number Diff line change
@@ -73,7 +73,7 @@ func (parameters Parameters) Validate(ctx context.Context, opts ...ValidationOpt
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameter-object
type Parameter struct {
Extensions map[string]any `json:"-" yaml:"-"`
Origin Origin `json:"origin,omitempty" yaml:"origin,omitempty"`
Origin *Origin `json:"origin,omitempty" yaml:"origin,omitempty"`

Name string `json:"name,omitempty" yaml:"name,omitempty"`
In string `json:"in,omitempty" yaml:"in,omitempty"`
2 changes: 1 addition & 1 deletion openapi3/path_item.go
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ import (
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#path-item-object
type PathItem struct {
Extensions map[string]any `json:"-" yaml:"-"`
Origin Origin `json:"origin,omitempty" yaml:"origin,omitempty"`
Origin *Origin `json:"origin,omitempty" yaml:"origin,omitempty"`

Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty"`
Summary string `json:"summary,omitempty" yaml:"summary,omitempty"`
2 changes: 1 addition & 1 deletion openapi3/paths.go
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ import (
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#paths-object
type Paths struct {
Extensions map[string]any `json:"-" yaml:"-"`
Origin Origin `json:"-" yaml:"-"`
Origin *Origin `json:"origin,omitempty" yaml:"origin,omitempty"`

m map[string]*PathItem
}
4 changes: 2 additions & 2 deletions openapi3/ref.go
Original file line number Diff line number Diff line change
@@ -5,6 +5,6 @@ package openapi3
// Ref is specified by OpenAPI/Swagger 3.0 standard.
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#reference-object
type Ref struct {
Ref string `json:"$ref" yaml:"$ref"`
Origin Origin `json:"origin,omitempty" yaml:"origin,omitempty"`
Ref string `json:"$ref" yaml:"$ref"`
Origin *Origin `json:"origin,omitempty" yaml:"origin,omitempty"`
}
18 changes: 9 additions & 9 deletions openapi3/refs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion openapi3/refs.tmpl
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ type {{ $type.Name }}Ref struct {
// Extensions only captures fields starting with 'x-' as no other fields
// are allowed by the openapi spec.
Extensions map[string]any
Origin Origin
Origin *Origin

Ref string
Value *{{ $type.Name }}
2 changes: 1 addition & 1 deletion openapi3/request_body.go
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ import (
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#request-body-object
type RequestBody struct {
Extensions map[string]any `json:"-" yaml:"-"`
Origin Origin `json:"origin,omitempty" yaml:"origin,omitempty"`
Origin *Origin `json:"origin,omitempty" yaml:"origin,omitempty"`

Description string `json:"description,omitempty" yaml:"description,omitempty"`
Required bool `json:"required,omitempty" yaml:"required,omitempty"`
4 changes: 2 additions & 2 deletions openapi3/response.go
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ import (
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#responses-object
type Responses struct {
Extensions map[string]any `json:"-" yaml:"-"`
Origin Origin `json:"-" yaml:"-"`
Origin *Origin `json:"-" yaml:"-"`

m map[string]*ResponseRef
}
@@ -103,7 +103,7 @@ func (responses *Responses) Validate(ctx context.Context, opts ...ValidationOpti
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#response-object
type Response struct {
Extensions map[string]any `json:"-" yaml:"-"`
Origin Origin `json:"origin,omitempty" yaml:"origin,omitempty"`
Origin *Origin `json:"origin,omitempty" yaml:"origin,omitempty"`

Description *string `json:"description,omitempty" yaml:"description,omitempty"`
Headers Headers `json:"headers,omitempty" yaml:"headers,omitempty"`
2 changes: 1 addition & 1 deletion openapi3/schema.go
Original file line number Diff line number Diff line change
@@ -82,7 +82,7 @@ func (s SchemaRefs) JSONLookup(token string) (any, error) {
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schema-object
type Schema struct {
Extensions map[string]any `json:"-" yaml:"-"`
Origin Origin `json:"origin,omitempty" yaml:"origin,omitempty"`
Origin *Origin `json:"origin,omitempty" yaml:"origin,omitempty"`

OneOf SchemaRefs `json:"oneOf,omitempty" yaml:"oneOf,omitempty"`
AnyOf SchemaRefs `json:"anyOf,omitempty" yaml:"anyOf,omitempty"`