serverless-openapi-documenter 0.0.60 → 0.0.61
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 +57 -0
- package/package.json +1 -1
- package/src/definitionGenerator.js +23 -0
package/README.md
CHANGED
|
@@ -389,6 +389,23 @@ custom:
|
|
|
389
389
|
|
|
390
390
|
`&ErrorItem` in the above example creates a node anchor (&ErrorItem) to the `ErrorResponse` schema which then can be used in the `PutDocumentResponse` schema via the reference (*ErrorItem). The node anchor needs to be declared first before it can be used elsewhere via the reference, swapping the above example around would result in an error.
|
|
391
391
|
|
|
392
|
+
##### ModelsList - Backwards compatibility
|
|
393
|
+
|
|
394
|
+
It was brought to my attention that an older plugin version allowed the use of `modelsList`. As of 0.0.60, you can continue to use `modelsList` as well as using `models`, however `modelsList` now has to be nested within the `documentation` section. You can write `modelsList` the same way as any of the two styles for [Models](#Models).
|
|
395
|
+
|
|
396
|
+
```
|
|
397
|
+
custom:
|
|
398
|
+
documentation:
|
|
399
|
+
...
|
|
400
|
+
modelsList:
|
|
401
|
+
- name: "ErrorResponse"
|
|
402
|
+
description: "This is an error"
|
|
403
|
+
content:
|
|
404
|
+
application/json:
|
|
405
|
+
schema:
|
|
406
|
+
type: string
|
|
407
|
+
```
|
|
408
|
+
|
|
392
409
|
|
|
393
410
|
#### Functions
|
|
394
411
|
|
|
@@ -605,6 +622,46 @@ functions:
|
|
|
605
622
|
- {}
|
|
606
623
|
```
|
|
607
624
|
|
|
625
|
+
##### private
|
|
626
|
+
|
|
627
|
+
If you use the [private](https://www.serverless.com/framework/docs/providers/aws/events/apigateway#setting-api-keys-for-your-rest-api) property on your event:
|
|
628
|
+
|
|
629
|
+
```yml
|
|
630
|
+
functions:
|
|
631
|
+
getData:
|
|
632
|
+
events:
|
|
633
|
+
- http:
|
|
634
|
+
path: /
|
|
635
|
+
method: get
|
|
636
|
+
private: true
|
|
637
|
+
```
|
|
638
|
+
|
|
639
|
+
It will automatically setup an apiKey security scheme of `x-api-key` attached to that method. You don't need to add this to the [Security Scheme](#securityschemes) in the main documentation. If you have already added a Security Scheme of an `apiKey` with a name of `x-api-key`, it will associate with that key.
|
|
640
|
+
|
|
641
|
+
```yml
|
|
642
|
+
custom:
|
|
643
|
+
documentation:
|
|
644
|
+
securitySchemes:
|
|
645
|
+
my_api_key:
|
|
646
|
+
type: apiKey
|
|
647
|
+
name: x-api-key
|
|
648
|
+
in: header
|
|
649
|
+
security:
|
|
650
|
+
- my_api_key: []
|
|
651
|
+
|
|
652
|
+
functions:
|
|
653
|
+
getData:
|
|
654
|
+
events:
|
|
655
|
+
- http:
|
|
656
|
+
path: /
|
|
657
|
+
method: get
|
|
658
|
+
private: true
|
|
659
|
+
documentation:
|
|
660
|
+
...
|
|
661
|
+
```
|
|
662
|
+
|
|
663
|
+
Will set the Security Scheme to `my_api_key` for that operation.
|
|
664
|
+
|
|
608
665
|
#### `requestModels`
|
|
609
666
|
|
|
610
667
|
The `requestModels` property allows you to define models for the HTTP Request of the function event. You can define a different model for each different `Content-Type`. You can define a reference to the relevant request model named in the `models` section of your configuration (see [Defining Models](#models) section).
|
package/package.json
CHANGED
|
@@ -312,6 +312,29 @@ class DefinitionGenerator {
|
|
|
312
312
|
obj.security = documentation.security
|
|
313
313
|
}
|
|
314
314
|
|
|
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
|
+
|
|
315
338
|
if (Object.keys(documentation).includes('deprecated'))
|
|
316
339
|
obj.deprecated = documentation.deprecated
|
|
317
340
|
|