Swagger

    • JaxRS Endpoint - Elide ships with a customizable JaxRS endpoint that can publish one or more swagger documents.
    • Path Discovery - Given a set of entities to explore, Elide will generate the minimum, cycle-free, de-duplicated set of URL paths in the swagger document.
    • Filter by Primitive Attributes - All GET requests on entity collections include filter parameters for each primitive attribute.
    • Include Top Level Relationships - All GET requests support the ability to include direct relationships.
    • Sort by Attribute - All GET requests support sort query parameters.
    • Pagination - All GET requests support pagination query parameters.
    • Permission Exposition - Elide permissions are exported as documentation for entity schemas.

    Pull in the following elide dependencies :

    Pull in swagger core :

    1. <groupId>io.swagger</groupId>
    2. <artifactId>swagger-core</artifactId>
    3. </dependency>

    Basic Setup

    Create and initialize an entity dictionary.

    1. EntityDictionary dictionary = new EntityDictionary(Maps.newHashMap());
    2. dictionary.bindEntity(Book.class);
    3. dictionary.bindEntity(Author.class);

    Create a swagger info object.

    1. SwaggerBuilder builder = new SwaggerBuilder(dictionary, info);

    Build the document & convert to JSON.

    1. String jsonOutput = SwaggerBuilder.getDocument(document);

    If you want swagger UI to acquire & use a bearer token from an OAuth identity provider, you can configurethe swagger document similar to:

    Adding a global parameter

    A query or header parameter can be added globally to all Elide API endpoints:

    1. HeaderParameter oauthParam = new HeaderParameter()
    2. .name("Authorization")
    3. .type("string")
    4. .description("OAuth bearer token")
    5. SwaggerBuilder crashBuilder = new SwaggerBuilder(dictionary, info)
    6. .withGlobalParameter(oauthParam);

    An HTTP response can be added globally to all Elide API endpoints:

    1. Response rateLimitedResponse = new Response().description("Too Many Requests");
    2. SwaggerBuilder crashBuilder = new SwaggerBuilder(dictionary, info)
    3. .withGlobalResponse(429, rateLimitedResponse);

    Path Generation

    In the above example, swagger will only generate paths that exclusively traverse the provided set of entities.

    The size of the swagger document can be reduced significantly by limiting the number of filter operators that are used to generate query parameterdocumentation.

    In the above example, filter query parameters are only generated for the IN operator.