2021-01-25 22:11:56 +00:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
import { INestApplication } from '@nestjs/common';
|
|
|
|
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
|
2021-08-29 16:45:46 +00:00
|
|
|
|
2021-01-25 22:11:56 +00:00
|
|
|
import { PrivateApiModule } from '../api/private/private-api.module';
|
|
|
|
import { PublicApiModule } from '../api/public/public-api.module';
|
2023-01-08 23:25:42 +00:00
|
|
|
import { getServerVersionFromPackageJson } from './serverVersion';
|
2021-01-25 22:11:56 +00:00
|
|
|
|
2023-01-08 23:25:42 +00:00
|
|
|
export async function setupPublicApiDocs(app: INestApplication): Promise<void> {
|
|
|
|
const version = await getServerVersionFromPackageJson();
|
2021-01-25 22:11:56 +00:00
|
|
|
const publicApiOptions = new DocumentBuilder()
|
|
|
|
.setTitle('HedgeDoc Public API')
|
2023-01-08 23:25:42 +00:00
|
|
|
.setVersion(version.fullString)
|
2021-01-25 22:11:56 +00:00
|
|
|
.addSecurity('token', {
|
|
|
|
type: 'http',
|
|
|
|
scheme: 'bearer',
|
|
|
|
})
|
|
|
|
.build();
|
|
|
|
const publicApi = SwaggerModule.createDocument(app, publicApiOptions, {
|
|
|
|
include: [PublicApiModule],
|
|
|
|
});
|
2023-01-08 23:27:29 +00:00
|
|
|
SwaggerModule.setup('apidoc/v2', app, publicApi);
|
2021-01-25 22:11:56 +00:00
|
|
|
}
|
|
|
|
|
2023-01-08 23:25:42 +00:00
|
|
|
export async function setupPrivateApiDocs(
|
|
|
|
app: INestApplication,
|
|
|
|
): Promise<void> {
|
|
|
|
const version = await getServerVersionFromPackageJson();
|
2021-01-25 22:11:56 +00:00
|
|
|
const privateApiOptions = new DocumentBuilder()
|
|
|
|
.setTitle('HedgeDoc Private API')
|
2023-01-08 23:25:42 +00:00
|
|
|
.setVersion(version.fullString)
|
2021-01-25 22:11:56 +00:00
|
|
|
.build();
|
|
|
|
|
|
|
|
const privateApi = SwaggerModule.createDocument(app, privateApiOptions, {
|
|
|
|
include: [PrivateApiModule],
|
|
|
|
});
|
2023-01-08 23:27:29 +00:00
|
|
|
SwaggerModule.setup('apidoc/private', app, privateApi);
|
2021-01-25 22:11:56 +00:00
|
|
|
}
|