Skip to content

Commit 98a695a

Browse files
committed
Add in x-api-key generation for private events
1 parent 70c9801 commit 98a695a

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/definitionGenerator.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,29 @@ class DefinitionGenerator {
312312
obj.security = documentation.security
313313
}
314314

315+
if (this.currentEvent?.private && this.currentEvent.private === true) {
316+
let apiKeyName = 'x-api-key'
317+
let hasXAPIKey = false
318+
if (this.openAPI?.components?.[this.componentTypes.securitySchemes]) {
319+
for (const [schemeName, schemeValue] of Object.entries(this.openAPI.components[this.componentTypes.securitySchemes])) {
320+
if (schemeValue.type === 'apiKey' && schemeValue.name === 'x-api-key') {
321+
apiKeyName = schemeName
322+
hasXAPIKey = true
323+
}
324+
}
325+
}
326+
327+
if (hasXAPIKey === false) {
328+
this.createSecuritySchemes({[apiKeyName]: {type: 'apiKey', name: apiKeyName, in: 'header'}})
329+
}
330+
331+
if (obj.security) {
332+
obj.security.push({[apiKeyName]: []})
333+
} else {
334+
obj.security = [{[apiKeyName]: []}]
335+
}
336+
}
337+
315338
if (Object.keys(documentation).includes('deprecated'))
316339
obj.deprecated = documentation.deprecated
317340

0 commit comments

Comments
 (0)