Any subclass of {@link oajr.servlet.BasicRestServlet} and {@link oajr.servlet.BasicRestObject} gets an auto-generated Swagger UI when performing an OPTIONS
request with Accept:text/html due to the following method:
| @RestGet(
| path="/api/*",
| summary="Swagger documentation",
| description="Swagger documentation for this resource."
| )
| @HtmlDocConfig(
| // Should override config annotations defined on class.
| rank=10,
| // Override the nav links for the swagger page.
| navlinks={
| "back: servlet:/",
| "json: servlet:/?Accept=text/json&plainText=true"
| },
| // Never show aside contents of page inherited from class.
| aside="NONE"
| )
| @BeanConfig(
| // POJO swaps to apply to all serializers/parsers on this method.
| swaps={
| // Use the SwaggerUI swap when rendering Swagger beans.
| // This is a per-media-type swap that only applies to text/html requests.
| SwaggerUI.class
| }
| )
| @Override /* BasicRestOperations */
| public Swagger getSwagger(RestRequest req) {
| return req.getSwagger().orElseThrow(NotFound::new);
| }
The underlying mechanics are simple.
The {@link oajr.servlet.BasicRestServlet#getSwagger(RestRequest)} method returns a {@link oaj.dto.swagger.Swagger} bean
consisting of information gathered from annotations and other sources.
Then that bean is swapped for a {@link oaj.dto.swagger.ui.SwaggerUI} bean when rendered as HTML.
Note that to have your resource create Swagger UI, you must either extend from one of the basic resource classes or provide
your own @RestOp-annotated method that returns a {@link oaj.dto.swagger.Swagger} object and a {@link oaj.dto.swagger.ui.SwaggerUI} swap.