@@ -27,33 +27,44 @@ const getDocs = (basePath, getPath) => {
27
27
const docsSources = getDocs ( baseRoutes , getPathRoutes )
28
28
// const docsSchemes = getDocs(baseSchemas, getPathSchemes)
29
29
30
- const serverProduction = [
31
- {
32
- url : 'https://api.example.com/v1' ,
33
- description : 'Production server' ,
34
- } ,
35
- ]
30
+ let baseURLServer = [ ]
36
31
37
- const serverLocal = [
38
- {
39
- url : `http://localhost:${ PORT || 8000 } /v1` ,
40
- description : 'Development server' ,
41
- } ,
42
- {
43
- url : 'https://api-staging.example.com/v1' ,
44
- description : 'Staging server' ,
45
- } ,
46
- {
47
- url : 'https://api.example.com/v1' ,
48
- description : 'Production server' ,
49
- } ,
50
- ]
32
+ if ( NODE_ENV === 'production' ) {
33
+ baseURLServer = [
34
+ {
35
+ url : 'https://api.example.com/v1' ,
36
+ description : 'Production server' ,
37
+ } ,
38
+ ]
39
+ } else if ( NODE_ENV === 'staging' ) {
40
+ baseURLServer = [
41
+ {
42
+ url : 'https://api-staging.example.com/v1' ,
43
+ description : 'Staging server' ,
44
+ } ,
45
+ ]
46
+ } else {
47
+ baseURLServer = [
48
+ {
49
+ url : `http://localhost:${ PORT || 8000 } /v1` ,
50
+ description : 'Development server' ,
51
+ } ,
52
+ {
53
+ url : 'https://api-staging.example.com/v1' ,
54
+ description : 'Staging server' ,
55
+ } ,
56
+ {
57
+ url : 'https://api.example.com/v1' ,
58
+ description : 'Production server' ,
59
+ } ,
60
+ ]
61
+ }
51
62
52
63
module . exports = function generateDocs ( app ) {
53
64
const swaggerOptions = {
54
65
definition : {
55
66
openapi : '3.0.1' ,
56
- servers : NODE_ENV === 'production' ? serverProduction : serverLocal ,
67
+ servers : baseURLServer ,
57
68
// security: [ //Set GLOBAL
58
69
// {
59
70
// auth_token: []
@@ -108,33 +119,44 @@ module.exports = function generateDocs(app) {
108
119
apis : [ ] ,
109
120
}
110
121
111
- const swaggerOptProduction = [
112
- {
113
- url : 'http://api.example.com/v1/api-docs.json' ,
114
- name : 'Production Server' ,
115
- } ,
116
- ]
122
+ let swaggerOptURL = [ ]
117
123
118
- const swaggerOptLocal = [
119
- {
120
- url : `http://localhost:${ PORT || 8000 } /v1/api-docs.json` ,
121
- name : 'Development Server' ,
122
- } ,
123
- {
124
- url : 'http://api-staging.example.com/v1/api-docs.json' ,
125
- name : 'Staging Server' ,
126
- } ,
127
- {
128
- url : 'http://api.example.com/v1/api-docs.json' ,
129
- name : 'Production Server' ,
130
- } ,
131
- ]
124
+ if ( NODE_ENV === 'production' ) {
125
+ swaggerOptURL = [
126
+ {
127
+ url : 'http://api.example.com/v1/api-docs.json' ,
128
+ name : 'Production Server' ,
129
+ } ,
130
+ ]
131
+ } else if ( NODE_ENV === 'staging' ) {
132
+ swaggerOptURL = [
133
+ {
134
+ url : 'http://api-staging.example.com/v1/api-docs.json' ,
135
+ name : 'Staging Server' ,
136
+ } ,
137
+ ]
138
+ } else {
139
+ swaggerOptURL = [
140
+ {
141
+ url : `http://localhost:${ PORT || 8000 } /v1/api-docs.json` ,
142
+ name : 'Development Server' ,
143
+ } ,
144
+ {
145
+ url : 'http://api-staging.example.com/v1/api-docs.json' ,
146
+ name : 'Staging Server' ,
147
+ } ,
148
+ {
149
+ url : 'http://api.example.com/v1/api-docs.json' ,
150
+ name : 'Production Server' ,
151
+ } ,
152
+ ]
153
+ }
132
154
133
155
const swaggerSpec = swaggerJSDoc ( swaggerOptions )
134
156
const optionsSwaggerUI = {
135
157
explorer : true ,
136
158
swaggerOptions : {
137
- urls : NODE_ENV === 'production' ? swaggerOptProduction : swaggerOptLocal ,
159
+ urls : swaggerOptURL ,
138
160
} ,
139
161
}
140
162
0 commit comments