We are using Jersey for RESTful API implementation utilizing its cool feature of automatic WADL generation.
Just as an example we have method
@GET
@Path("/{id}/{attribute}")
@Produces(MediaType.APPLICATION_JSON)
public Object getAttributeByID(@PathParam("id") long id, @PathParam("attribute") String attribute) {
....
}
This generates the following fragment in WADL:
<param type="xs:string" style="template" name="attribute:.*"/>
Attribute can be name
, type
, size
and we want not only to validate the value at runtime but also show it in generated wadl According to this document such feature should be supported by generating several tags <option>
inside <param>
, i.e. I am expecting something like the following:
<param type="aws:Attributes" style="template" name="attribute">
<option value="name"/>
<option value="type"/>
<option value="size"/>
</param>
My problem is to enable it with Jersey. If failed to find relevant document and assumed that probably if I change the type of parameter from String
to enum
this feature will work automatically, so I changed the method signature to:
@Path("/{id}/{attribute}")
@Produces(MediaType.APPLICATION_JSON)
public Object getAttributeByID(@PathParam("id") long id, @PathParam("attribute") Attribute attribute) {
....
}
where
public enum Attribute {
name, type, size
}
but Jersey still generates <param>
tag without options and the type of parameter is still xs:string
.
I tried to find it in code of Jersey and found class com.sun.research.ws.wadl.Option
with relevant JAXB annotations, so it seems to be relevant, but I do not know how to make it working. I guess the problem is in WadlGeneratorConfig
.
Here is relevant part of Jersey definition in our web.xml
<filter>
<filter-name>REST-API</filter-name>
<filter-class>com.sun.jersey.spi.container.servlet.ServletContainer</filter-class>
................
<init-param>
<param-name>com.sun.jersey.config.property.WadlGeneratorConfig</param-name>
<param-value>com.mycompany.resource.OurWADLGenerator</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.mycompany</param-value>
</init-param>
</filter>
where OurWADLGenerator
code is:
public class OurWADLGenerator extends WadlGeneratorConfig {
@Override
public List<WadlGeneratorDescription> configure() {
return generator(WadlGeneratorApplicationDoc.class)
.prop("applicationDocsStream", "application-doc.xml")
.generator(WadlGeneratorResourceDocSupport.class)
.prop("resourceDocStream", "resourcedoc.xml").descriptions();
}
}
What am I missing here? Thanks in advance.
public enum Attribure
should bepublic enum Attribute
... was it copied from your code or just a typo? – Lenwood