Open timo-klarshift opened 2 years ago
Just a note: I have the same issue using the maven plugin > 5.0.0 with version 5.0.0 it still works With a similar setup
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>${openapi-generator-maven-plugin.version}</version>
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: 17
Errors:
-Unable to load RELATIVE ref: openapi/openapi/model.yaml path: /home/$user/$project
Warnings:
-Unable to load RELATIVE ref: openapi/openapi/model.yaml path: /home/$user/$project
Hey guys! I could reproduce it. Can you please try to set the ref in quotes:
...
$ref: './openapi/model.yaml#/components/parameters/XXX'
...
Tested with 5.2.1 In my case it was doing the magic. Greetings from Berlin. :)
Hey guys! I could reproduce it. Can you please try to set the ref in quotes:
... $ref: './openapi/model.yaml#/components/parameters/XXX' ...
Tested with 5.2.1 In my case it was doing the magic. Greetings from Berlin. :)
I will try this at beginning of next week. This sounds quite strange to me as YAML would not require quotes there technically. So this sound still like a bug to me and I would prefer to address this properly :)
After reading your error message again and following the code it leads me to following position:
org.openapitools.codegen.config.CodegenConfigurator > io.swagger.parser.OpenAPIParser
As you can see the OpenAPIParser.java
is part of swagger.io so their parser is used.
Reading the spec from swagger.io shows, that they are doing it with quotes: https://swagger.io/docs/specification/using-ref/
If you want to change that behaviour you can create ticket here: https://github.com/swagger-api
Can confirm. Any relative path deeper than "../XYZ" ("../../XYZ", "../../../XYZ" and so on) is not working with version greater than 5.0.0
@Blubb324
thank you for suggesting this workaround, I will check this out.
Reading the spec from swagger.io shows, that they are doing it with quotes: https://swagger.io/docs/specification/using-ref/
indeed they use quotes everywhere in the examples however they also mention this in the documentation.
Note: When using local references such as #/components/schemas/User in YAML, enclose the value in quotes: '#/components/schemas/User'. Otherwise it will be treated as a comment.
I am not sure why they would mention this if you would be required to use quotes. Of course in the example above, they use it, since it is required otherwise it would be a comment in yaml.
As you can see the OpenAPIParser.java is part of swagger.io so their parser is used.
what I also wonder is why swagger ui has no problems interpreting, the same relative yaml without quotes, that this parser from swagger seem to struggle with resolving correctly. Also in 5.0.0 it was still working with the generator plugin so I guess we have to check if the swagger parser library changed between 5.0.0 and 5.0.1, maybe the problem was introduced there.
Indeed this was changed.
<swagger-parser-version>2.0.23</swagger-parser-version>
to <swagger-parser-version>2.0.24</swagger-parser-version>
Any news about this, please?
Having the same issue on v5.1.1. referencing ../../model.yml
makes the generation fail.
This is still broken in v6.4.0
broken in v6.6.0 too
Any news about this, please?
Is the original issue described by @timo-klarshift still relevant? There is a reference to this bug: https://github.com/swagger-api/swagger-parser/issues/505 which has been fixed in 4/20 and the fixed swagger-parser also seems to be part of the later openapi-generator versions.
As a side node, we were already running into:
java.lang.RuntimeException: Unable to load RELATIVE ref: ..\components\
This could be solved by changing all backslash occurrences () with slash occurrences.
Also we were running into:
[main] WARN o.o.codegen.utils.ModelUtils - #/components/schemas/accounts_{id} is not defined
This could be solved by not using { } in file naming, e.g., rename paths/accounts_{id}.yaml to paths/accounts_id.yaml
But I am not sure if these challenges are in the scope of the original issue (besides a similar error message). Other than that, version 7.0.1 is working fine for us.
Bug still present with org.openapitools:openapi-generator-maven-plugin:7.6.0
Using specifications coming from another company, I can't really modify the original files, so not sure how I could circumvent this bug in my case. By the way, IntelliJ also show an Unresolved reference
until I add the quotes around the reference. So I wonder, is this a bug on openapi generator or is it the desired behaviour of OpenAPi specifications itself ?
you may want to try the workaround mentioned in https://github.com/OpenAPITools/openapi-generator/issues/8844#issuecomment-789714081
Bug Report Checklist
Description
This is a regression of the bug described here: https://github.com/swagger-api/swagger-parser/issues/505
Its working in 5.0.0 but is broken in 5.0.1 and also in the latest version 5.2.1
openapi-generator version
Broken versions probably everything > 5.0.0 I tested:
Generation Details
Related issues/PRs
Here are all pull-requests between 5.0.0 and 5.0.1
https://github.com/OpenAPITools/openapi-generator/pulls?q=is%3Amerged+is%3Apr+milestone%3A5.0.1++
Suggest a fix
It could temporary be fixed by dereferencing everything into a single file.