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:
Jachin
2025-09-23 18:31:16 +08:00
committed by GitHub
parent 762b702e46
commit 812c2d86d4
3 changed files with 79 additions and 11 deletions

View File

@@ -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",

View File

@@ -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';