Schema from Validators

Automatically generate OpenAPI request body schemas from AdonisJS VineJS validators for type-safe API documentation.

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)
  }
}

On this page