Jersey 2 generate WADL schema with method parameters

Evgeny Makarov picture Evgeny Makarov · Mar 27, 2014 · Viewed 7.5k times · Source

I'm using Jersey 2 and would like to generate a WADL schema. When I access to <context_root>/application.wadl I can see all my REST services but in the case that a service consumes JSON (and almost all of my services consume JSON) I get the following:

<resource path="/addItem">
    <method id="addItem" name="POST">
        <request>
            <representation mediaType="application/json"/>
        </request>
        <response>
            <representation mediaType="application/json"/>
        </response>
    </method>
</resource>

while my service looks like:

@POST
@Path("/addItem")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response addItem(ItemDto item) {
    cartService.addItem(item);
    return Response.ok().build();
}

Can I get details about ItemDto in my wadl scheme?

Answer

AdamL picture AdamL · May 27, 2014

WADL itself AFAIK does not provide more information than you are getting. OK, actually it does, because some non-user-defined resources and methods are hidden in the default /application.wadl response since Jersey 2.5.1. To see a bit more (but still not what you want to achieve), you can call the wadl resource with detail query parameter, i.e. /application.wadl?detail=true, see Chapter 16 of the Jersey docs.

To return to your question - if I understand correctly, what you want Jersey to do is to automatically expose JSON-Schemas of your beans in the WADL, right?

This is not easily possible in Jersey-2.x at the moment. There was an extension module in Jersey-1.x written by Gerard Davison, but the support was not yet ported into Jersey-2.x (currently only XSD is supported).

However, there is an issue in the Jersey backlog, so with some patience, you might get the out-of-the-box solution one day.

In the meantime, you can try to do a Quick and a bit dirty solution described in the Gerard's blogpost.

I know that the answer comes a bit late, but still hope it helps.

Good luck.