serverless-openapi-documenter 0.0.4 → 0.0.5

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/README.md CHANGED
@@ -46,10 +46,14 @@ Options:
46
46
  | info.description | custom.documentation.description OR blank string |
47
47
  | info.version | custom.documentation.version OR random v4 uuid if not provided |
48
48
  | externalDocs.description | custom.documentation.externalDocumentation.description |
49
- | externalDocs.url | custom.documenation.externalDocumentation.url |
49
+ | externalDocs.url | custom.documentation.externalDocumentation.url |
50
+ | servers[].description | custom.documentation.servers.description |
51
+ | servers[].url | custom.documentation.servers.url |
50
52
  | path[path] | functions.functions.events.[http OR httpApi].path |
51
53
  | path[path].summary | functions.functions.summary |
52
54
  | path[path].description | functions.functions.description |
55
+ | path[path].servers[].description | functions.functions.servers.description |
56
+ | path[path].servers[].url | functions.functions.servers.url |
53
57
  | path[path].[operation] | functions.functions.[http OR httpApi].method |
54
58
  | path[path].[operation].summary | functions.functions.[http OR httpApi].documentation.summary |
55
59
  | path[path].[operation].description | functions.functions.[http OR httpApi].documentation.description |
@@ -57,6 +61,8 @@ Options:
57
61
  | path[path].[operation].deprecated | functions.functions.[http OR httpApi].documentation.deprecated |
58
62
  | path[path].[operation].externalDocs.description | functions.functions.[http OR httpApi].documentation.externalDocumentation.description |
59
63
  | path[path].[operation].externalDocs.url | functions.functions.[http OR httpApi].documentation.externalDocumentation.url |
64
+ | path[path].[operation].servers[].description | functions.functions.[http OR httpApi].documentation.servers.description |
65
+ | path[path].[operation].servers[].url | functions.functions.[http OR httpApi].documentation.servers.url |
60
66
  | path[path].[operation].deprecated | functions.functions.[http OR httpApi].documentation.deprecated |
61
67
  | path[path].[operation].parameters | functions.functions.[http OR httpApi].documentation.[path|query|cookie|header]Params |
62
68
  | path[path].[operation].parameters.name | functions.functions.[http OR httpApi].documentation.[path|query|cookie|header]Params.name |
@@ -97,6 +103,9 @@ custom:
97
103
  externalDocumentation:
98
104
  url: https://google.com
99
105
  description: A link to google
106
+ servers:
107
+ url: https://example.com
108
+ description: The server
100
109
  ```
101
110
 
102
111
  These configurations can be quite verbose; you can separate it out into it's own file, such as `serverless.doc.yml` as below:
package/package.json CHANGED
@@ -1,9 +1,18 @@
1
1
  {
2
2
  "name": "serverless-openapi-documenter",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "Generate OpenAPI v3 documentation and Postman Collections from your Serverless Config",
5
5
  "main": "index.js",
6
- "keywords": ["serverless", "serverless2", "serverless3", "openAPI", "openAPIv3", "openAPI3", "PostmanCollections", "Postman-Collections"],
6
+ "keywords": [
7
+ "serverless",
8
+ "serverless2",
9
+ "serverless3",
10
+ "openAPI",
11
+ "openAPIv3",
12
+ "openAPI3",
13
+ "PostmanCollections",
14
+ "Postman-Collections"
15
+ ],
7
16
  "scripts": {
8
17
  "test": "echo \"Error: no test specified\" && exit 1"
9
18
  },
@@ -18,9 +27,6 @@
18
27
  "url": "https://github.com/JaredCE/serverless-openapi-documenter/issues"
19
28
  },
20
29
  "license": "MIT",
21
- "devDependencies": {
22
- "serverless": "^3.17.0"
23
- },
24
30
  "dependencies": {
25
31
  "chalk": "^4.1.2",
26
32
  "js-yaml": "^4.1.0",
@@ -6,7 +6,7 @@ const SchemaConvertor = require('json-schema-for-openapi')
6
6
 
7
7
  class DefinitionGenerator {
8
8
  constructor(serverless, options = {}) {
9
- this.version = options.v || '3.0.0'
9
+ this.version = serverless.processedInput.options.openApiVersion || '3.0.0'
10
10
 
11
11
  this.serverless = serverless
12
12
  this.httpKeys = {
@@ -29,6 +29,10 @@ class DefinitionGenerator {
29
29
  parse() {
30
30
  this.createInfo()
31
31
  this.createPaths()
32
+ if (this.serverless.service.custom.documentation.servers) {
33
+ const servers = this.createServers(this.serverless.service.custom.documentation.servers)
34
+ Object.assign(this.openAPI, {servers: servers})
35
+ }
32
36
  this.createExternalDocumentation()
33
37
  }
34
38
 
@@ -68,6 +72,11 @@ class DefinitionGenerator {
68
72
  if (httpFunction.functionInfo?.description)
69
73
  path.description = httpFunction.functionInfo.description
70
74
 
75
+ if (httpFunction.functionInfo?.servers) {
76
+ const servers = this.createServers(httpFunction.functionInfo.servers)
77
+ path.servers = servers
78
+ }
79
+
71
80
  let slashPath = event.http.path
72
81
  const pathStart = new RegExp(/^\//, 'g')
73
82
  if (pathStart.test(slashPath) === false) {
@@ -81,6 +90,37 @@ class DefinitionGenerator {
81
90
  Object.assign(this.openAPI, {paths})
82
91
  }
83
92
 
93
+ createServers(servers) {
94
+ const serverDoc = servers
95
+ const newServers = []
96
+
97
+ if (Array.isArray(serverDoc)) {
98
+ for (const server of serverDoc) {
99
+ const obj = {
100
+ url: server.url,
101
+ }
102
+
103
+ if (server.description) {
104
+ obj.description = server.description
105
+ }
106
+
107
+ newServers.push(obj)
108
+ }
109
+ } else {
110
+ const obj = {
111
+ url: servers.url,
112
+ }
113
+
114
+ if (servers.description) {
115
+ obj.description = servers.description
116
+ }
117
+
118
+ newServers.push(obj)
119
+ }
120
+
121
+ return newServers
122
+ }
123
+
84
124
  createExternalDocumentation() {
85
125
  const documentation = this.serverless.service.custom.documentation
86
126
  if (documentation.externalDocumentation) {
@@ -130,6 +170,11 @@ class DefinitionGenerator {
130
170
  if (documentation.methodResponses)
131
171
  obj.responses = this.createResponses(documentation)
132
172
 
173
+ if (documentation.servers) {
174
+ const servers = this.createServers(documentation.servers)
175
+ obj.servers = servers
176
+ }
177
+
133
178
  return {[method]: obj}
134
179
  }
135
180
 
@@ -70,7 +70,8 @@ class OpenAPIGenerator {
70
70
  this.serverless.configSchemaHandler.defineFunctionProperties('aws', {
71
71
  properties: {
72
72
  // description: {type: 'string'},
73
- summary: {type: 'string'}
73
+ summary: {type: 'string'},
74
+ servers: {type: ['object', 'array']},
74
75
  }
75
76
  })
76
77
  }
@@ -126,7 +127,7 @@ class OpenAPIGenerator {
126
127
  }
127
128
 
128
129
  const postmanCollection = PostmanGenerator.convert(
129
- {type: 'json', data: generator.openAPI},
130
+ {type: 'json', data: JSON.parse(JSON.stringify(generator.openAPI))},
130
131
  {},
131
132
  postmanGeneration
132
133
  )