Skip to content

[BUG] 5.0.0 breaks generator if servers url relative #8266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
UnleashSpirit opened this issue Dec 24, 2020 · 16 comments
Open

[BUG] 5.0.0 breaks generator if servers url relative #8266

UnleashSpirit opened this issue Dec 24, 2020 · 16 comments

Comments

@UnleashSpirit
Copy link
Contributor

Hi recently switch from [email protected] 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.

@auto-labeler
Copy link

auto-labeler bot commented Dec 24, 2020

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

selliera added a commit to selliera/openapi-generator-maven-plugin-test that referenced this issue Jan 7, 2021
It should work better like that, it looks like you encountered issue #8266
OpenAPITools/openapi-generator#8266
@selliera
Copy link
Contributor

selliera commented Jan 7, 2021

Reverting the version of swagger-parser in 5.0.0 to 2.0.20 enabled me to have a better error message:

Exception in thread "main" org.openapitools.codegen.SpecValidationException: There were issues with the specification. The option can be disabled via validateSpec (Maven/Gradle) or --skip-validate-spec (CLI).
 | Error count: 1, Warning count: 0
Errors:
        -attribute .servers.invalid url : /api

        at org.openapitools.codegen.config.CodegenConfigurator.toContext(CodegenConfigurator.java:541)

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.

@UnleashSpirit
Copy link
Contributor Author

Ho it's not OpenApi so ? It's "deeper".
You know if there is a issue on swagger-parser ?

@selliera
Copy link
Contributor

selliera commented Jan 7, 2021

It looks like there is one. In fact when I searched first, I had nto yet understood that it was coming from the url.
swagger-api/swagger-parser#1509 look like the cause of our problems.

@selliera
Copy link
Contributor

selliera commented Jan 7, 2021

Oh, my bad: the --skip-validate-spec workaround is only usable with 5.0.0 rebuilt with swagger-parser version 2.0.21 as a dependency. With the real 5.0.0, it does not work at all ! (I tested with the wrong jar).
With swagger-parser 2.0.20, I even do not need to add the --skip-validate-spec, so for now, it will use a modified 5.0.0 with this older version of swagger-parser.

@SwingGuy1024
Copy link

I should point out that there are two problems here. One is that a relative url breaks the build. The other is that the error message is incorrect. I'm having a different issue that's breaking the build (https://github.com/SwingGuy1024/OpenAPI_inputSpec_Bug) where I also get a misleading error message, so this may be a wider problem with the code.
I haven't looked at the code, but in my experience, this may happen if exceptions are being handled carelessly. For example, If you catch Exception and assuming it's the specific exception you were expecting, you may produce an incorrect error message if some other bug threw a RuntimeException that's also getting caught. This is why, whenever I need to say "catch Exception", I always also catch RuntimeException and rethrow it. I have no idea if this is the cause of your misleading error messages, but I thought I'd mention it.

@stapel
Copy link
Contributor

stapel commented Mar 5, 2021

Might this be a windows-related problem? I had no problems generating a client from a schema with a relative path on a Linux System, a colleague however could not build it (openapi-gen 5.0.1, maven plugin) on Windows, though he could build it with an absolute path.

@frochi42
Copy link

Any updates on this? We definitely need that possibility to provide relative URL in servers...
Another question: as I am using the generator from the maven plugin: Is there an example available how to force the usage of a differen swagger parser when using that plugin?

@deiag
Copy link

deiag commented Mar 26, 2021

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.

@Klaboe
Copy link

Klaboe commented Apr 14, 2021

Can chip in here with the cliff notes of my experience:

Is on Windows10
Has openapi3 spec,
Has relative path i servers.url
Used gradle plugin 5.1.0

Validation breaks and it seems like it has tried to parse the file as en openapi2-spec:

Errors:
        -attribute swagger is missing
        -attribute components is unexpected
        -attribute openapi is unexpected
        -attribute servers is unexpected

Skipping validation made it generate the api-files, but not the component-files.

If i tried building from WSL, everything worked out fine
If i tried generation with the CLI for 5.1.0, everything worked out fine

@jhannes
Copy link

jhannes commented Apr 19, 2021

I think this is the underlying cause: swagger-api/swagger-parser#1553

@norrs
Copy link

norrs commented May 25, 2021

What is the usual timeframe for making a new release of openapi-generator in maven repositories which includes the fix shipped in swagger-api/swagger-parser#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.

@lufecir
Copy link

lufecir commented May 26, 2021

Yes, same question as norrs. Would also much appreciate a release.
So any idea on when we might expect this? To understand what our options are.

@jhannes
Copy link

jhannes commented May 26, 2021

Please note that swagger-parser hasn't been released with the PR yet and I have not verified that it does in fact fix the problem in openapi-generator. So the request for a new release must start upstream :-)

@jhannes
Copy link

jhannes commented May 28, 2021

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

@marcelstoer
Copy link
Contributor

This is a duplicate of #8260.

julianladisch added a commit to julianladisch/mod-password-validator that referenced this issue Jun 29, 2021
"[BUG] openapi-generator-maven-plugin version 5.0.0 does not work for OpenApi 3.0 yml-files"
OpenAPITools/openapi-generator#8260

"[BUG] 5.0.0 breaks generator if servers url relative"
OpenAPITools/openapi-generator#8266
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests