Skip to content

Cannot generate when OpenAPI is written in YAML 1.2 #257

@stellirin

Description

@stellirin

OpenAPI recommends using YAML 1.2 where one of the differences is a smaller range of allowed strings to represent a boolean.

We have an API in production with something like:

/v1/image/{x}/{y}.png:
  parameters:
    - name: x
      in: path
      required: true
      schema:
        type: number
    - name: y
      in: path
      required: true
      schema:
        type: number

Where the y is a string. We use x and y here to represent coordinates. The oapi-codegen tool does not parse this, it sees the y as a boolean. The API is parsed correctly by other libraries.

error loading swagger spec
: error unmarshaling JSON: Error while unmarshalling property 'paths' (*openapi3.Paths): Error while unmarshalling property 'parameters' (*openapi3.Parameters): Error while unmarshalling property 'name' (*string): json: cannot unmarshal bool into Go value of type string
make: *** [Makefile:19: openapi] Error 1

This is (probably) because of a dependency on gopkg.in/yaml.v2 both directly and indirectly via github.com/getkin/kin-openapi => github.com/ghodss/yaml => gopkg.in/yaml.v2.

YAML 1.2 is not supported in v2 of this library. Support for YAML 1.2 was added in v3.

I attempted to switch everything to use v3, and it does compile, but I got the same error. Perhaps I missed some use of v2 somewhere. Unfortunately I don't have much more time to spend on this because I can simply put the y in quotes and it will compile.

However it would be nice to consume our production APIs without the need to modify them first!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions