Skip to main content

BasicRestServlet/BasicRestResource Swagger and OpenAPI 3.1

Migrating from 9.4.x? The @Rest(apiFormat=…) annotation member, the juneau.rest.apiFormat system property, the RestContext.getApiFormat() accessor, and the ?Swagger / ?OpenApi query mirrors on group resources are all removed in 10.0.0. Both Swagger v2 and OpenAPI 3.1 are now always mounted via the four-class api-docs mixin pack on BasicRestServlet / BasicRestResource. See the V10 Migration Guide for the full removal table, and API-Docs Mixin Pack for the new composition story.

Any subclass of BasicRestServlet or BasicRestResource gets six auto-generated API-documentation endpoints by default:

URLFormatUI swap
GET /apiSwagger v2 specSwaggerUI swap for Accept: text/html
GET /swaggerSame Swagger v2 spec at an HTML-first URLSwaggerUI swap for bare browser GET
GET /openapiOpenAPI 3.1 specRedocUI swap for Accept: text/html
GET /openapi.jsonOpenAPI 3.1 specFormat-pinned JSON (ignores Accept)
GET /openapi.yamlOpenAPI 3.1 specFormat-pinned YAML (ignores Accept)
GET /redocSame OpenAPI 3.1 spec at an HTML-first URLRedocUI swap for bare browser GET

See the guide: Generate OpenAPI docs for your API

The six endpoints come from a four-class mixin pack: SwaggerMixin, SwaggerUiMixin, OpenApiMixin, and RedocMixin. BasicRestServlet declares:

@Rest(mixins = {SwaggerUiMixin.class, RedocMixin.class})
public abstract class BasicRestServlet extends RestServlet implements ... { ... }

SwaggerUiMixin transitively pulls in SwaggerMixin, and RedocMixin transitively pulls in OpenApiMixin, so listing the two UI halves is enough to mount all six URLs. See API-Docs Mixin Pack for the full composition reference (custom compositions, transitive resolution, parent-chain aggregation, defaultAccept content-negotiation behavior, format-pinned /openapi.json / /openapi.yaml).

Spec emission​

Both spec endpoints lean on the existing SwaggerProvider and OpenApiProvider infrastructure. The mixins do not implement their own emission paths; they expose what those providers already produce at the canonical URLs:

  • SwaggerMixin returns the Swagger bean produced by the resource's SwaggerProvider. The class-level @MarshalledConfig applies the SwaggerUI swap when an HTML response is being produced.
  • OpenApiMixin returns the OpenApi bean produced by the resource's OpenApiProvider. The class-level @MarshalledConfig applies the RedocUI swap when an HTML response is being produced.

Custom emission is supported by registering a custom SwaggerProvider / OpenApiProvider @Bean (Spring Boot) or via the bean-store registration path (microservice). See API-Docs Mixin Pack § Spring Boot vs. microservice for the resolution rules, including the @Primary precedence for multi-provider Spring Boot applications.

Mounting on a non-BasicRestServlet resource​

To get the same six-URL surface on a resource that does not extend BasicRestServlet, declare the mixin pack directly:

@Rest(path = "/api", mixins = {SwaggerUiMixin.class, RedocMixin.class})
public class CustomApi extends RestServlet {
@RestGet("/items") public List<Item> items() { ... }
}
// Serves /api/items, /api/api, /api/swagger, /api/openapi, /api/openapi.json,
// /api/openapi.yaml, /api/redoc.

To get only the OpenAPI 3.1 half (no Swagger v2, no /api, no /swagger):

@Rest(path = "/api", mixins = RedocMixin.class)
public class CustomApi extends RestServlet {
@RestGet("/items") public List<Item> items() { ... }
}
// Serves /api/items, /api/openapi, /api/openapi.json, /api/openapi.yaml, /api/redoc.

To get the OpenAPI half on a BasicRestServlet subclass while dropping the inherited Swagger half, opt out of inheritance for the mixins property:

@Rest(noInherit = {"mixins"}, mixins = RedocMixin.class)
public class OpenApiOnly extends BasicRestServlet {
@RestGet("/items") public List<Item> items() { ... }
}
// Serves /items, /openapi, /openapi.json, /openapi.yaml, /redoc.

See REST Server — Mixins and Multi-Mount Paths § Parent-chain mixin aggregation for the aggregation rules that govern how noInherit and per-mixin declarations compose across an inheritance hierarchy.

components.schemas reuse​

The OpenAPI 3.1 emission path collapses duplicated inline schemas into reusable components.schemas entries. Two layers contribute:

  • Bean-class lift via Swagger v2 definitions. BasicRestServlet carries @JsonSchemaConfig(useBeanDefs="true"), so when the underlying Swagger generator encounters a bean class it lifts the schema into definitions[<beanClassName>] and emits {"$ref":"#/definitions/<beanClassName>"} from each operation slot. The OpenAPI transform rewrites definitions to components.schemas and #/definitions/<name> refs to #/components/schemas/<name> refs.
  • Inline dedup pass. After the JSON-level Swagger-2.0 → OpenAPI-3.1 transform, BasicOpenApiProviderSession walks every operation parameter, request-body, and response-content schema slot. Inline schemas (those without $ref) that appear two or more times are hoisted into components.schemas and each occurrence is rewritten to a {"$ref":"#/components/schemas/<name>"} pointer. The lifted entry is keyed by the schema's title when present and unique; otherwise a synthesized Schema<N> name is assigned with collision avoidance against existing entries.

The dedup pass runs equally on the spec served by /openapi, /openapi.json, and /openapi.yaml, so all three deliver the same components.schemas shape.

See also​

  • Generate OpenAPI docs for your API: a guided walkthrough.
  • API-Docs Mixin Pack — the four-class composition reference: default mount, custom compositions, transitive resolution, parent-chain aggregation, defaultAccept behavior, format-pinned URLs, Spring Boot vs. microservice deployment, and migration from apiFormat.
  • REST Server — Mixins and Multi-Mount Paths — the @Rest(mixins=...) and @Rest(paths=...) primitives, importer-wins precedence, and parent-chain mixin aggregation rules.
  • Swagger Basics — Swagger v2 emission deeper dive: the Swagger bean, SwaggerUI swap, @HtmlDocConfig-driven navlinks, and schema-lift internals.
  • V10 Migration Guide — full breaking-change table for the api-docs surface, including apiFormat, ?Swagger / ?OpenApi query mirrors, and the op-interface-to-mixin migration.