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!
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:
Where the
yis a string. We usexandyhere to represent coordinates. Theoapi-codegentool does not parse this, it sees theyas a boolean. The API is parsed correctly by other libraries.This is (probably) because of a dependency on
gopkg.in/yaml.v2both directly and indirectly viagithub.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
yin quotes and it will compile.However it would be nice to consume our production APIs without the need to modify them first!