mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 12:55:00 +00:00
feat(server): add Swagger API docs (#13455)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Interactive API documentation available at /api/docs when running in development. * **Chores** * Added a development dependency to enable generation of the API documentation. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: DarkSky <25152247+darkskygit@users.noreply.github.com> Co-authored-by: DarkSky <darksky2048@gmail.com>
This commit is contained in:
@@ -128,6 +128,7 @@
|
||||
"@affine-tools/utils": "workspace:*",
|
||||
"@affine/graphql": "workspace:*",
|
||||
"@faker-js/faker": "^10.0.0",
|
||||
"@nestjs/swagger": "^11.2.0",
|
||||
"@nestjs/testing": "patch:@nestjs/testing@npm%3A10.4.15#~/.yarn/patches/@nestjs-testing-npm-10.4.15-d591a1705a.patch",
|
||||
"@types/cookie-parser": "^1.4.8",
|
||||
"@types/express": "^5.0.1",
|
||||
|
||||
@@ -59,6 +59,21 @@ export async function run() {
|
||||
const adapter = new SocketIoAdapter(app);
|
||||
app.useWebSocketAdapter(adapter);
|
||||
|
||||
if (env.dev) {
|
||||
const { SwaggerModule, DocumentBuilder } = await import('@nestjs/swagger');
|
||||
// Swagger API Docs
|
||||
const docConfig = new DocumentBuilder()
|
||||
.setTitle('AFFiNE API')
|
||||
.setDescription(`AFFiNE Server ${env.version} API documentation`)
|
||||
.setVersion(`${env.version}`)
|
||||
.build();
|
||||
const documentFactory = () => SwaggerModule.createDocument(app, docConfig);
|
||||
SwaggerModule.setup('/api/docs', app, documentFactory, {
|
||||
useGlobalPrefix: true,
|
||||
swaggerOptions: { persistAuthorization: true },
|
||||
});
|
||||
}
|
||||
|
||||
const url = app.get(URLHelper);
|
||||
const listeningHost = '0.0.0.0';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user