spectrum
spectrum copied to clipboard
Breaking changes in `kin-openapi` v0.124.0 - change of type definition
From go test
. Appears that Types
has changed types to github.com/getkin/kin-openapi/openapi3.Types
from string
:
openapi3/visit.go:29:5: cannot use propRef.Value.Type (variable of type *"github.com/getkin/kin-openapi/openapi3".Types) as string value in argument to visitTypeFormat
openapi3/visit.go:41:4: cannot use paramRef.Value.Schema.Value.Type (variable of type *"github.com/getkin/kin-openapi/openapi3".Types) as string value in argument to visitTypeFormat
openapi3/visit.go:59:6: cannot use paramRef.Value.Schema.Value.Type (variable of type *"github.com/getkin/kin-openapi/openapi3".Types) as string value in argument to visitTypeFormat
Definition for github.com/getkin/kin-openapi/openapi3.Types
is here:
https://pkg.go.dev/github.com/getkin/[email protected]/openapi3#Types
Definition for Schema.Type
is as follows:
v0.124.0
Type *Types `json:"type,omitempty" yaml:"type,omitempty"`
Types
is a []string
:
type Types []string
https://pkg.go.dev/github.com/getkin/[email protected]/openapi3#Schema
v0.123.0
Type string `json:"type,omitempty" yaml:"type,omitempty"`
https://pkg.go.dev/github.com/getkin/[email protected]/openapi3#Schema
Upstream merge links:
- https://github.com/getkin/kin-openapi/pull/912
- https://github.com/getkin/kin-openapi/pull/921
Additional discussion links:
- https://github.com/mattpolzin/OpenAPIKit/pull/356
- OpenAPI Specification plugin erroneously requires schema type field to be an array when OpenAPI version is 3.1.0 youtrack.jetbrains.com/issue/IJPL-63311
Spec discussion:
https://github.com/getkin/kin-openapi/issues/563
In OpenAPIv3.0 type can only take a single string value per https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#properties
In OAS 3.0.3:
https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#properties
The following properties are taken from the JSON Schema definition but their definitions were adjusted to the OpenAPI Specification.
- type - Value MUST be a string. Multiple types via an array are not supported.
This is no longer the case in OAS 3.1.0.
This issue:
https://github.com/getkin/kin-openapi/issues/563
Mentions this YAML impelmentation:
'Legal in v2':
type: [boolean, string]
'Legal in v3.0':
oneOf:
- {type: boolean}
- {type: string}
It is best to validate that downstream tools like OpenAPI Generator, Docusaurus, Redoc and others behave as expected given use of oneOf
.
oapi-codegen
PR changes for reference: https://github.com/oapi-codegen/oapi-codegen/pull/1532/files