diff --git a/src/openapi-registry.ts b/src/openapi-registry.ts index 495db90..20c0f6b 100644 --- a/src/openapi-registry.ts +++ b/src/openapi-registry.ts @@ -347,6 +347,10 @@ export function createOpenApiRegistry(config: OpenApiRegistryConfig) { } function registerRoutes(routes: AppRoutes, {ctx}: NodeKit): AppRoutes { + if (config.enabled === false) { + return routes; + } + const recognizedMethods: readonly HttpMethod[] = [ 'get', 'post', diff --git a/src/tests/openapi-registry.test.ts b/src/tests/openapi-registry.test.ts index 02454c7..7e025d8 100644 --- a/src/tests/openapi-registry.test.ts +++ b/src/tests/openapi-registry.test.ts @@ -98,6 +98,29 @@ describe('openapi-registry', () => { const registeredRoutes = registerRoutes(routes, nodekit); expect(registeredRoutes).toHaveProperty('MOUNT /api/docs'); }); + + it('should not add MOUNT route when enabled is false', () => { + const {registerRoutes} = createOpenApiRegistry({ + enabled: false, + }); + + const nodekit = new NodeKit(); + + const routes = { + 'GET /test': { + handler: withContract({ + request: {}, + response: {content: {200: z.object({})}}, + })(async (_req, res) => { + res.sendTyped(200, {}); + }), + }, + }; + + const registeredRoutes = registerRoutes(routes, nodekit); + expect(registeredRoutes).not.toHaveProperty('MOUNT /api/docs'); + expect(registeredRoutes).toHaveProperty('GET /test'); + }); }); describe('registerRoutes', () => {