raml-for-jax-rs
raml-for-jax-rs copied to clipboard
Schema references lead to "URI is not absolute" Exception
In the old version, one could reference a JSON schema from within another schema using the name, defined in the RAML "schemas" section. When trying the same approach now, the generation leads to an exception:
Failed to execute goal org.raml:raml-to-jaxrs-maven-plugin:2.0.0:generate on project test-api: Error generating Java classes from: null: URI is not absolute -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.raml:raml-to-jaxrs-maven-plugin:2.0.0:generate on project test-api: Error generating Java classes from: null
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:862)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:286)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:197)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: Error generating Java classes from: null
at org.raml.jaxrs.codegen.maven.RamlJaxrsCodegenMojo.execute(RamlJaxrsCodegenMojo.java:212)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
... 20 more
Caused by: java.lang.IllegalArgumentException: URI is not absolute
at java.net.URI.toURL(URI.java:1088)
at org.jsonschema2pojo.ContentResolver.resolve(ContentResolver.java:67)
at org.jsonschema2pojo.SchemaStore.create(SchemaStore.java:48)
at org.jsonschema2pojo.SchemaStore.create(SchemaStore.java:116)
at org.jsonschema2pojo.rules.SchemaRule.apply(SchemaRule.java:59)
at org.jsonschema2pojo.rules.SchemaRule.apply(SchemaRule.java:30)
at org.jsonschema2pojo.rules.PropertyRule.apply(PropertyRule.java:75)
at org.jsonschema2pojo.rules.PropertyRule.apply(PropertyRule.java:43)
at org.jsonschema2pojo.rules.PropertiesRule.apply(PropertiesRule.java:64)
at org.jsonschema2pojo.rules.PropertiesRule.apply(PropertiesRule.java:32)
at org.jsonschema2pojo.rules.ObjectRule.apply(ObjectRule.java:115)
at org.jsonschema2pojo.rules.ObjectRule.apply(ObjectRule.java:66)
at org.jsonschema2pojo.rules.TypeRule.apply(TypeRule.java:90)
at org.jsonschema2pojo.rules.TypeRule.apply(TypeRule.java:40)
at org.jsonschema2pojo.rules.SchemaRule.apply(SchemaRule.java:73)
at org.jsonschema2pojo.rules.SchemaRule.apply(SchemaRule.java:30)
at org.jsonschema2pojo.SchemaMapper.generate(SchemaMapper.java:134)
at org.raml.jaxrs.generator.JsonSchemaTypeGenerator.output(JsonSchemaTypeGenerator.java:60)
at org.raml.jaxrs.generator.builders.AbstractTypeGenerator.output(AbstractTypeGenerator.java:27)
at org.raml.jaxrs.generator.CurrentBuild.generate(CurrentBuild.java:126)
at org.raml.jaxrs.generator.RamlScanner.handle(RamlScanner.java:94)
at org.raml.jaxrs.generator.RamlScanner.handle(RamlScanner.java:74)
at org.raml.jaxrs.generator.RamlScanner.handle(RamlScanner.java:55)
at org.raml.jaxrs.codegen.maven.RamlJaxrsCodegenMojo.execute(RamlJaxrsCodegenMojo.java:210)
... 22 more
The RAML:
#%RAML 1.0
title: URI is not absolute
baseUri: https://foo/bar
mediaType: application/json
types:
A: !include model/A.schema.json
B: !include model/B.schema.json
/foo:
get:
responses:
200:
body:
type: A
A.schema.json
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"refB": {
"$ref": "B"
}
}
}
B.schema.json
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {}
}
When I reference B using the direct path (e.g. file:src/main/resources/raml/model/B.schema.json
) it works. However using relative paths (e.g. B.schema.json
, or file:B.schema.json
) the exception is thrown again.
Is this feature dropped? Always using the complete path makes the schemas super ugly, and glued to the complete package structure.
That seems closely related to #202
What about this issue? I can't find a way to define the refs which works both using the plugin and api-workbench for Atom.
Sorry, slipped through the cracks. I'll look into it and see if we can do something tonight.
@jpbelang In your solution, please consider that the workaround suggested by @frl7082 doesn't work if you have a multi-module Maven project and you run the build from the parent instead of the module which uses this plugin.
When do you expect to release a version which solves this issue?
I've had a look.
We delegate all or the json schema stuff to jsonschema2pojo. The difficulty is that j2p resolves the $refs by itself.
https://github.com/joelittlejohn/jsonschema2pojo/wiki/Reference#ref
I think the only solution would be to use classpath: or one of the other synonyms. I'm currently having problems adjusting the classpath in the maven plugin.