feat(apidocs): use real version number

Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
Erik Michelson 2023-01-09 00:25:42 +01:00 committed by David Mehren
parent 8ee2d809c7
commit d52fc55ef3
3 changed files with 16 additions and 7 deletions

View file

@ -18,6 +18,8 @@ export class ServerVersion {
preRelease?: string;
@ApiProperty()
commit?: string;
@ApiProperty()
fullString: string;
}
export class ServerStatusDto extends BaseDto {

View file

@ -22,11 +22,15 @@ export async function getServerVersionFromPackageJson(): Promise<ServerVersion>
const versionParts: number[] = packageInfo.version
.split('.')
.map((x) => parseInt(x, 10));
const preRelease = 'dev'; // TODO: Replace this?
versionCache = {
major: versionParts[0],
minor: versionParts[1],
patch: versionParts[2],
preRelease: 'dev', // TODO: Replace this?
preRelease: preRelease,
fullString: `${versionParts[0]}.${versionParts[1]}.${versionParts[2]}${
preRelease ? '-' + preRelease : ''
}`,
};
}

View file

@ -8,12 +8,13 @@ import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { PrivateApiModule } from '../api/private/private-api.module';
import { PublicApiModule } from '../api/public/public-api.module';
import { getServerVersionFromPackageJson } from './serverVersion';
export function setupPublicApiDocs(app: INestApplication): void {
export async function setupPublicApiDocs(app: INestApplication): Promise<void> {
const version = await getServerVersionFromPackageJson();
const publicApiOptions = new DocumentBuilder()
.setTitle('HedgeDoc Public API')
// TODO: Use real version
.setVersion('2.0-dev')
.setVersion(version.fullString)
.addSecurity('token', {
type: 'http',
scheme: 'bearer',
@ -25,11 +26,13 @@ export function setupPublicApiDocs(app: INestApplication): void {
SwaggerModule.setup('apidoc', app, publicApi);
}
export function setupPrivateApiDocs(app: INestApplication): void {
export async function setupPrivateApiDocs(
app: INestApplication,
): Promise<void> {
const version = await getServerVersionFromPackageJson();
const privateApiOptions = new DocumentBuilder()
.setTitle('HedgeDoc Private API')
// TODO: Use real version
.setVersion('2.0-dev')
.setVersion(version.fullString)
.build();
const privateApi = SwaggerModule.createDocument(app, privateApiOptions, {