spectrum icon indicating copy to clipboard operation
spectrum copied to clipboard

Breaking changes in `kin-openapi` v0.124.0 - change of type definition

Open grokify opened this issue 10 months ago • 5 comments

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

grokify avatar Apr 07 '24 12:04 grokify

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

grokify avatar Apr 07 '24 13:04 grokify

Upstream merge links:

  1. https://github.com/getkin/kin-openapi/pull/912
  2. https://github.com/getkin/kin-openapi/pull/921

Additional discussion links:

  1. https://github.com/mattpolzin/OpenAPIKit/pull/356
  2. 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

grokify avatar Apr 15 '24 07:04 grokify

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}

grokify avatar Apr 15 '24 08:04 grokify

It is best to validate that downstream tools like OpenAPI Generator, Docusaurus, Redoc and others behave as expected given use of oneOf.

grokify avatar Apr 15 '24 08:04 grokify

oapi-codegen PR changes for reference: https://github.com/oapi-codegen/oapi-codegen/pull/1532/files

grokify avatar Jun 16 '24 16:06 grokify