hammock-project/hammock

Integration with Swagger 2.0

Closed this issue · 8 comments

Add support for Swagger 2.0 https://github.com/swagger-api/swagger-core/tree/2.0

  • Single coordinate to depend on that adds Swagger 2.0 APIs.
  • It should add swagger support any JAX-RS runtime.

The benefit of pushing the integration into Swagger 2.0's jars would be allowing the user to control the Swagger version upgrades (being able to upgrade Swagger without relying on Hammock releases).

@derekm for any dependency that hammock brings in, you can mark the dependencies as excluded, or if you declare the dependencies before the hammock JAR maven will use those instead of the ones hammock brings in.

Ok, I didn't know about the dependency order trick! It's less explicit, but maybe it beats the exclude approach. Thanks for the tip!

@johnament -- RestAssured looks very interesting! ... Btw, I've got a highly generic set of CrudResource interfaces and abstract classes + CrudEndpoint/CrudService + JPA & JAXB type transformers. Jersey Server has no problems presenting extensions of these CRUD services for endpoints of random types, but Jersey Proxy Client struggles when it hits CrudResource<T> off of some concrete interface WhateverResource extends CrudResource<Whatever>. This CRUD logic refactor saves a ton of code. Do you think MP Rest Client 1.0 would be able to handle it? I'll have to send my CRUD refactor your way!

Base & Interface:

/**
 * A generic CRUD Endpoint implementation.
 *
 * @author dmoore
 *
 * @param <T> return type & service transform return type
 * @param <S> service type
 * @param <E> service entity type
 * @param <X> service transformation type
 * @param <I> input/output transformation type
 */
public abstract class CrudEndpoint<T,
                                   S extends CrudService<E, X, T, I>,
                                   E,
                                   X extends Function<E, T>,
                                   I extends EntityTransformer<T, E>
                                   >
        implements CrudResource<T> {

Implementation:

public class AnswersEndpoint
        extends CrudEndpoint<QuestionAnswer,
                             AnswerService,
                             Answer,
                             AnswerTransformer,
                             QuestionAnswerTransformer>
        implements AnswersResource {

:D

What do the annotations look like on the actual interfaces?

public interface CrudResource<T> {

    @GET
    @Consumes({
            MediaType.APPLICATION_JSON,
            MediaType.APPLICATION_XML,
            })
    @Produces({
            MediaType.APPLICATION_JSON,
            MediaType.APPLICATION_XML,
            })
    public List<T> get();

    @POST
    @Consumes({
            MediaType.APPLICATION_JSON,
            MediaType.APPLICATION_XML,
            })
    @Produces({
            MediaType.APPLICATION_JSON,
            MediaType.APPLICATION_XML,
            })
    public T post(T answer);

}

and

public interface AnswersResource extends CrudResource<QuestionAnswer> {}

swagger-jaxrs2 is now CDI-enabled in swagger-core 2.0.0-SNAPSHOT, presumably to be released in 2.0.0-rc4: swagger-api/swagger-core#2627