Search code examples
javajaxbjax-rsenunciate

Can Enunciate take Java Interface as data types?


I want to use Enunciate to automatically generate documentation of my REST API.

The JAX-RS annotated code goes something like this:

@POST
@Produces({MediaType.APPLICATION_JSON, MediaType.TEXT_XML})
@Consumes({MediaType.APPLICATION_JSON, MediaType.TEXT_XML})
public IAuthentication login(CLogin aLogin) throws XException {
    return this.pManager.authenticate(aLogin);
}

IAuthentication is an interface, and it has to remain one. This is because I use injection, and I cannot predict the exact type returned by the method authenticate(). CLogin however is a class, and it is OK since it is a specialisation of the type that method authenticate() accepts.

Now my problem is that only Request Body is document in the Enunciate-generated documentation, and not the Response Body. Enunciate seems to ignore Java interfaces when looking for potential data types, with the following message:

[DEBUG] [ENUNCIATE] com.example.IAuthentication isn't a potential Jackson type because it's not a class or an enum.

My interfaces are annotated with JAXB annotations. They are accessible form the source path.

@XmlRootElement
public interface IAuthentication {
    /* methods signatures */
}

Is there a way to tell Enunciate that Java interfaces are OK as data types and must be taken into account.

Addendum

A real-life example of the JSON output of this method:

{
    "token": "imec51lpb72lgsdrb0ftvfomt3",
    "auth_key": ""
}

Solution

  • As per @stoicflame answer to this issue, version 2.7 of Enunciate doesn't seem to support Java interfaces as data types.

    I resorted to using the JavaDoc tag @returnWrapped. Another option would be the Enunciate-specific annotation @TypeHint. The JavaDoc tag spares me external runtime dependencies though.

    Edit: Version 2.9.0 of Enunciate now supports documenting interface types.