Route configuration (schemas, response, tags, security)
@Controller('/api/v1/notes', {
tags: ['Notes'],
security: ['bearerAuth']
})
export class NotesController implements Controller {
@Route({
body: createNoteSchema,
response: noteSchema, // 201 auto-derived from 'create' method
tags: ['Mutations'],
description: 'Create a new note'
})
async create(ctx: RouterContext): Promise<Response> {
// POST /api/v1/notes (auto-derived from method name)
// Body schema: createNoteSchema (auto-validated)
// Response: 201 → noteSchema (status auto-derived)
// Tags: ['Notes', 'Mutations'] (merged with controller)
// Security: ['bearerAuth'] (inherited from controller)
const body = ctx.body()
const note = await this.notesService.create(body)
return ctx.json(note, 201)
}
@Route({
query: paginationSchema,
response: z.array(noteSchema) // 200 auto-derived from 'index' method
})
async index(ctx: RouterContext): Promise<Response> {
// GET /api/v1/notes (auto-derived)
// Query params auto-validated
const notes = await this.notesService.list()
return ctx.json(notes)
}
@Route({
params: z.object({ id: z.string().uuid() }),
response: {
schema: noteSchema,
description: 'Note details'
},
security: [] // Override to make public
})
async show(ctx: RouterContext): Promise<Response> {
// GET /api/v1/notes/:id (auto-derived)
// URL params auto-validated
// Response: 200 → noteSchema (status auto-derived)
// Security: [] (public route, override controller security)
const id = ctx.param('id')
const note = await this.notesService.findById(id)
return ctx.json(note)
}
}
Decorator to add OpenAPI metadata to a controller method
Stores route configuration (schemas, response, tags, security) in metadata. HTTP method, path, and success status code are auto-derived from the method name: