import { type FastifyInstance } from 'fastify';
// Query parameters schema (including pagination)
const QUERY_SCHEMA = {
type: 'object',
properties: {
// Your filtering parameters
category: {
type: 'string',
description: 'Filter by category'
},
status: {
type: 'string',
enum: ['active', 'inactive'],
description: 'Filter by status'
},
// Standard pagination parameters
limit: {
type: 'string',
pattern: '^\\d+$',
description: 'Maximum number of items to return (1-100, default: 20)'
},
offset: {
type: 'string',
pattern: '^\\d+$',
description: 'Number of items to skip (≥0, default: 0)'
}
},
additionalProperties: false
} as const;
// Response schema
const RESPONSE_SCHEMA = {
type: 'object',
properties: {
success: { type: 'boolean' },
data: {
type: 'object',
properties: {
items: {
type: 'array',
items: {
// Your item schema here
type: 'object',
properties: {
id: { type: 'string' },
name: { type: 'string' },
// ... other properties
}
}
},
pagination: {
type: 'object',
properties: {
total: { type: 'number' },
limit: { type: 'number' },
offset: { type: 'number' },
has_more: { type: 'boolean' }
},
required: ['total', 'limit', 'offset', 'has_more']
}
},
required: ['items', 'pagination']
}
},
required: ['success', 'data']
} as const;
// TypeScript interfaces
interface QueryParams {
category?: string;
status?: 'active' | 'inactive';
limit?: string;
offset?: string;
}
interface PaginatedResponse {
success: boolean;
data: {
items: Item[];
pagination: {
total: number;
limit: number;
offset: number;
has_more: boolean;
};
};
}