serverless-openapi-documenter 0.0.25 → 0.0.26
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 +38 -21
- package/package.json +1 -1
- package/src/definitionGenerator.js +29 -0
package/README.md
CHANGED
|
@@ -350,6 +350,24 @@ cookieParams:
|
|
|
350
350
|
type: "string"
|
|
351
351
|
```
|
|
352
352
|
|
|
353
|
+
#### `headerParams` - Request Headers
|
|
354
|
+
|
|
355
|
+
Request Headers can be described as follow:
|
|
356
|
+
|
|
357
|
+
* `name`: the name of the query variable
|
|
358
|
+
* `description`: a description of the query variable
|
|
359
|
+
* `required`: whether the query parameter is mandatory (boolean)
|
|
360
|
+
* `schema`: JSON schema (inline, file or externally hosted)
|
|
361
|
+
|
|
362
|
+
```yml
|
|
363
|
+
headerParams:
|
|
364
|
+
- name: "Content-Type"
|
|
365
|
+
description: "The content type"
|
|
366
|
+
required: true
|
|
367
|
+
schema:
|
|
368
|
+
type: "string"
|
|
369
|
+
```
|
|
370
|
+
|
|
353
371
|
#### `requestModels`
|
|
354
372
|
|
|
355
373
|
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).
|
|
@@ -369,14 +387,24 @@ For an example of a `methodResponses` configuration for an event see below:
|
|
|
369
387
|
```yml
|
|
370
388
|
methodResponse:
|
|
371
389
|
- statusCode: 200
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
description: "Content Type header"
|
|
375
|
-
schema:
|
|
376
|
-
type: "string"
|
|
390
|
+
responseBody:
|
|
391
|
+
description: Success
|
|
377
392
|
responseModels:
|
|
378
393
|
application/json: "CreateResponse"
|
|
379
394
|
application/xml: "CreateResponseXML"
|
|
395
|
+
responseHeaders:
|
|
396
|
+
X-Rate-Limit-Limit:
|
|
397
|
+
description: The number of allowed requests in the current period
|
|
398
|
+
schema:
|
|
399
|
+
type: integer
|
|
400
|
+
X-Rate-Limit-Remaining:
|
|
401
|
+
description: The number of remaining requests in the current period
|
|
402
|
+
schema:
|
|
403
|
+
type: integer
|
|
404
|
+
X-Rate-Limit-Reset:
|
|
405
|
+
description: The number of seconds left in the current period
|
|
406
|
+
schema:
|
|
407
|
+
type: integer
|
|
380
408
|
```
|
|
381
409
|
|
|
382
410
|
##### `responseModels`
|
|
@@ -389,27 +417,16 @@ responseModels:
|
|
|
389
417
|
application/xml: "CreateResponseXML"
|
|
390
418
|
```
|
|
391
419
|
|
|
392
|
-
##### `responseHeaders`
|
|
393
|
-
|
|
394
|
-
The `responseHeaders/requestHeaders` section of the configuration allows you to define the HTTP headers for the function event.
|
|
420
|
+
##### `responseHeaders`
|
|
395
421
|
|
|
396
|
-
The
|
|
397
|
-
|
|
398
|
-
* `name`: the name of the HTTP Header
|
|
399
|
-
* `description`: a description of the HTTP Header
|
|
400
|
-
* `schema`: JSON schema (inline, file or externally hosted)
|
|
422
|
+
The `responseHeaders` property allows you to define the headers expected in a HTTP Response of the function event. This should only contain a description and a schema, which must be a JSON schema (inline, file or externally hosted).
|
|
401
423
|
|
|
402
424
|
```yml
|
|
403
425
|
responseHeaders:
|
|
404
|
-
-
|
|
405
|
-
description:
|
|
426
|
+
X-Rate-Limit-Limit:
|
|
427
|
+
description: The number of allowed requests in the current period
|
|
406
428
|
schema:
|
|
407
|
-
type:
|
|
408
|
-
requestHeaders:
|
|
409
|
-
- name: "Content-Type"
|
|
410
|
-
description: "Content Type header"
|
|
411
|
-
schema:
|
|
412
|
-
type: "string"
|
|
429
|
+
type: integer
|
|
413
430
|
```
|
|
414
431
|
|
|
415
432
|
## Example configuration
|
package/package.json
CHANGED
|
@@ -271,12 +271,41 @@ class DefinitionGenerator {
|
|
|
271
271
|
throw err
|
|
272
272
|
})
|
|
273
273
|
|
|
274
|
+
if (response.responseHeaders) {
|
|
275
|
+
obj.headers = await this.createResponseHeaders(response.responseHeaders)
|
|
276
|
+
.catch(err => {
|
|
277
|
+
throw err
|
|
278
|
+
})
|
|
279
|
+
}
|
|
280
|
+
|
|
274
281
|
Object.assign(responses,{[response.statusCode]: obj})
|
|
275
282
|
}
|
|
276
283
|
|
|
277
284
|
return responses
|
|
278
285
|
}
|
|
279
286
|
|
|
287
|
+
async createResponseHeaders(headers) {
|
|
288
|
+
const obj = {}
|
|
289
|
+
for (const header of Object.keys(headers)) {
|
|
290
|
+
const newHeader = {}
|
|
291
|
+
newHeader.description = headers[header].description || ''
|
|
292
|
+
|
|
293
|
+
if (headers[header].schema) {
|
|
294
|
+
const schemaRef = await this.schemaCreator(headers[header].schema, header)
|
|
295
|
+
.catch(err => {
|
|
296
|
+
throw err
|
|
297
|
+
})
|
|
298
|
+
newHeader.schema = {
|
|
299
|
+
$ref: schemaRef
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
Object.assign(obj, {[header]: newHeader})
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
return obj
|
|
307
|
+
}
|
|
308
|
+
|
|
280
309
|
async createRequestBody(documentation) {
|
|
281
310
|
const obj = {
|
|
282
311
|
description: documentation.requestBody.description,
|