Schema from Validators
Pass a VineJS or Zod validator to @ApiSchema and it documents the params, query and body of the operation from the schema you already validate with.
A common pattern with Adonis is to perform request validation using request.validateUsing(validator).
By using the @ApiSchema decorator you can generate the OpenAPI documentation automatically from the same validator.
This feature is based on StandardJSONSchema which works with any validation library that support it (Vine, Zod, etc).
Usage
const IndexSchema = vine.create({
params: vine.object({
categoryId: vine.string().uuid(),
}),
qs: vine.object({
page: vine.number(),
perPage: vine.number(),
}),
})
export class PostsController {
@ApiSchema(IndexSchema)
index({ request }: HttpContext) {
const { params, qs } = await request.validateUsing(IndexSchema)
}
}Defining Endpoints
Describe endpoints with @ApiTags, @ApiHeader and @ApiResponse, and switch the media type on a body to document multipart file uploads in AdonisJS.
Using Transformers
Extend OpenAPISerializer and register TransformerTypeLoader to build response schemas from AdonisJS transformers, including collections and pagination.