serverless-openapi-documenter 0.0.52 → 0.0.53
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 +1 -1
- package/src/definitionGenerator.js +29 -29
package/package.json
CHANGED
|
@@ -79,7 +79,7 @@ class DefinitionGenerator {
|
|
|
79
79
|
|
|
80
80
|
if (this.serverless.service.custom.documentation.servers) {
|
|
81
81
|
const servers = this.createServers(this.serverless.service.custom.documentation.servers)
|
|
82
|
-
Object.assign(this.openAPI, {servers: servers})
|
|
82
|
+
Object.assign(this.openAPI, { servers: servers })
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
if (this.serverless.service.custom.documentation.tags) {
|
|
@@ -88,7 +88,7 @@ class DefinitionGenerator {
|
|
|
88
88
|
|
|
89
89
|
if (this.serverless.service.custom.documentation.externalDocumentation) {
|
|
90
90
|
const extDoc = this.createExternalDocumentation(this.serverless.service.custom.documentation.externalDocumentation)
|
|
91
|
-
Object.assign(this.openAPI, {externalDocs: extDoc})
|
|
91
|
+
Object.assign(this.openAPI, { externalDocs: extDoc })
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
|
|
@@ -113,7 +113,7 @@ class DefinitionGenerator {
|
|
|
113
113
|
contactObj.url = documentation.contact.url
|
|
114
114
|
|
|
115
115
|
contactObj.email = documentation.contact.email || ''
|
|
116
|
-
Object.assign(info, {contact: contactObj})
|
|
116
|
+
Object.assign(info, { contact: contactObj })
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
if (documentation.license && documentation.license.name) {
|
|
@@ -123,16 +123,16 @@ class DefinitionGenerator {
|
|
|
123
123
|
if (documentation.license.url)
|
|
124
124
|
licenseObj.url = documentation.license.url || ''
|
|
125
125
|
|
|
126
|
-
Object.assign(info, {license: licenseObj})
|
|
126
|
+
Object.assign(info, { license: licenseObj })
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
for (const key of Object.keys(documentation)) {
|
|
130
130
|
if (/^[x\-]/i.test(key)) {
|
|
131
|
-
Object.assign(info, {[key]: documentation[key]})
|
|
131
|
+
Object.assign(info, { [key]: documentation[key] })
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
-
Object.assign(this.openAPI, {info})
|
|
135
|
+
Object.assign(this.openAPI, { info })
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
async createPaths() {
|
|
@@ -173,18 +173,18 @@ class DefinitionGenerator {
|
|
|
173
173
|
let slashPath = (event?.http?.path || event.httpApi?.path) ?? '/'
|
|
174
174
|
const pathStart = new RegExp(/^\//, 'g')
|
|
175
175
|
if (pathStart.test(slashPath) === false) {
|
|
176
|
-
slashPath = `/${(event?.http?.path||event.httpApi?.path)?? ''}`
|
|
176
|
+
slashPath = `/${(event?.http?.path || event.httpApi?.path) ?? ''}`
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
if (paths[slashPath]) {
|
|
180
180
|
Object.assign(paths[slashPath], path);
|
|
181
181
|
} else {
|
|
182
|
-
Object.assign(paths, {[slashPath]: path});
|
|
182
|
+
Object.assign(paths, { [slashPath]: path });
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
|
-
Object.assign(this.openAPI, {paths})
|
|
187
|
+
Object.assign(this.openAPI, { paths })
|
|
188
188
|
}
|
|
189
189
|
|
|
190
190
|
createServers(servers) {
|
|
@@ -227,7 +227,7 @@ class DefinitionGenerator {
|
|
|
227
227
|
}
|
|
228
228
|
|
|
229
229
|
createExternalDocumentation(docs) {
|
|
230
|
-
return {...docs}
|
|
230
|
+
return { ...docs }
|
|
231
231
|
// const documentation = this.serverless.service.custom.documentation
|
|
232
232
|
// if (documentation.externalDocumentation) {
|
|
233
233
|
// // Object.assign(this.openAPI, {externalDocs: {...documentation.externalDocumentation}})
|
|
@@ -251,7 +251,7 @@ class DefinitionGenerator {
|
|
|
251
251
|
}
|
|
252
252
|
tags.push(obj)
|
|
253
253
|
}
|
|
254
|
-
Object.assign(this.openAPI, {tags: tags})
|
|
254
|
+
Object.assign(this.openAPI, { tags: tags })
|
|
255
255
|
}
|
|
256
256
|
|
|
257
257
|
async createOperationObject(method, documentation, name = uuid()) {
|
|
@@ -323,7 +323,7 @@ class DefinitionGenerator {
|
|
|
323
323
|
obj.servers = servers
|
|
324
324
|
}
|
|
325
325
|
|
|
326
|
-
return {[method.toLowerCase()]: obj}
|
|
326
|
+
return { [method.toLowerCase()]: obj }
|
|
327
327
|
}
|
|
328
328
|
|
|
329
329
|
async createResponses(documentation) {
|
|
@@ -363,7 +363,7 @@ class DefinitionGenerator {
|
|
|
363
363
|
obj.headers = corsHeaders
|
|
364
364
|
}
|
|
365
365
|
|
|
366
|
-
Object.assign(responses,{[response.statusCode]: obj})
|
|
366
|
+
Object.assign(responses, { [response.statusCode]: obj })
|
|
367
367
|
}
|
|
368
368
|
|
|
369
369
|
return responses
|
|
@@ -380,7 +380,7 @@ class DefinitionGenerator {
|
|
|
380
380
|
const newHeaders = {}
|
|
381
381
|
for (const key of Object.keys(this.DEFAULT_CORS_HEADERS)) {
|
|
382
382
|
if (key === 'Access-Control-Allow-Credentials' &&
|
|
383
|
-
this.currentEvent.cors.allowCredentials === undefined || this.currentEvent.cors?.allowCredentials === false) {
|
|
383
|
+
(this.currentEvent.cors.allowCredentials === undefined || this.currentEvent.cors?.allowCredentials === false)) {
|
|
384
384
|
continue
|
|
385
385
|
}
|
|
386
386
|
|
|
@@ -394,7 +394,7 @@ class DefinitionGenerator {
|
|
|
394
394
|
}
|
|
395
395
|
}
|
|
396
396
|
|
|
397
|
-
Object.assign(newHeaders, {[key]: obj})
|
|
397
|
+
Object.assign(newHeaders, { [key]: obj })
|
|
398
398
|
}
|
|
399
399
|
|
|
400
400
|
headers = await this.createResponseHeaders(newHeaders)
|
|
@@ -423,7 +423,7 @@ class DefinitionGenerator {
|
|
|
423
423
|
}
|
|
424
424
|
}
|
|
425
425
|
|
|
426
|
-
Object.assign(obj, {[header]: newHeader})
|
|
426
|
+
Object.assign(obj, { [header]: newHeader })
|
|
427
427
|
}
|
|
428
428
|
|
|
429
429
|
return obj
|
|
@@ -485,7 +485,7 @@ class DefinitionGenerator {
|
|
|
485
485
|
$ref: schemaRef
|
|
486
486
|
}
|
|
487
487
|
|
|
488
|
-
Object.assign(mediaTypeObj, {[contentKey]: obj})
|
|
488
|
+
Object.assign(mediaTypeObj, { [contentKey]: obj })
|
|
489
489
|
}
|
|
490
490
|
}
|
|
491
491
|
return mediaTypeObj
|
|
@@ -557,10 +557,10 @@ class DefinitionGenerator {
|
|
|
557
557
|
const oldRef = originalSchema.$ref
|
|
558
558
|
const path = oldRef.split('/')
|
|
559
559
|
|
|
560
|
-
const pathTitle = path[path.length-1]
|
|
560
|
+
const pathTitle = path[path.length - 1]
|
|
561
561
|
const referencedProperties = deReferencedSchema.definitions[pathTitle]
|
|
562
562
|
|
|
563
|
-
Object.assign(deReferencedSchema, {...referencedProperties})
|
|
563
|
+
Object.assign(deReferencedSchema, { ...referencedProperties })
|
|
564
564
|
|
|
565
565
|
delete deReferencedSchema.$ref
|
|
566
566
|
deReferencedSchema = await this.dereferenceSchema(deReferencedSchema)
|
|
@@ -618,7 +618,7 @@ class DefinitionGenerator {
|
|
|
618
618
|
if (this.openAPI.components[type]) {
|
|
619
619
|
Object.assign(this.openAPI.components[type], schemaObj)
|
|
620
620
|
} else {
|
|
621
|
-
Object.assign(this.openAPI.components, {[type]: schemaObj})
|
|
621
|
+
Object.assign(this.openAPI.components, { [type]: schemaObj })
|
|
622
622
|
}
|
|
623
623
|
} else {
|
|
624
624
|
const components = {
|
|
@@ -639,30 +639,30 @@ class DefinitionGenerator {
|
|
|
639
639
|
if (securityScheme.description)
|
|
640
640
|
schema.description = securityScheme.description
|
|
641
641
|
|
|
642
|
-
switch(securityScheme.type.toLowerCase()) {
|
|
642
|
+
switch (securityScheme.type.toLowerCase()) {
|
|
643
643
|
case 'apikey':
|
|
644
644
|
const apiKeyScheme = this.createAPIKeyScheme(securityScheme)
|
|
645
645
|
schema.type = 'apiKey'
|
|
646
646
|
Object.assign(schema, apiKeyScheme)
|
|
647
|
-
|
|
647
|
+
break;
|
|
648
648
|
|
|
649
649
|
case 'http':
|
|
650
650
|
const HTTPScheme = this.createHTTPScheme(securityScheme)
|
|
651
651
|
schema.type = 'http'
|
|
652
652
|
Object.assign(schema, HTTPScheme)
|
|
653
|
-
|
|
653
|
+
break;
|
|
654
654
|
|
|
655
655
|
case 'openidconnect':
|
|
656
656
|
const openIdConnectScheme = this.createOpenIDConnectScheme(securityScheme)
|
|
657
657
|
schema.type = 'openIdConnect'
|
|
658
658
|
Object.assign(schema, openIdConnectScheme)
|
|
659
|
-
|
|
659
|
+
break;
|
|
660
660
|
|
|
661
661
|
case 'oauth2':
|
|
662
662
|
const oAuth2Scheme = this.createOAuth2Scheme(securityScheme)
|
|
663
663
|
schema.type = 'oauth2'
|
|
664
664
|
Object.assign(schema, oAuth2Scheme)
|
|
665
|
-
|
|
665
|
+
break;
|
|
666
666
|
}
|
|
667
667
|
|
|
668
668
|
this.addToComponents(this.componentTypes.securitySchemes, schema, scheme)
|
|
@@ -712,7 +712,7 @@ class DefinitionGenerator {
|
|
|
712
712
|
const schema = {}
|
|
713
713
|
if (securitySchema.flows) {
|
|
714
714
|
const flows = this.createOAuthFlows(securitySchema.flows)
|
|
715
|
-
Object.assign(schema, {flows: flows})
|
|
715
|
+
Object.assign(schema, { flows: flows })
|
|
716
716
|
} else
|
|
717
717
|
throw new Error('Security Scheme for "oauth2" requires flows')
|
|
718
718
|
|
|
@@ -744,7 +744,7 @@ class DefinitionGenerator {
|
|
|
744
744
|
else
|
|
745
745
|
throw new Error(`oAuth2 ${flow} flow requires scopes`)
|
|
746
746
|
|
|
747
|
-
Object.assign(obj, {[flow]: schema})
|
|
747
|
+
Object.assign(obj, { [flow]: schema })
|
|
748
748
|
}
|
|
749
749
|
return obj
|
|
750
750
|
}
|
|
@@ -752,8 +752,8 @@ class DefinitionGenerator {
|
|
|
752
752
|
createExamples(examples) {
|
|
753
753
|
const examplesObj = {}
|
|
754
754
|
|
|
755
|
-
for(const example of examples) {
|
|
756
|
-
Object.assign(examplesObj, {[example.name]: example})
|
|
755
|
+
for (const example of examples) {
|
|
756
|
+
Object.assign(examplesObj, { [example.name]: example })
|
|
757
757
|
delete examplesObj[example.name].name
|
|
758
758
|
}
|
|
759
759
|
|