question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG][JAVA] Regression "-Unable to load RELATIVE ref:"

See original GitHub issue

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What’s the actual output vs expected output?
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

[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: ./openapi/model.yaml#/components/responses/FooResponse
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: 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

        at org.openapitools.codegen.config.CodegenConfigurator.toContext(CodegenConfigurator.java:541)
        at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:568)
        at org.openapitools.codegen.cmd.Generate.execute(Generate.java:424)
        at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
        at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
├── openapi
│   ├── model.yaml
└── openapi.yaml
...
$ref: ./openapi/model.yaml#/components/parameters/XXX
...
openapi-generator version

Broken versions probably everything > 5.0.0 I tested:

  • 5.0.0 (working)
  • 5.0.1 (not working)
  • 5.2.1 (not working)
Generation Details
npx openapi-generator-cli generate \
    -i openapi.yaml \
    -g typescript-axios \
    -o ${OUTDIR} \
    --additional-properties=ngVersion=6.1.7,npmName=restClient,supportsES6=true,npmVersion=6.9.0,withInterfaces=true
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.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:6
  • Comments:8

github_iconTop GitHub Comments

8reactions
Donorlincommented, Feb 4, 2022

Any news about this, please?

3reactions
ineednousernamecommented, Sep 11, 2021

@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>

Read more comments on GitHub >

github_iconTop Results From Across the Web

"Unable to load RELATIVE ref" for openapi-run.yaml in GCP ...
You are using an absolute filename, not a relative one. Try dropping the leading /workspace/ from the path in $ref .
Read more >
Relative $refs not being loaded when running as a jar?
I've having difficulty getting my OpenAPI spec file to load into my API. ... RuntimeException: Unable to load RELATIVE ref: .
Read more >
Java Compiler cannot find jar files referenced by other
A DESCRIPTION OF THE REGRESSION : I have tried the exact same compile command on Java 1.4, Java 1.5, and Java 1.6 beta....
Read more >
The correct way to pull stuff from classpath in $ref
... of goal io.swagger:swagger-codegen-maven-plugin:2.1.6:generate failed: Unable to load RELATIVE ref: ./parameters.yaml: Could not find .
Read more >
Databricks runtime maintenance updates - Azure
[SPARK-40169] Don't pushdown Parquet filters with no reference to data schema ... inputCols and outputCols can not be loaded after saving it ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found