Skip to content

Commit 57624b3

Browse files
authored
openapi3: allow Extensions next to $ref in SchemaRef (#901)
1 parent 7ec3129 commit 57624b3

File tree

9 files changed

+1219
-365
lines changed

9 files changed

+1219
-365
lines changed

.github/docs/openapi3.txt

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,10 @@ func (callback *Callback) Value(key string) *PathItem
231231
Value returns the callback for key or nil
232232

233233
type CallbackRef struct {
234+
// Extensions only captures fields starting with 'x-' as no other fields
235+
// are allowed by the openapi spec.
236+
Extensions map[string]any
237+
234238
Ref string
235239
Value *Callback
236240

@@ -430,6 +434,10 @@ func (example *Example) Validate(ctx context.Context, opts ...ValidationOption)
430434
Validate returns an error if Example does not comply with the OpenAPI spec.
431435

432436
type ExampleRef struct {
437+
// Extensions only captures fields starting with 'x-' as no other fields
438+
// are allowed by the openapi spec.
439+
Extensions map[string]any
440+
433441
Ref string
434442
Value *Example
435443

@@ -528,6 +536,10 @@ func (header *Header) Validate(ctx context.Context, opts ...ValidationOption) er
528536
Validate returns an error if Header does not comply with the OpenAPI spec.
529537

530538
type HeaderRef struct {
539+
// Extensions only captures fields starting with 'x-' as no other fields
540+
// are allowed by the openapi spec.
541+
Extensions map[string]any
542+
531543
Ref string
532544
Value *Header
533545

@@ -641,6 +653,10 @@ func (link *Link) Validate(ctx context.Context, opts ...ValidationOption) error
641653
Validate returns an error if Link does not comply with the OpenAPI spec.
642654

643655
type LinkRef struct {
656+
// Extensions only captures fields starting with 'x-' as no other fields
657+
// are allowed by the openapi spec.
658+
Extensions map[string]any
659+
644660
Ref string
645661
Value *Link
646662

@@ -963,6 +979,10 @@ func (parameter *Parameter) WithRequired(value bool) *Parameter
963979
func (parameter *Parameter) WithSchema(value *Schema) *Parameter
964980

965981
type ParameterRef struct {
982+
// Extensions only captures fields starting with 'x-' as no other fields
983+
// are allowed by the openapi spec.
984+
Extensions map[string]any
985+
966986
Ref string
967987
Value *Parameter
968988

@@ -1207,6 +1227,10 @@ func (requestBody *RequestBody) WithSchema(value *Schema, consumes []string) *Re
12071227
func (requestBody *RequestBody) WithSchemaRef(value *SchemaRef, consumes []string) *RequestBody
12081228

12091229
type RequestBodyRef struct {
1230+
// Extensions only captures fields starting with 'x-' as no other fields
1231+
// are allowed by the openapi spec.
1232+
Extensions map[string]any
1233+
12101234
Ref string
12111235
Value *RequestBody
12121236

@@ -1282,6 +1306,10 @@ func (m ResponseBodies) JSONLookup(token string) (any, error)
12821306
https://pkg.go.dev/github.com/go-openapi/jsonpointer#JSONPointable
12831307

12841308
type ResponseRef struct {
1309+
// Extensions only captures fields starting with 'x-' as no other fields
1310+
// are allowed by the openapi spec.
1311+
Extensions map[string]any
1312+
12851313
Ref string
12861314
Value *Response
12871315

@@ -1588,6 +1616,10 @@ func (err *SchemaError) JSONPointer() []string
15881616
func (err SchemaError) Unwrap() error
15891617

15901618
type SchemaRef struct {
1619+
// Extensions only captures fields starting with 'x-' as no other fields
1620+
// are allowed by the openapi spec.
1621+
Extensions map[string]any
1622+
15911623
Ref string
15921624
Value *Schema
15931625

@@ -1748,6 +1780,10 @@ func (ss *SecurityScheme) WithScheme(value string) *SecurityScheme
17481780
func (ss *SecurityScheme) WithType(value string) *SecurityScheme
17491781

17501782
type SecuritySchemeRef struct {
1783+
// Extensions only captures fields starting with 'x-' as no other fields
1784+
// are allowed by the openapi spec.
1785+
Extensions map[string]any
1786+
17511787
Ref string
17521788
Value *SecurityScheme
17531789

@@ -1968,6 +2004,12 @@ type ValidationOption func(options *ValidationOptions)
19682004
ValidationOption allows the modification of how the OpenAPI document is
19692005
validated.
19702006

2007+
func AllowExtensionsWithRef() ValidationOption
2008+
AllowExtensionsWithRef allows extensions (fields starting with 'x-') as
2009+
siblings for $ref fields. This is the default. Non-extension fields are
2010+
prohibited unless allowed explicitly with the AllowExtraSiblingFields
2011+
option.
2012+
19712013
func AllowExtraSiblingFields(fields ...string) ValidationOption
19722014
AllowExtraSiblingFields called as AllowExtraSiblingFields("description")
19732015
makes Validate not return an error when said field appears next to a $ref.
@@ -2008,6 +2050,12 @@ func EnableSchemaPatternValidation() ValidationOption
20082050
DisableSchemaPatternValidation. By default, schema pattern validation is
20092051
enabled.
20102052

2053+
func ProhibitExtensionsWithRef() ValidationOption
2054+
ProhibitExtensionsWithRef causes the validation to return an error if
2055+
extensions (fields starting with 'x-') are found as siblings for $ref
2056+
fields. Non-extension fields are prohibited unless allowed explicitly with
2057+
the AllowExtraSiblingFields option.
2058+
20112059
type ValidationOptions struct {
20122060
// Has unexported fields.
20132061
}

0 commit comments

Comments
 (0)