Relative references from a file in a sub-folder to other folders do not resolve
See original GitHub issueOriginally from swagger-codegen https://github.com/swagger-api/swagger-codegen/issues/3614
If you have a directory structure like
swagger.yaml
-folder1
-file1.yaml
-folder2
-file2.yaml
-folder3
-file3.yaml
then from file1.yaml it is unable to resolve references to file3.yaml or file2.yaml.
For the case in which file1 references file2, the exception thrown is:
Exception in thread "main" java.lang.RuntimeException: Unable to load RELATIVE ref: ../folder2/file2.yaml
at io.swagger.parser.util.RefUtils.readExternalRef(RefUtils.java:140)
at io.swagger.parser.ResolverCache.loadRef(ResolverCache.java:96)
at io.swagger.parser.processors.ExternalRefProcessor.processRefToExternalDefinition(ExternalRefProcessor.java:30)
at io.swagger.parser.processors.ExternalRefProcessor.processRefToExternalDefinition(ExternalRefProcessor.java:69)
at io.swagger.parser.processors.PropertyProcessor.processRefProperty(PropertyProcessor.java:33)
at io.swagger.parser.processors.PropertyProcessor.processProperty(PropertyProcessor.java:21)
at io.swagger.parser.processors.PropertyProcessor.processObjectProperty(PropertyProcessor.java:59)
at io.swagger.parser.processors.PropertyProcessor.processProperty(PropertyProcessor.java:27)
at io.swagger.parser.processors.ResponseProcessor.processResponse(ResponseProcessor.java:21)
at io.swagger.parser.processors.OperationProcessor.processOperation(OperationProcessor.java:45)
at io.swagger.parser.processors.PathsProcessor.processPaths(PathsProcessor.java:89)
at io.swagger.parser.SwaggerResolver.resolve(SwaggerResolver.java:40)
at io.swagger.parser.SwaggerParser.read(SwaggerParser.java:66)
at io.swagger.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:390)
at io.swagger.codegen.cmd.Generate.run(Generate.java:221)
at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:36)
Caused by: java.lang.RuntimeException: Could not find ../folder2/file2.yaml on the classpath
at io.swagger.parser.util.ClasspathHelper.loadFileFromClasspath(ClasspathHelper.java:31)
at io.swagger.parser.util.RefUtils.readExternalRef(RefUtils.java:135)
... 15 more
I created a suite of tests that I believe illustrate the problem, and attached it swagger-relative-file-references.zip.
The test cases that compare “./file1.yaml” vs “file.yaml” can likely be ignored, I created them for my own education to verify which formats of a relative reference were acceptable.
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
How to reference a cell in another workbook without storing ...
I'd like to make it so as long as both workbooks are in the same folder, only the file name should be stored,...
Read more >Making subdirectories for each .tex document (with AUX files ...
I have read some threads about this, and I found out a relatively convenient solution for me is to create separate directories with...
Read more >How to recurse through folders and display relative folder path?
Show activity on this post. This will correctly loop through all subfolders in C:\Users\Mark\Desktop\dummy and output file name with file size, ...
Read more >List Files in a Subdirectory and get Relative Paths only with ...
(Use the below to set your folder names and file extensions for the DIR command. Also plug in the parent directory full path...
Read more >File not found error returned from compiler when referencing ...
When using a relative reference to input from a file or os-dir, the file or folder must be relative to the current working...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Has this been fixed , i am still facing the problem with swagger-codegen v2.3.0
So thank you for getting these tests in. It was a long time coming, and I’ve gone through and carefully recreated your scenarios. This will go in the next parser release, then into codegen.