Class SwaggerMixin

java.lang.Object
org.apache.juneau.rest.server.docs.SwaggerMixin

public class SwaggerMixin extends Object
Mixin that publishes the Swagger v2 spec endpoint at /api/*.

Sibling of SwaggerUiMixin (HTML-first mount at /swagger), OpenApiMixin (OpenAPI 3.1 spec at /openapi*), and RedocMixin (HTML-first mount at /redoc). All four classes live in the org.apache.juneau.rest.server.docs api-docs mixin pack.

Compose into a host resource via @Rest(mixins=SwaggerMixin.class); the /api URL becomes available alongside the host's own endpoints with no further wiring.

Configurable mount path:

The default mount /api/* can be overridden via the SVL variable ${juneau.swagger.path:api} — set via system property (-Djuneau.swagger.path=swagger), environment variable (JUNEAU_SWAGGER_PATH=swagger), or Config key (juneau.swagger.path = swagger) to change the runtime mount without subclassing. Resolution happens once at RestContext construction time (SVL resolution in @RestOp(path)).

Override accepts bare token (api), leading slash (/api), trailing slash (api/), or wildcard suffix (/api/*) — all resolve to the same mount.

Mixin-only deployment:

This resource is designed for composition via @Rest(mixins=...). The mount path is pinned at the op level by @RestGet(path="/{juneau.swagger.path:api}/*") on getSwagger(org.apache.juneau.rest.server.RestRequest); a class-level @Rest(paths=...) declaration would be silently ignored under the mixin pattern (see @Rest(paths) Javadoc).

Composition example:

@Rest(path="/myresource", mixins=SwaggerMixin.class) public class MyResource extends RestServlet { @RestGet("/items") public List<Item> items() { ... } // Now also serves /myresource/api with the Swagger v2 spec for this resource. }

Content negotiation:

Standard Juneau content negotiation. Accept: text/html renders the Swagger-UI HTML view via the SwaggerUI per-media-type swap; other accept types serialize the Swagger bean using the host's serializer set.

See Also:
Since:
10.0.0
  • Constructor Details

  • Method Details

    • getSwagger

      [GET /api] — emit the Swagger v2 spec for this resource.
      Parameters:
      req - The current REST request.
      Returns:
      The Swagger document.
      Throws:
      NotFound - If no Swagger document is available for this resource.