You can selectively include or exclude procedures from your generated OpenAPI document using the filter option in generateOpenApiDocument. The filter function receives a context object containing the procedure's metadata. Return true to include the procedure, or false to exclude it.
To get proper types for your custom metadata within the filter function, pass a metadata generic to generateOpenApiDocument.
// Define your custom metadata type
interface MyMeta {
isPublic: boolean;
}
const appRouter = t.router({
publicProc: t.procedure
.meta({ openapi: { method: 'GET', path: '/public' }, isPublic: true })
.query(() => ({ result: 'public' })),
privateProc: t.procedure
.meta({ openapi: { method: 'GET', path: '/private' }, isPublic: false })
.query(() => ({ result: 'private' })),
});
// Only include procedures where isPublic is true
const openApiDocument = generateOpenApiDocument<MyMeta>(appRouter, {
title: 'My API',
version: '1.0.0',
baseUrl: 'http://localhost:3000',
filter: ({ metadata }) => metadata.isPublic === true,
});
// openApiDocument.paths will only include '/public'