/swaggerrout with SwaggerUI/swagger/swagger.jsonroute/swagger/swagger.ymlroute
<dependency>
<groupId>org.jooby</groupId>
<artifactId>jooby-swagger</artifactId>
<version>1.0.0.CR8</version>
</dependency>{
// define your API... via script or MVC:
/**
* Everything about your pets
*/
use("/api/pets")
/**
* Get a pet by ID.
* @param id Pet ID
*/
.get("/:id", req -> {
int id = req.param("id").intValue();
DB db = req.require(DB.class);
Pet pet = db.find(Pet.class, id);
return pet;
})
...;
new Swagger().install(this);
}Now the jooby:spec maven plugin:
<plugin>
<groupId>org.jooby</groupId>
<artifactId>jooby-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>spec</goal>
</goals>
</execution>
</executions>
</plugin>Start your app and try:
- The Swagger-UI at
/swagger - The
swagger.jsonat/swagger/swagger.json - The
swagger.ymlat/swagger/swagger.yml
There are a few options available, let's see what they are:
The path option controls where to mount the Swagger routes:
{
...
new Swagger("docs").install(this);
}Produces: /docs for swagger-ui, /docs/swagger.json and /docs/swagger.yml. Default path is: /swagger.
The filter option controls what is exported to Swagger:
{
...
new Swagger()
.filter(route -> {
return route.pattern().startsWith("/api");
})
.install(this);
}Default filter keeps /api/* routes.
One ore more routes are grouped by a tag. The default tag provider produces pets for a route at /api/pets or /pets. You can specify your own tag provider via:
{
new Swagger()
.tag(route -> route.name())
.install(this);
}This option turn off the swagger-ui:
{
...
new Swagger()
.noUI()
.install(this);
}Check out the a live demo for Swagger.
Source code available at github
swagger {
swagger: "2.0"
info {
title: ${application.name} API
version: ${application.version}
}
basePath: ${application.path}
consumes: ["application/json"]
produces: ["application/json"]
schemes: ["http"]
}