raml-java-parser
raml-java-parser copied to clipboard
Same instance of RamlDocumentBuilder cannot parse multiple RAML definitions
(affects version 0.8.12)
I tried parsing two multi-file definitions with the same instance of RamlDocumentBuilder and the second failed to resolve includes.
RamlDocumentBuilder builder = new RamlDocumentBuilder();
// Successful parsing
URL url1 = getClass().getResource("raml/api1/api.raml");
Raml raml1 = builder.build(url1.toString());
// Parsing failed
URL url2 = getClass().getResource("raml/api2/api.raml");
Raml raml1 = builder.build(url2.toString());
The trace looked like this:
java.lang.RuntimeException: resource not found: traits.raml
at org.raml.parser.visitor.YamlDocumentBuilder.onCustomTagError(YamlDocumentBuilder.java:307)
at org.raml.parser.tagresolver.IncludeResolver.resolve(IncludeResolver.java:68)
at org.raml.parser.visitor.TemplateResolver.resolveInclude(TemplateResolver.java:180)
at org.raml.parser.visitor.TemplateResolver.init(TemplateResolver.java:117)
at org.raml.parser.visitor.RamlDocumentBuilder.preBuildProcess(RamlDocumentBuilder.java:140)
at org.raml.parser.visitor.YamlDocumentBuilder.build(YamlDocumentBuilder.java:89)
at org.raml.parser.visitor.YamlDocumentBuilder.build(YamlDocumentBuilder.java:102)
at org.raml.parser.visitor.YamlDocumentBuilder.build(YamlDocumentBuilder.java:78)
at fr.quilici.raml.conversion.RamlFolderCrawler.processDefinition(RamlFolderCrawler.java:91)
at fr.quilici.raml.conversion.RamlFolderCrawler.crawl(RamlFolderCrawler.java:65)
at fr.quilici.raml.conversion.TestAllRamlImport.main(TestAllRamlImport.java:29)
And when debugging class Include resolver (line 64) I noticed that the resourceLocation used to create the inputStream was that of the first definition (/path/to/my/project/api1).
Creating a new instance of RamlDocumentBuilder fixed my issue.
Aha! Link: https://mulesoft-roadmap.aha.io/features/APIRAML-145