Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: removing version from swagger UI #666

Merged
merged 2 commits into from
Sep 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 5 additions & 17 deletions src/setup-swagger.function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ 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 || 'no-sha'}.${
buildInfo.timestamp || 'no-timestamp'
})`
);

if (config.get<boolean>('ENABLE_AUTH')) {
options.addBearerAuth();
Expand All @@ -24,21 +27,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<string, never> {
Expand Down
Loading