Class OpenApiMixin
Three URL paths are mounted:
/openapi— content-negotiated (HTML view viaRedocUIswap, plus all serializers registered on the host)./openapi.json— format-pinned: always emits JSON regardless of the requestAcceptheader. Implemented viaRestResponse.getDirectWriter(String)so the pin is robust againstAccept: text/htmlor any other media type./openapi.yaml— format-pinned: always emits YAML regardless of the requestAcceptheader.
Sibling of SwaggerMixin (Swagger v2 spec at /api),
SwaggerUiMixin (HTML-first mount at /swagger), and RedocMixin
(HTML-first mount at /redoc). All four classes live in the
org.apache.juneau.rest.server.docs api-docs mixin pack.
The mixin declares @Rest(serializers={YamlSerializer.class}) so the
/openapi content-negotiated endpoint can serve application/yaml when explicitly
requested via Accept. Sub-context inheritance (per the mixin sub-context model) confines this
contribution to this mixin's endpoints — the host's other endpoints retain their own serializer set.
Configurable mount path:
The default mount prefix /openapi can be overridden via the SVL variable
${juneau.openapi.path:openapi} — the same variable is reused for all three mounts
(/openapi/*, /openapi.json, /openapi.yaml) so a single override
relocates the whole surface. Set via system property
(-Djuneau.openapi.path=v1/openapi), environment variable
(JUNEAU_OPENAPI_PATH=v1/openapi), or Config key
(juneau.openapi.path = v1/openapi) to change the runtime mount without subclassing.
Resolution happens once at RestContext construction time (SVL resolution in @RestOp(path)).
Override accepts bare token (openapi), leading slash (/openapi), trailing slash
(openapi/), or wildcard suffix (/openapi/*) — all resolve to the same mount.
Mixin-only deployment:
This resource is designed for composition via @Rest(mixins=...). The three mount paths
(/openapi/*, /openapi.json, /openapi.yaml) are pinned at the op level
by @RestGet(path=...) on the handler methods; a class-level
@Rest(paths=...) declaration would be silently ignored under the mixin pattern (see
@Rest(paths) Javadoc).
Composition example:
See Also:
- Since:
- 10.0.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetOpenApi(RestRequest req) [GET /openapi] — emit the OpenAPI 3.1 document for this resource.voidgetOpenApiJson(RestRequest req, RestResponse res) [GET /openapi.json] — emit the OpenAPI 3.1 document as JSON, ignoring theAcceptheader.voidgetOpenApiYaml(RestRequest req, RestResponse res) [GET /openapi.yaml] — emit the OpenAPI 3.1 document as YAML, ignoring theAcceptheader.
-
Constructor Details
-
OpenApiMixin
public OpenApiMixin()
-
-
Method Details
-
getOpenApi
[GET /openapi] — emit the OpenAPI 3.1 document for this resource.Standard Juneau content negotiation.
Accept: text/htmlrenders the Redoc HTML view via theRedocUIper-media-type swap; other accept types serialize theOpenApibean using the host's serializer set (plus theYamlSerializercontributed by this mixin).- Parameters:
req- The current REST request.- Returns:
- The OpenAPI document.
- Throws:
NotFound- If no OpenAPI document is available for this resource.
-
getOpenApiJson
[GET /openapi.json] — emit the OpenAPI 3.1 document as JSON, ignoring theAcceptheader.Format-pinned: always returns
application/json. Implemented viaRestResponse.getDirectWriter(String)so the pin is not subject to content negotiation.- Parameters:
req- The current REST request.res- The current REST response.- Throws:
NotFound- If no OpenAPI document is available for this resource.IOException- If an I/O error occurs while writing the response.
-
getOpenApiYaml
[GET /openapi.yaml] — emit the OpenAPI 3.1 document as YAML, ignoring theAcceptheader.Format-pinned: always returns
application/yaml.- Parameters:
req- The current REST request.res- The current REST response.- Throws:
NotFound- If no OpenAPI document is available for this resource.IOException- If an I/O error occurs while writing the response.
-