Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate swagger spec from from JAX RS annotated interface?

I was wondering if there's a way to generate the swagger spec from an existing JAX RS annotated interface, e.g. something like this:

@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public interface ISampleService {

    @GET
    @Path("sample/foobar/{foobarId}")
    Foobar getFoobar(@PathParam("foobarId") String foobarId);

    @PUT
    @Path("sample/foobar/{foobarId}")
    Foobar updateFoobar(@PathParam("foobarId") String foobarId, Foobar foobar);
}

I did find this "jaxrs analyzer" project, but it doesn't seem to recognize my interface.

Basically, I have my service defined in an interface like that, and I want to reverse-engineer the swagger spec to be able to post it so anyone else can generate (other) clients using the swagger functionality.

Preferably, the solution would just work in a maven build (plugin).

like image 856
mac Avatar asked Feb 18 '16 07:02

mac


1 Answers

Swagger has an easy-to-follow tutorial for Jersey here.

In order for Swagger to generate a specification for your resources, you need to add the @Api annotation at the top of your class. The available annotations are listed here, but I just use @Api.

like image 194
Paul Avatar answered Sep 21 '22 00:09

Paul