serverless-openapi-documenter 0.0.49 → 0.0.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "serverless-openapi-documenter",
3
- "version": "0.0.49",
3
+ "version": "0.0.50",
4
4
  "description": "Generate OpenAPI v3 documentation and Postman Collections from your Serverless Config",
5
5
  "main": "index.js",
6
6
  "keywords": [
@@ -38,7 +38,7 @@
38
38
  "json-schema-for-openapi": "^0.3.2",
39
39
  "lodash.isequal": "^4.5.0",
40
40
  "oas-validator": "^5.0.8",
41
- "openapi-to-postmanv2": "^4.11.0",
41
+ "openapi-to-postmanv2": "^4.12.0",
42
42
  "swagger2openapi": "^7.0.8",
43
43
  "uuid": "^9.0.0"
44
44
  },
@@ -12,7 +12,19 @@ class OpenAPIGenerator {
12
12
  this.logOutput = log;
13
13
  this.serverless = serverless
14
14
  this.options = options
15
- this.defaultLog = 'notice';
15
+
16
+ this.logTypes = {
17
+ NOTICE: 'notice',
18
+ DEBUG: 'debug',
19
+ ERROR: 'error',
20
+ WARNING: 'warning',
21
+ INFO: 'info',
22
+ VERBOSE: 'verbose',
23
+ SUCCESS: 'success',
24
+ }
25
+
26
+ this.defaultLog = this.logTypes.NOTICE;
27
+
16
28
  this.commands = {
17
29
  openapi: {
18
30
  commands: {
@@ -81,7 +93,7 @@ class OpenAPIGenerator {
81
93
  })
82
94
  }
83
95
 
84
- log(type = this.defaultLog, str) {
96
+ log(str, type = this.defaultLog) {
85
97
  switch(this.serverless.version[0]) {
86
98
  case '2':
87
99
  let colouredString = str
@@ -105,7 +117,7 @@ class OpenAPIGenerator {
105
117
  }
106
118
 
107
119
  async generate() {
108
- this.log(this.defaultLog, chalk.bold.underline('OpenAPI v3 Document Generation'))
120
+ this.log(chalk.bold.underline('OpenAPI v3 Document Generation'))
109
121
  this.processCliInput()
110
122
 
111
123
  const validOpenAPI = await this.generationAndValidation()
@@ -129,9 +141,9 @@ class OpenAPIGenerator {
129
141
  }
130
142
  try {
131
143
  fs.writeFileSync(this.config.file, output);
132
- this.log('success', 'OpenAPI v3 Documentation Successfully Written')
144
+ this.log('OpenAPI v3 Documentation Successfully Written', this.logTypes.SUCCESS)
133
145
  } catch (err) {
134
- this.log('error', `ERROR: An error was thrown whilst writing the openAPI Documentation`)
146
+ this.log(`ERROR: An error was thrown whilst writing the openAPI Documentation`, this.logTypes.ERROR)
135
147
  throw new this.serverless.classes.Error(err)
136
148
  }
137
149
  }
@@ -141,19 +153,19 @@ class OpenAPIGenerator {
141
153
 
142
154
  await generator.parse()
143
155
  .catch(err => {
144
- this.log('error', `ERROR: An error was thrown generating the OpenAPI v3 documentation`)
156
+ this.log(`ERROR: An error was thrown generating the OpenAPI v3 documentation`, this.logTypes.ERROR)
145
157
  throw new this.serverless.classes.Error(err)
146
158
  })
147
159
 
148
160
  await generator.validate()
149
161
  .catch(err => {
150
- this.log('error', `ERROR: An error was thrown validating the OpenAPI v3 documentation`)
162
+ this.log(`ERROR: An error was thrown validating the OpenAPI v3 documentation`, this.logTypes.ERROR)
151
163
  this.validationErrorDetails(err)
152
164
  throw new this.serverless.classes.Error(err)
153
165
  })
154
166
 
155
167
 
156
- this.log('success', 'OpenAPI v3 Documentation Successfully Generated')
168
+ this.log('OpenAPI v3 Documentation Successfully Generated', this.logTypes.SUCCESS)
157
169
 
158
170
  return generator.openAPI
159
171
  }
@@ -161,16 +173,16 @@ class OpenAPIGenerator {
161
173
  createPostman(openAPI) {
162
174
  const postmanGeneration = (err, result) => {
163
175
  if (err) {
164
- this.log('error', `ERROR: An error was thrown when generating the postman collection`)
176
+ this.log(`ERROR: An error was thrown when generating the postman collection`, this.logTypes.ERROR)
165
177
  throw new this.serverless.classes.Error(err)
166
178
  }
167
179
 
168
- this.log('success', 'postman collection v2 Documentation Successfully Generated')
180
+ this.log('postman collection v2 Documentation Successfully Generated', this.logTypes.SUCCESS)
169
181
  try {
170
182
  fs.writeFileSync(this.config.postmanCollection, JSON.stringify(result.output[0].data))
171
- this.log('success', 'postman collection v2 Documentation Successfully Written')
183
+ this.log('postman collection v2 Documentation Successfully Written', this.logTypes.SUCCESS)
172
184
  } catch (err) {
173
- this.log('error', `ERROR: An error was thrown whilst writing the postman collection`)
185
+ this.log(`ERROR: An error was thrown whilst writing the postman collection`, this.logTypes.ERROR)
174
186
  throw new this.serverless.classes.Error(err)
175
187
  }
176
188
  }
@@ -204,7 +216,6 @@ class OpenAPIGenerator {
204
216
  ((config.format === 'yaml') ? 'openapi.yml' : 'openapi.json');
205
217
 
206
218
  this.log(
207
- this.defaultLog,
208
219
  `${chalk.bold.green('[OPTIONS]')}
209
220
  openApiVersion: "${chalk.bold.green(String(config.openApiVersion))}"
210
221
  format: "${chalk.bold.green(config.format)}"
@@ -217,9 +228,9 @@ class OpenAPIGenerator {
217
228
  }
218
229
 
219
230
  validationErrorDetails(validationError) {
220
- this.log('error', `${chalk.bold.yellow('[VALIDATION]')} Failed to validate OpenAPI document: \n`);
221
- this.log('error', `${chalk.bold.yellow('Context:')} ${JSON.stringify(validationError.options.context[validationError.options.context.length-1], null, 2)}\n`);
222
- this.log('error', `${chalk.bold.yellow('Error Message:')} ${JSON.stringify(validationError.message, null, 2)}\n`);
231
+ this.log(`${chalk.bold.yellow('[VALIDATION]')} Failed to validate OpenAPI document: \n`, this.logTypes.ERROR);
232
+ this.log(`${chalk.bold.yellow('Context:')} ${JSON.stringify(validationError.options.context[validationError.options.context.length-1], null, 2)}\n`, this.logTypes.ERROR);
233
+ this.log(`${chalk.bold.yellow('Error Message:')} ${JSON.stringify(validationError.message, null, 2)}\n`, this.logTypes.ERROR);
223
234
  }
224
235
  }
225
236