Skip to content

Commit 5ee7eb4

Browse files
committed
update README
1 parent ba4f7a0 commit 5ee7eb4

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ Options:
6161
#### Model Details
6262
* [Models](#models)
6363
* [Notes on Schemas](#notes-on-schemas)
64+
* [Request Schema Validators](#serverless-request-schema-validators)
6465
#### Response Headers
6566
* [CORS](#cors)
6667
* [OWASP Secure Headers](#owasp)
@@ -409,6 +410,76 @@ custom:
409410
type: string
410411
```
411412
413+
##### Serverless Request Schema Validators
414+
415+
As of 0.0.64, you can now make use of [Request Schema Validators](https://www.serverless.com/framework/docs/providers/aws/events/apigateway#request-schema-validators). This allows you to define Request models via the `apiGateway` settings:
416+
417+
```yml
418+
provider:
419+
...
420+
apiGateway:
421+
request:
422+
schemas:
423+
post-create-model:
424+
name: PostCreateModel
425+
schema: ${file(api_schema/post_add_schema.json)}
426+
description: "A Model validation for adding posts"
427+
```
428+
429+
which are then used like:
430+
431+
```yml
432+
functions:
433+
create:
434+
handler: posts.create
435+
events:
436+
- http:
437+
path: posts/create
438+
method: post
439+
request:
440+
schemas:
441+
application/json: post-create-model
442+
documentation:
443+
...
444+
```
445+
446+
The generator will match to the model within the `apiGateway` settings model list. If you are using the `apiGateway` to define models, please do not re-use any names that you might define in the [`models`](#models) list.
447+
448+
You can also skip writing a `requestBody` and `requestModels` if you have defined a `request` property in your event.
449+
450+
If you're not using `apiGateway`, you can still make use of `request` by writing in the other styles that serverless accepts for Request Schema Validators:
451+
452+
```yml
453+
functions:
454+
create:
455+
handler: posts.create
456+
events:
457+
- http:
458+
path: posts/create
459+
method: post
460+
request:
461+
schemas:
462+
application/json:
463+
schema: ${file(create_request.json)}
464+
name: PostCreateModel
465+
description: 'Validation model for Creating Posts'
466+
467+
```
468+
469+
or
470+
471+
```yml
472+
functions:
473+
create:
474+
handler: posts.create
475+
events:
476+
- http:
477+
path: posts/create
478+
method: post
479+
request:
480+
schemas:
481+
application/json: ${file(create_request.json)}
482+
```
412483

413484
#### Functions
414485

0 commit comments

Comments
 (0)