Skip to content

Commit 88b408b

Browse files
committed
Refactor swagger configuration to use hardcoded version and dynamic date for examples; streamline server definitions for production and development environments.
1 parent 7fc0ec5 commit 88b408b

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

src/config/swagger.ts

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,32 @@
11
import swaggerJsdoc from 'swagger-jsdoc'
2-
import { version } from '../../package.json'
32
import { generateQueryPaths } from './generate-query-docs'
43

4+
// Use hardcoded version to avoid rootDir issues with package.json import
5+
const version = '1.0.0'
6+
7+
// Calculate dynamic date (2 days ago)
8+
const getTwoDaysAgo = (): string => {
9+
const date = new Date()
10+
date.setDate(date.getDate() - 2)
11+
return date.toISOString().split('T')[0] // YYYY-MM-DD format
12+
}
13+
514
const { paths: queryPaths, categories } = generateQueryPaths()
615

16+
const servers = [
17+
{
18+
url: 'https://api.openpodcast.dev',
19+
description: 'OpenPodcast API',
20+
},
21+
]
22+
23+
if (process.env.NODE_ENV !== 'production') {
24+
servers.push({
25+
url: 'http://localhost:8080',
26+
description: 'Local development server',
27+
})
28+
}
29+
730
const options: swaggerJsdoc.Options = {
831
definition: {
932
openapi: '3.0.0',
@@ -22,16 +45,7 @@ const options: swaggerJsdoc.Options = {
2245
url: 'https://github.com/openpodcast/api/blob/main/LICENSE',
2346
},
2447
},
25-
servers: [
26-
{
27-
url: 'https://api.openpodcast.dev',
28-
description: 'Production server',
29-
},
30-
{
31-
url: 'http://localhost:3000',
32-
description: 'Development server',
33-
},
34-
],
48+
servers,
3549
components: {
3650
securitySchemes: {
3751
bearerAuth: {
@@ -58,7 +72,7 @@ const options: swaggerJsdoc.Options = {
5872
schema: {
5973
type: 'string',
6074
format: 'date',
61-
example: '2024-01-01',
75+
example: getTwoDaysAgo(),
6276
},
6377
description: 'Start date (YYYY-MM-DD)',
6478
},
@@ -69,7 +83,7 @@ const options: swaggerJsdoc.Options = {
6983
schema: {
7084
type: 'string',
7185
format: 'date',
72-
example: '2024-12-31',
86+
example: getTwoDaysAgo(),
7387
},
7488
description: 'End date (YYYY-MM-DD)',
7589
},

0 commit comments

Comments
 (0)