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; preRelease?: string;
@ApiProperty() @ApiProperty()
commit?: string; commit?: string;
@ApiProperty()
fullString: string;
} }
export class ServerStatusDto extends BaseDto { export class ServerStatusDto extends BaseDto {

View file

@ -22,11 +22,15 @@ export async function getServerVersionFromPackageJson(): Promise<ServerVersion>
const versionParts: number[] = packageInfo.version const versionParts: number[] = packageInfo.version
.split('.') .split('.')
.map((x) => parseInt(x, 10)); .map((x) => parseInt(x, 10));
const preRelease = 'dev'; // TODO: Replace this?
versionCache = { versionCache = {
major: versionParts[0], major: versionParts[0],
minor: versionParts[1], minor: versionParts[1],
patch: versionParts[2], 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 { PrivateApiModule } from '../api/private/private-api.module';
import { PublicApiModule } from '../api/public/public-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() const publicApiOptions = new DocumentBuilder()
.setTitle('HedgeDoc Public API') .setTitle('HedgeDoc Public API')
// TODO: Use real version .setVersion(version.fullString)
.setVersion('2.0-dev')
.addSecurity('token', { .addSecurity('token', {
type: 'http', type: 'http',
scheme: 'bearer', scheme: 'bearer',
@ -25,11 +26,13 @@ export function setupPublicApiDocs(app: INestApplication): void {
SwaggerModule.setup('apidoc', app, publicApi); 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() const privateApiOptions = new DocumentBuilder()
.setTitle('HedgeDoc Private API') .setTitle('HedgeDoc Private API')
// TODO: Use real version .setVersion(version.fullString)
.setVersion('2.0-dev')
.build(); .build();
const privateApi = SwaggerModule.createDocument(app, privateApiOptions, { const privateApi = SwaggerModule.createDocument(app, privateApiOptions, {