openapi-generator: [BUG] 5.0.0 breaks generator if servers url relative
Hi recently switch from openapi-generator-maven-plugin@4.3.1 to 5.0.0 and the generation of my swagger did not work anymore.
After hours of search, I finaly found that it was mu servers > url value that breaked the generation. Of course my swagger is valid according to https://apitools.dev/swagger-parser/online/ (and many others). And also specification : https://swagger.io/specification/#server-object
| Field Name | Type | Description |
|---|---|---|
| url | string | REQUIRED. A URL to the target host. This URL supports Server Variables and MAY be relative |
Step to reproduce :
Take the classic petstore : https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml Change
servers:
- url: http://petstore.swagger.io/v1
To
servers:
- url: /v1
Run
java -jar openapi-generator-cli.jar generate -i <path_to/petstore.yaml> -g spring
Breaks with error (unclear at all)
com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'openapi': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
I guess it breaks all generator cause it also break validate command.
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 9
- Comments: 16 (6 by maintainers)
Commits related to this issue
- Update api.yaml It should work better like that, it looks like you encountered issue #8266 https://github.com/OpenAPITools/openapi-generator/issues/8266 — committed to selliera/openapi-generator-maven-plugin-test by selliera 3 years ago
- Bump swagger-parser to 2.0.26 Fixes #8260, #8266 — committed to marcelstoer/openapi-generator by marcelstoer 3 years ago
- Absolute servers url, workaround for Windows "[BUG] openapi-generator-maven-plugin version 5.0.0 does not work for OpenApi 3.0 yml-files" https://github.com/OpenAPITools/openapi-generator/issues/8260... — committed to julianladisch/mod-password-validator by julianladisch 3 years ago
I think this is the underlying cause: https://github.com/swagger-api/swagger-parser/issues/1553
What is the usual timeframe for making a new release of
openapi-generatorin maven repositories which includes the fix shipped in https://github.com/swagger-api/swagger-parser/issues/1553? Is this considered critical enough to warant a quick release for the team? (cc @wing328 as I see the user in the Github releases page)As currently this breaks builds for our Windows developers without involving and running the maven target for openapi-generator under WSL2 in Windows after we upgraded from 4.3.1 to 5.1.0.
Thanks @jhannes for finding the underlaying cause and fixing this upstream.
Reverting the version of swagger-parser in 5.0.0 to 2.0.20 enabled me to have a better error message:
And true enough: adding the --skip-validate-spec to my call lets this work. Ugly, but a suitable workaroud waiting for the problem to be fixed.
Swagger-parser 2.0.26 was just released with this fix. Upgrading the dependency in openapi-generator should allow it to work on Windows again
I ran into the same issue on Windows, but when I tried it on Ubuntu via WSL, it worked fine, so I assume there’s something in the way paths are handled in Windows that’s the problem.