Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/openapi-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
23 changes: 23 additions & 0 deletions src/tests/openapi-registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
Loading