Skip to content
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

Unable to load RELATIVE ref #1551

Closed
nickcmaynard opened this issue Nov 11, 2015 · 15 comments
Closed

Unable to load RELATIVE ref #1551

nickcmaynard opened this issue Nov 11, 2015 · 15 comments

Comments

@nickcmaynard
Copy link
Contributor

With swagger-codegen 2.1.4, we receive this error when attempting to generate JAX-RS server from a swagger.json:

reading from http://localhost:9080/swagger.json
Exception in thread "main" java.lang.RuntimeException: Unable to load RELATIVE ref: ./parameters.json
    at io.swagger.parser.util.RefUtils.readExternalRef(RefUtils.java:85)
    at io.swagger.parser.ResolverCache.loadRef(ResolverCache.java:91)
    at io.swagger.parser.processors.ParameterProcessor.processParameters(ParameterProcessor.java:38)
    at io.swagger.parser.processors.OperationProcessor.processOperation(OperationProcessor.java:28)
    at io.swagger.parser.processors.PathsProcessor.processPaths(PathsProcessor.java:58)
    at io.swagger.parser.SwaggerResolver.resolve(SwaggerResolver.java:38)
    at io.swagger.parser.SwaggerParser.read(SwaggerParser.java:62)
    at io.swagger.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:317)
    at io.swagger.codegen.cmd.Generate.run(Generate.java:186)
    at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:35)
Caused by: java.lang.NullPointerException
    at io.swagger.parser.util.RefUtils.readExternalRef(RefUtils.java:75)
    ... 9 more

I've seen other issues (#214) where @fehguy states this should be fixed, but we're not seeing this... does anyone have any ideas, please?

@wing328
Copy link
Contributor

wing328 commented Nov 11, 2015

Here is the error:
Exception in thread "main" java.lang.RuntimeException: Unable to load RELATIVE ref: ./parameters.json

Seems like you're using relative path for the definition of parameters.

Can you replace ./parameters.json with full URL instead as the parser is expecting the full URL (https://github.com/swagger-api/swagger-parser/blob/master/modules/swagger-parser/src/main/java/io/swagger/parser/util/RefUtils.java#L71) ?

@wing328
Copy link
Contributor

wing328 commented Nov 13, 2015

You can find an example for reference at #1544 (comment)

@nickcmaynard
Copy link
Contributor Author

That's the issue. Sadly, we need to use relative references - this gets deployed on a number of servers with different URLs.

@nickcmaynard
Copy link
Contributor Author

To be clear, we expect this relative style to work, in line with @fehguy's assertion.

@wing328
Copy link
Contributor

wing328 commented Nov 14, 2015

@nickcmaynard I read #214 twice but didn't see how it's related to this issue (relative URL) that you reported.

Are you referring to another issue instead?

@nickcmaynard
Copy link
Contributor Author

Definitely a typo. Will try to track down the real issue number. However, this issue should be sufficient. Essentially, @fehguy states "swagger-parser supports relative, so swagger-codegen should too". Clearly, not the case. Hence, raising the issue.

@nickcmaynard
Copy link
Contributor Author

#742 is the issue I'm referring to.

@wing328
Copy link
Contributor

wing328 commented Nov 15, 2015

I've read #742 and the issue #1193 associated with it. My understanding is that the thread/issue refers to relative "file" path (not URI).

Looking at the swagger spec, canonical dereferencing is supported so in your case swagger parser should look for http://localhost:9080/parameter.json

@nickcmaynard
Copy link
Contributor Author

swagger-codegen is being passed a URI. The URI contains a relative $ref. It throws the error linked in the original report. We expect it to work.

@nicksloan
Copy link

Until this is fixed, I have worked around it by using swagger-parser (the JavaScript library). Here is a quick node.js script I wrote to help: https://gist.github.com/nicksloan/b4aeb117734c5c1cec81

I simply run that with $ node consolidate.js > full.json to serialize my schema to a single JSON file, which I can then build using swagger-codegen. The extra step is a bummer, but not really that much of a problem in the grand scheme of things.

This is tested and working for local file schemas, but not for hosted schema URIs. It's probably worth a try though.

@nicksloan
Copy link

I'm not sure but I believe that this will be fixed when swagger-codegen depends on the next release of swagger-parser. More information is here: swagger-api/swagger-parser#213.

@wing328
Copy link
Contributor

wing328 commented Apr 19, 2016

@nickcmaynard @nicksloan do you mind pull the latest master of Swagger Codegen to see if you're still facing the issue? Thanks.

@nicksloan
Copy link

I'll try to take a look this weekend.

@wing328
Copy link
Contributor

wing328 commented May 13, 2016

@nicksloan may I know if you've a chance to take another look?

@fehguy
Copy link
Contributor

fehguy commented Oct 27, 2016

This should be fixed by 92af2cf

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

4 participants