Skip to content

Commit ee3732c

Browse files
committed
docs(api): improve Swagger documentation and API config
1 parent 80307da commit ee3732c

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

apps/api/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "api",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Express API with TypeScript",
55
"main": "dist/index.js",
66
"scripts": {
@@ -38,6 +38,7 @@
3838
"express-rate-limit": "^7.4.1",
3939
"helmet": "^7.1.0",
4040
"jsonwebtoken": "^9.0.2",
41+
"node-vibrant": "^4.0.2",
4142
"pg": "^8.16.3",
4243
"swagger-jsdoc": "^6.2.8",
4344
"swagger-ui-express": "^5.0.1",

apps/api/src/lib/config/swagger.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@ import { config } from "../../core/config/env";
44
import { logger } from "../../lib/utils";
55
import path from "path";
66
import os from "os";
7+
import { readFileSync } from "fs";
8+
9+
// Read version from package.json
10+
function getApiVersion(): string {
11+
try {
12+
const packageJson = JSON.parse(
13+
readFileSync(path.join(__dirname, "../../../package.json"), "utf-8")
14+
);
15+
return packageJson.version;
16+
} catch (error) {
17+
return "0.1.0"; // Fallback version
18+
}
19+
}
720

821
/// Get local machine IP address for LAN access
922
function getLocalIpAddress(): string {
@@ -22,13 +35,14 @@ function getLocalIpAddress(): string {
2235
}
2336

2437
const localIp = getLocalIpAddress();
38+
const apiVersion = getApiVersion();
2539

2640
const options = {
2741
definition: {
2842
openapi: "3.0.0",
2943
info: {
3044
title: "DesterLib API",
31-
version: "1.0.0",
45+
version: apiVersion,
3246
description:
3347
"API documentation for DesterLib - A comprehensive media library management system",
3448
contact: {
@@ -93,6 +107,11 @@ const options = {
93107
type: "string",
94108
example: "OK",
95109
},
110+
version: {
111+
type: "string",
112+
example: "0.1.0",
113+
description: "API version",
114+
},
96115
timestamp: {
97116
type: "string",
98117
format: "date-time",
@@ -231,7 +250,7 @@ try {
231250
openapi: "3.0.0",
232251
info: {
233252
title: "DesterLib API",
234-
version: "1.0.0",
253+
version: apiVersion,
235254
description: "API documentation for DesterLib",
236255
},
237256
paths: {},

0 commit comments

Comments
 (0)