serverless-openapi-documenter 0.0.13 → 0.0.15

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.13",
3
+ "version": "0.0.15",
4
4
  "description": "Generate OpenAPI v3 documentation and Postman Collections from your Serverless Config",
5
5
  "main": "index.js",
6
6
  "keywords": [
@@ -83,10 +83,17 @@ class OpenAPIGenerator {
83
83
  })
84
84
  }
85
85
 
86
- log(type = this.defaultLog, ...str) {
86
+ log(type = this.defaultLog, str) {
87
87
  switch(this.serverless.version[0]) {
88
88
  case '2':
89
- this.serverless.cli.log(str)
89
+ let colouredString = str
90
+ if (type === 'error') {
91
+ colouredString = chalk.bold.red(`✖ ${str}`)
92
+ } else if (type === 'success') {
93
+ colouredString = chalk.bold.green(`✓ ${str}`)
94
+ }
95
+
96
+ this.serverless.cli.log(colouredString)
90
97
  break
91
98
 
92
99
  case '3':
@@ -106,32 +113,32 @@ class OpenAPIGenerator {
106
113
 
107
114
  await generator.parse()
108
115
  .catch(err => {
109
- this.log('error', chalk.bold.red(`ERROR: An error was thrown generating the OpenAPI v3 documentation`))
116
+ this.log('error', `ERROR: An error was thrown generating the OpenAPI v3 documentation`)
110
117
  throw new this.serverless.classes.Error(err)
111
118
  })
112
119
 
113
120
  const valid = await generator.validate()
114
121
  .catch(err => {
115
- this.log('error', chalk.bold.red(`ERROR: An error was thrown validating the OpenAPI v3 documentation`))
122
+ this.log('error', `ERROR: An error was thrown validating the OpenAPI v3 documentation`)
116
123
  throw new this.serverless.classes.Error(err)
117
124
  })
118
125
 
119
126
  if (valid)
120
- this.log(this.defaultLog, chalk.bold.green('OpenAPI v3 Documentation Successfully Generated'))
127
+ this.log('success', 'OpenAPI v3 Documentation Successfully Generated')
121
128
 
122
129
  if (config.postmanCollection) {
123
130
  const postmanGeneration = (err, result) => {
124
131
  if (err) {
125
- this.log('error', chalk.bold.red(`ERROR: An error was thrown when generating the postman collection`))
132
+ this.log('error', `ERROR: An error was thrown when generating the postman collection`)
126
133
  throw new this.serverless.classes.Error(err)
127
134
  }
128
135
 
129
- this.log(this.defaultLog, chalk.bold.green('postman collection v2 Documentation Successfully Generated'))
136
+ this.log('success', 'postman collection v2 Documentation Successfully Generated')
130
137
  try {
131
138
  fs.writeFileSync(config.postmanCollection, JSON.stringify(result.output[0].data))
132
- this.log(this.defaultLog, chalk.bold.green('postman collection v2 Documentation Successfully Written'))
139
+ this.log('success', 'postman collection v2 Documentation Successfully Written')
133
140
  } catch (err) {
134
- this.log('error', chalk.bold.red(`ERROR: An error was thrown whilst writing the postman collection`))
141
+ this.log('error', `ERROR: An error was thrown whilst writing the postman collection`)
135
142
  throw new this.serverless.classes.Error(err)
136
143
  }
137
144
  }
@@ -155,9 +162,9 @@ class OpenAPIGenerator {
155
162
  }
156
163
  try {
157
164
  fs.writeFileSync(config.file, output);
158
- this.log(this.defaultLog, chalk.bold.green('OpenAPI v3 Documentation Successfully Written'))
165
+ this.log('success', 'OpenAPI v3 Documentation Successfully Written')
159
166
  } catch (err) {
160
- this.log('error', chalk.bold.red(`ERROR: An error was thrown whilst writing the openAPI Documentation`))
167
+ this.log('error', `ERROR: An error was thrown whilst writing the openAPI Documentation`)
161
168
  throw new this.serverless.classes.Error(err)
162
169
  }
163
170
  }
@@ -177,7 +184,8 @@ class OpenAPIGenerator {
177
184
  config.postmanCollection = this.serverless.processedInput.options.postmanCollection || null
178
185
 
179
186
  if (['yaml', 'json'].indexOf(config.format.toLowerCase()) < 0) {
180
- throw new Error('Invalid Output Format Specified - must be one of "yaml" or "json"');
187
+ // throw new Error('Invalid Output Format Specified - must be one of "yaml" or "json"');
188
+ throw new this.serverless.classes.Error('Invalid Output Format Specified - must be one of "yaml" or "json"')
181
189
  }
182
190
 
183
191
  config.file = this.serverless.processedInput.options.output ||
@@ -185,12 +193,12 @@ class OpenAPIGenerator {
185
193
 
186
194
  this.log(
187
195
  this.defaultLog,
188
- `${chalk.bold.green('[OPTIONS]')}`,
189
- ` openApiVersion: "${chalk.bold.red(String(config.openApiVersion))}"`,
190
- ` format: "${chalk.bold.red(config.format)}"`,
191
- ` output file: "${chalk.bold.red(config.file)}"`,
192
- ` indentation: "${chalk.bold.red(String(config.indent))}"`,
193
- ` ${config.postmanCollection ? `postman collection: ${chalk.bold.red(config.postmanCollection)}`: `\n\n`}`
196
+ `${chalk.bold.green('[OPTIONS]')}
197
+ openApiVersion: "${chalk.bold.green(String(config.openApiVersion))}"
198
+ format: "${chalk.bold.green(config.format)}"
199
+ output file: "${chalk.bold.green(config.file)}"
200
+ indentation: "${chalk.bold.green(String(config.indent))}"
201
+ ${config.postmanCollection ? `postman collection: ${chalk.bold.green(config.postmanCollection)}`: `\n\n`}`
194
202
  )
195
203
 
196
204
  return config
@@ -12,11 +12,16 @@ functions:
12
12
  handler: handler.create
13
13
  events:
14
14
  - http:
15
- path: create
15
+ path: create/{username}
16
16
  method: post
17
17
  documentation:
18
18
  summary: Create User
19
19
  description: Creates a user and then sends a generated password email
20
+ tags:
21
+ - jesus
22
+ externalDocumentation:
23
+ url: https://bing.com
24
+ description: A link to bing
20
25
  requestBody:
21
26
  description: A user information object
22
27
  requestModels:
@@ -54,25 +59,30 @@ functions:
54
59
 
55
60
  custom:
56
61
  documentation:
62
+ description: This is a description of what this does
63
+ version: 1.0.0
57
64
  models:
58
65
  - name: ErrorResponse
59
66
  description: This is an error
60
- contentType: application/json
61
- schema: ${file(models/ErrorResponse.json)}
67
+ content:
68
+ application/json:
69
+ schema: ${file(../models/ErrorResponse.json)}
62
70
 
63
71
  - name: PutDocumentResponse
64
72
  description: PUT Document response model (external reference example)
65
- contentType: application/json
66
- schema: ${file(models/PutDocumentResponse.json)}
73
+ content:
74
+ application/json:
75
+ schema: ${file(../models/PutDocumentResponse.json)}
67
76
 
68
77
  - name: PutDocumentRequest
69
78
  description: PUT Document request model (inline example)
70
- contentType: application/json
71
- schema:
72
- $schema: http://json-schema.org/draft-04/schema#
73
- properties:
74
- SomeObject:
75
- type: object
79
+ content:
80
+ application/json:
81
+ schema:
82
+ $schema: http://json-schema.org/draft-04/schema#
76
83
  properties:
77
- SomeAttribute:
78
- type: string
84
+ SomeObject:
85
+ type: object
86
+ properties:
87
+ SomeAttribute:
88
+ type: string