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

On this page