Package com.jsgalactic.axiom.openapi.ui
Class SwaggerUi
java.lang.Object
com.jsgalactic.axiom.openapi.ui.SwaggerUi
Serves Swagger UI from the application itself, pointing at the application's own OpenAPI or
Swagger document. Nothing is loaded from a CDN or any other origin: the UI files come from the
org.webjars:swagger-ui artifact on the class path, are read once when the UI is
registered and are served from memory.
SwaggerUi.builder().spec("OpenAPI 3.1", "/openapi.json").build().register(app); // GET /docs
Served routes (under the configured path, /docs by default):
GET /docsandGET /docs/: the HTML page. It has no inline script; it loads the files below from its own origin.GET /docs/swagger-initializer.js: the generated start-up script that names your document URL(s).GET /docs/assets/<ui version>/<file>: the bundled UI files, an exact allow-list (swagger-ui.css,swagger-ui-bundle.js,swagger-ui-standalone-preset.js,index.css, two favicons). Any other name, including anything that looks like a path traversal, answers 404; no file system or class path path is ever built from a request.
Cache-Control: no-cache, strong ETag,
304 on a match); assets live under a versioned path and are immutable. Every response
carries a strict Content-Security-Policy (scripts and connections only from the same
origin, no framing), X-Content-Type-Options: nosniff and Referrer-Policy:
no-referrer. The document URLs must therefore be same-origin paths such as
/openapi.json. HEAD and OPTIONS are answered by the router like for any route.
The UI is a front end for your API description. Whether to expose it publicly is the
application's choice: nothing is served until register(com.jsgalactic.axiom.application.Application, com.jsgalactic.axiom.context.Middleware...) is called, and it takes the same
middleware as any route, so register the document routes and the UI with the same policy.
Instances are immutable and thread-safe.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic SwaggerUi.Builderbuilder()Starts a configuration.path()Returns the path the UI is served under.register(Application app, Middleware... middleware) Registers the UI routes.
-
Method Details
-
builder
Starts a configuration.- Returns:
- a builder
-
path
Returns the path the UI is served under.- Returns:
- the path, for example
/docs
-
register
Registers the UI routes. The UI files are read from the class path now, so a missing artifact stops startup instead of failing a request. Routes are hidden from generated documents.- Parameters:
app- application still configuringmiddleware- middleware for every UI route, for example an authentication policy- Returns:
- the route serving the page
- Throws:
IllegalStateException- if the Swagger UI artifact is not on the class path
-