From 81531665dea4428772e7f3932c3c14a74fe4d66f Mon Sep 17 00:00:00 2001 From: Artur Sudnik-Hrynkiewicz Date: Wed, 20 Sep 2023 20:27:53 +0200 Subject: [PATCH 1/2] feat: removing package version from the Swagger UI --- src/setup-swagger.function.ts | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/src/setup-swagger.function.ts b/src/setup-swagger.function.ts index 47e8faf1..f8dd3d50 100644 --- a/src/setup-swagger.function.ts +++ b/src/setup-swagger.function.ts @@ -5,13 +5,12 @@ import { readFileSync } from 'fs'; import { resolve } from 'path'; export const setupSwagger = (app: INestApplication, config: ConfigService) => { - const version = readVersion(); const buildInfo = readBuildInfo(); const options = new DocumentBuilder() .setTitle('API') .setDescription('Cache Server API documentation') - .setVersion(`${version} (${buildInfo.gitSha}.${buildInfo.timestamp})`); + .setVersion(`(${buildInfo.gitSha}.${buildInfo.timestamp})`); if (config.get('ENABLE_AUTH')) { options.addBearerAuth(); @@ -24,21 +23,6 @@ export const setupSwagger = (app: INestApplication, config: ConfigService) => { ); }; -function readVersion(): string { - let pkg; - - try { - pkg = JSON.parse( - readFileSync(resolve(__dirname, '../package.json')).toString('utf8') - ); - } catch (err) { - console.log(`error reading/parsing package.json: ${err}`); - return ''; - } - - return pkg.version; -} - function readBuildInfo(): | { timestamp: string; gitSha: string } | Record { From 0f4ffda04f97927a7375e23fb4b436d67cda96b1 Mon Sep 17 00:00:00 2001 From: Artur Sudnik-Hrynkiewicz Date: Wed, 20 Sep 2023 20:56:03 +0200 Subject: [PATCH 2/2] fix: fixing `undefined.undefined` version displayed in Swagger UI when executed locally --- src/setup-swagger.function.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/setup-swagger.function.ts b/src/setup-swagger.function.ts index f8dd3d50..5d408fbb 100644 --- a/src/setup-swagger.function.ts +++ b/src/setup-swagger.function.ts @@ -10,7 +10,11 @@ export const setupSwagger = (app: INestApplication, config: ConfigService) => { const options = new DocumentBuilder() .setTitle('API') .setDescription('Cache Server API documentation') - .setVersion(`(${buildInfo.gitSha}.${buildInfo.timestamp})`); + .setVersion( + `(${buildInfo.gitSha || 'no-sha'}.${ + buildInfo.timestamp || 'no-timestamp' + })` + ); if (config.get('ENABLE_AUTH')) { options.addBearerAuth();