feat(api): upgrade zod to v4 and implement api docs and client generation
This commit is contained in:
parent
98776aacb2
commit
87dc6162f4
26 changed files with 4827 additions and 419 deletions
36
src/lib/swagger.ts
Normal file
36
src/lib/swagger.ts
Normal file
|
@ -0,0 +1,36 @@
|
|||
import {
|
||||
OpenAPIRegistry,
|
||||
OpenApiGeneratorV3,
|
||||
} from '@asteasolutions/zod-to-openapi';
|
||||
|
||||
export const registry = new OpenAPIRegistry();
|
||||
|
||||
export const getApiDocs = async () => {
|
||||
const swaggerFiles = require.context('../app', true, /swagger\.ts$/);
|
||||
|
||||
swaggerFiles
|
||||
.keys()
|
||||
.sort((a, b) => b.length - a.length)
|
||||
.forEach((file) => {
|
||||
console.log(`Registering Swagger file: ${file}`);
|
||||
swaggerFiles(file).default?.(registry);
|
||||
});
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
require('@/app/api/validation');
|
||||
|
||||
try {
|
||||
const generator = new OpenApiGeneratorV3(registry.definitions);
|
||||
const spec = generator.generateDocument({
|
||||
openapi: '3.0.0',
|
||||
info: {
|
||||
version: '1.0.0',
|
||||
title: 'MeetUP',
|
||||
description: 'API documentation for MeetUP application',
|
||||
},
|
||||
});
|
||||
return spec;
|
||||
} catch (error) {
|
||||
console.error('Error generating API docs:', error);
|
||||
throw new Error('Failed to generate API documentation');
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue