diff --git a/.github/docs/openapi3.txt b/.github/docs/openapi3.txt index 993d2da1..71945408 100644 --- a/.github/docs/openapi3.txt +++ b/.github/docs/openapi3.txt @@ -184,6 +184,10 @@ func (callback *Callback) Value(key string) *PathItem Value returns the callback for key or nil type CallbackRef struct { + // Extensions only captures fields starting with 'x-' as no other fields + // are allowed by the openapi spec. + Extensions map[string]interface{} + Ref string Value *Callback // Has unexported fields. @@ -357,6 +361,10 @@ func (example *Example) Validate(ctx context.Context, opts ...ValidationOption) Validate returns an error if Example does not comply with the OpenAPI spec. type ExampleRef struct { + // Extensions only captures fields starting with 'x-' as no other fields + // are allowed by the openapi spec. + Extensions map[string]interface{} + Ref string Value *Example // Has unexported fields. @@ -441,6 +449,10 @@ func (header *Header) Validate(ctx context.Context, opts ...ValidationOption) er Validate returns an error if Header does not comply with the OpenAPI spec. type HeaderRef struct { + // Extensions only captures fields starting with 'x-' as no other fields + // are allowed by the openapi spec. + Extensions map[string]interface{} + Ref string Value *Header // Has unexported fields. @@ -534,6 +546,10 @@ func (link *Link) Validate(ctx context.Context, opts ...ValidationOption) error Validate returns an error if Link does not comply with the OpenAPI spec. type LinkRef struct { + // Extensions only captures fields starting with 'x-' as no other fields + // are allowed by the openapi spec. + Extensions map[string]interface{} + Ref string Value *Link // Has unexported fields. @@ -830,6 +846,10 @@ func (parameter *Parameter) WithRequired(value bool) *Parameter func (parameter *Parameter) WithSchema(value *Schema) *Parameter type ParameterRef struct { + // Extensions only captures fields starting with 'x-' as no other fields + // are allowed by the openapi spec. + Extensions map[string]interface{} + Ref string Value *Parameter // Has unexported fields. @@ -1057,6 +1077,10 @@ func (requestBody *RequestBody) WithSchema(value *Schema, consumes []string) *Re func (requestBody *RequestBody) WithSchemaRef(value *SchemaRef, consumes []string) *RequestBody type RequestBodyRef struct { + // Extensions only captures fields starting with 'x-' as no other fields + // are allowed by the openapi spec. + Extensions map[string]interface{} + Ref string Value *RequestBody // Has unexported fields. @@ -1118,6 +1142,10 @@ func (m ResponseBodies) JSONLookup(token string) (interface{}, error) https://pkg.go.dev/github.com/go-openapi/jsonpointer#JSONPointable type ResponseRef struct { + // Extensions only captures fields starting with 'x-' as no other fields + // are allowed by the openapi spec. + Extensions map[string]interface{} + Ref string Value *Response // Has unexported fields. @@ -1410,6 +1438,10 @@ func (err *SchemaError) JSONPointer() []string func (err SchemaError) Unwrap() error type SchemaRef struct { + // Extensions only captures fields starting with 'x-' as no other fields + // are allowed by the openapi spec. + Extensions map[string]interface{} + Ref string Value *Schema // Has unexported fields. @@ -1556,6 +1588,10 @@ func (ss *SecurityScheme) WithScheme(value string) *SecurityScheme func (ss *SecurityScheme) WithType(value string) *SecurityScheme type SecuritySchemeRef struct { + // Extensions only captures fields starting with 'x-' as no other fields + // are allowed by the openapi spec. + Extensions map[string]interface{} + Ref string Value *SecurityScheme // Has unexported fields. @@ -1753,6 +1789,12 @@ type ValidationOption func(options *ValidationOptions) ValidationOption allows the modification of how the OpenAPI document is validated. +func AllowExtensionsWithRef() ValidationOption + AllowExtensionsWithRef allows extensions (fields starting with 'x-') as + siblings for $ref fields. This is the default. Non-extension fields are + prohibited unless allowed explicitly with the AllowExtraSiblingFields + option. + func AllowExtraSiblingFields(fields ...string) ValidationOption AllowExtraSiblingFields called as AllowExtraSiblingFields("description") makes Validate not return an error when said field appears next to a $ref. @@ -1793,6 +1835,12 @@ func EnableSchemaPatternValidation() ValidationOption DisableSchemaPatternValidation. By default, schema pattern validation is enabled. +func ProhibitExtensionsWithRef() ValidationOption + ProhibitExtensionsWithRef causes the validation to return an error if + extensions (fields starting with 'x-') are found as siblings for $ref + fields. Non-extension fields are prohibited unless allowed explicitly with + the AllowExtraSiblingFields option. + type ValidationOptions struct { // Has unexported fields. } diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index acb3a0f0..2604468b 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -55,6 +55,9 @@ jobs: - run: ./refs.sh | tee openapi3/refs.go - run: git --no-pager diff --exit-code + - run: ./refs_test.sh | tee openapi3/refs_test.go + - run: git --no-pager diff --exit-code + - run: ./maps.sh - run: git --no-pager diff --exit-code