Elide supports the generation of Swagger documentation from Elide annotated beans. Specifically, it generates a JSON document conforming to the swagger specification that can be used by tools like Swagger UI (among others) to explore, understand, and compose queries against your Elide API.

Features Supported

  • 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.
  • Prune Fields - All GET requests support JSON-API sparse fields query parameter.
  • 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.

Getting Started


Pull in the following elide dependencies :



Pull in swagger core :


Basic Setup

Create and initialize an entity dictionary.

EntityDictionary dictionary = new EntityDictionary(Maps.newHashMap());


Create a swagger info object.

Info info = new Info().title("My Service").version("1.0");

Initialize a swagger builder.

SwaggerBuilder builder = new SwaggerBuilder(dictionary, info);

Build the swagger document

Swagger document = builder.build();

Convert Swagger to JSON

You can directly convert to JSON:

String jsonOutput = SwaggerBuilder.getDocument(document);

Configure JAX-RS Endpoint

Or you can use the Swagger document directly to configure the provided JAX-RS Endpoint:

Map<String, Swagger> swaggerDocs = new HashMap<>();
docs.put("publishingModels", document)

//Dependency Inject the DocEndpoint JAX-RS resource
bind(docs).named("swagger").to(new TypeLiteral<Map<String, Swagger>>() { });

Supporting OAuth

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

SecuritySchemeDefinition oauthDef = new OAuth2Definition().implicit(CONFIG_DATA.zuulAuthorizeUri());
SecurityRequirement oauthReq = new SecurityRequirement().requirement("myOauth");

SwaggerBuilder builder = new SwaggerBuilder(entityDictionary, info);
Swagger document = builder.build();
    .securityDefinition("myOauth", oauthDef)

Adding a global parameter

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

HeaderParameter oauthParam = new HeaderParameter()
    .description("OAuth bearer token")

SwaggerBuilder crashBuilder = new SwaggerBuilder(dictionary, info)

Adding a global response code

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

Response rateLimitedResponse = new Response().description("Too Many Requests");

SwaggerBuilder crashBuilder = new SwaggerBuilder(dictionary, info)
    .withGlobalResponse(429, rateLimitedResponse);


Path Generation

The Swagger UI is very slow when the number of generated URL paths exceeds a few dozen. For large, complex data models, it is recommended to generate separate swagger documents for subgraphs of the model.

Set<Class<?>> entities = Sets.newHashSet(
SwaggerBuilder coreBuilder = new SwaggerBuilder(dictionary, info)

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

Document Size

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

SwaggerBuilder crashBuilder = new SwaggerBuilder(dictionary, info)

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