Skip to content

Commit 3e581c6

Browse files
authored
Merge pull request #107 from JaredCE/fix-CORS-generation
Fix cors generation
2 parents 11ba3b7 + 401c11c commit 3e581c6

File tree

3 files changed

+32
-32
lines changed

3 files changed

+32
-32
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "serverless-openapi-documenter",
3-
"version": "0.0.52",
3+
"version": "0.0.53",
44
"description": "Generate OpenAPI v3 documentation and Postman Collections from your Serverless Config",
55
"main": "index.js",
66
"keywords": [

src/definitionGenerator.js

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class DefinitionGenerator {
7979

8080
if (this.serverless.service.custom.documentation.servers) {
8181
const servers = this.createServers(this.serverless.service.custom.documentation.servers)
82-
Object.assign(this.openAPI, {servers: servers})
82+
Object.assign(this.openAPI, { servers: servers })
8383
}
8484

8585
if (this.serverless.service.custom.documentation.tags) {
@@ -88,7 +88,7 @@ class DefinitionGenerator {
8888

8989
if (this.serverless.service.custom.documentation.externalDocumentation) {
9090
const extDoc = this.createExternalDocumentation(this.serverless.service.custom.documentation.externalDocumentation)
91-
Object.assign(this.openAPI, {externalDocs: extDoc})
91+
Object.assign(this.openAPI, { externalDocs: extDoc })
9292
}
9393
}
9494

@@ -113,7 +113,7 @@ class DefinitionGenerator {
113113
contactObj.url = documentation.contact.url
114114

115115
contactObj.email = documentation.contact.email || ''
116-
Object.assign(info, {contact: contactObj})
116+
Object.assign(info, { contact: contactObj })
117117
}
118118

119119
if (documentation.license && documentation.license.name) {
@@ -123,16 +123,16 @@ class DefinitionGenerator {
123123
if (documentation.license.url)
124124
licenseObj.url = documentation.license.url || ''
125125

126-
Object.assign(info, {license: licenseObj})
126+
Object.assign(info, { license: licenseObj })
127127
}
128128

129129
for (const key of Object.keys(documentation)) {
130130
if (/^[x\-]/i.test(key)) {
131-
Object.assign(info, {[key]: documentation[key]})
131+
Object.assign(info, { [key]: documentation[key] })
132132
}
133133
}
134134

135-
Object.assign(this.openAPI, {info})
135+
Object.assign(this.openAPI, { info })
136136
}
137137

138138
async createPaths() {
@@ -173,18 +173,18 @@ class DefinitionGenerator {
173173
let slashPath = (event?.http?.path || event.httpApi?.path) ?? '/'
174174
const pathStart = new RegExp(/^\//, 'g')
175175
if (pathStart.test(slashPath) === false) {
176-
slashPath = `/${(event?.http?.path||event.httpApi?.path)?? ''}`
176+
slashPath = `/${(event?.http?.path || event.httpApi?.path) ?? ''}`
177177
}
178178

179179
if (paths[slashPath]) {
180180
Object.assign(paths[slashPath], path);
181181
} else {
182-
Object.assign(paths, {[slashPath]: path});
182+
Object.assign(paths, { [slashPath]: path });
183183
}
184184
}
185185
}
186186
}
187-
Object.assign(this.openAPI, {paths})
187+
Object.assign(this.openAPI, { paths })
188188
}
189189

190190
createServers(servers) {
@@ -227,7 +227,7 @@ class DefinitionGenerator {
227227
}
228228

229229
createExternalDocumentation(docs) {
230-
return {...docs}
230+
return { ...docs }
231231
// const documentation = this.serverless.service.custom.documentation
232232
// if (documentation.externalDocumentation) {
233233
// // Object.assign(this.openAPI, {externalDocs: {...documentation.externalDocumentation}})
@@ -251,7 +251,7 @@ class DefinitionGenerator {
251251
}
252252
tags.push(obj)
253253
}
254-
Object.assign(this.openAPI, {tags: tags})
254+
Object.assign(this.openAPI, { tags: tags })
255255
}
256256

257257
async createOperationObject(method, documentation, name = uuid()) {
@@ -323,7 +323,7 @@ class DefinitionGenerator {
323323
obj.servers = servers
324324
}
325325

326-
return {[method.toLowerCase()]: obj}
326+
return { [method.toLowerCase()]: obj }
327327
}
328328

329329
async createResponses(documentation) {
@@ -363,7 +363,7 @@ class DefinitionGenerator {
363363
obj.headers = corsHeaders
364364
}
365365

366-
Object.assign(responses,{[response.statusCode]: obj})
366+
Object.assign(responses, { [response.statusCode]: obj })
367367
}
368368

369369
return responses
@@ -380,7 +380,7 @@ class DefinitionGenerator {
380380
const newHeaders = {}
381381
for (const key of Object.keys(this.DEFAULT_CORS_HEADERS)) {
382382
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)) {
384384
continue
385385
}
386386

@@ -394,7 +394,7 @@ class DefinitionGenerator {
394394
}
395395
}
396396

397-
Object.assign(newHeaders, {[key]: obj})
397+
Object.assign(newHeaders, { [key]: obj })
398398
}
399399

400400
headers = await this.createResponseHeaders(newHeaders)
@@ -423,7 +423,7 @@ class DefinitionGenerator {
423423
}
424424
}
425425

426-
Object.assign(obj, {[header]: newHeader})
426+
Object.assign(obj, { [header]: newHeader })
427427
}
428428

429429
return obj
@@ -485,7 +485,7 @@ class DefinitionGenerator {
485485
$ref: schemaRef
486486
}
487487

488-
Object.assign(mediaTypeObj, {[contentKey]: obj})
488+
Object.assign(mediaTypeObj, { [contentKey]: obj })
489489
}
490490
}
491491
return mediaTypeObj
@@ -557,10 +557,10 @@ class DefinitionGenerator {
557557
const oldRef = originalSchema.$ref
558558
const path = oldRef.split('/')
559559

560-
const pathTitle = path[path.length-1]
560+
const pathTitle = path[path.length - 1]
561561
const referencedProperties = deReferencedSchema.definitions[pathTitle]
562562

563-
Object.assign(deReferencedSchema, {...referencedProperties})
563+
Object.assign(deReferencedSchema, { ...referencedProperties })
564564

565565
delete deReferencedSchema.$ref
566566
deReferencedSchema = await this.dereferenceSchema(deReferencedSchema)
@@ -618,7 +618,7 @@ class DefinitionGenerator {
618618
if (this.openAPI.components[type]) {
619619
Object.assign(this.openAPI.components[type], schemaObj)
620620
} else {
621-
Object.assign(this.openAPI.components, {[type]: schemaObj})
621+
Object.assign(this.openAPI.components, { [type]: schemaObj })
622622
}
623623
} else {
624624
const components = {
@@ -639,30 +639,30 @@ class DefinitionGenerator {
639639
if (securityScheme.description)
640640
schema.description = securityScheme.description
641641

642-
switch(securityScheme.type.toLowerCase()) {
642+
switch (securityScheme.type.toLowerCase()) {
643643
case 'apikey':
644644
const apiKeyScheme = this.createAPIKeyScheme(securityScheme)
645645
schema.type = 'apiKey'
646646
Object.assign(schema, apiKeyScheme)
647-
break;
647+
break;
648648

649649
case 'http':
650650
const HTTPScheme = this.createHTTPScheme(securityScheme)
651651
schema.type = 'http'
652652
Object.assign(schema, HTTPScheme)
653-
break;
653+
break;
654654

655655
case 'openidconnect':
656656
const openIdConnectScheme = this.createOpenIDConnectScheme(securityScheme)
657657
schema.type = 'openIdConnect'
658658
Object.assign(schema, openIdConnectScheme)
659-
break;
659+
break;
660660

661661
case 'oauth2':
662662
const oAuth2Scheme = this.createOAuth2Scheme(securityScheme)
663663
schema.type = 'oauth2'
664664
Object.assign(schema, oAuth2Scheme)
665-
break;
665+
break;
666666
}
667667

668668
this.addToComponents(this.componentTypes.securitySchemes, schema, scheme)
@@ -712,7 +712,7 @@ class DefinitionGenerator {
712712
const schema = {}
713713
if (securitySchema.flows) {
714714
const flows = this.createOAuthFlows(securitySchema.flows)
715-
Object.assign(schema, {flows: flows})
715+
Object.assign(schema, { flows: flows })
716716
} else
717717
throw new Error('Security Scheme for "oauth2" requires flows')
718718

@@ -744,16 +744,16 @@ class DefinitionGenerator {
744744
else
745745
throw new Error(`oAuth2 ${flow} flow requires scopes`)
746746

747-
Object.assign(obj, {[flow]: schema})
747+
Object.assign(obj, { [flow]: schema })
748748
}
749749
return obj
750750
}
751751

752752
createExamples(examples) {
753753
const examplesObj = {}
754754

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 })
757757
delete examplesObj[example.name].name
758758
}
759759

0 commit comments

Comments
 (0)