You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[Specify Name and Description](#specify-name-and-description)
@@ -933,6 +934,88 @@ Please note that those are the API keys names, not the actual values. Once you d
933
934
934
935
Clients connecting to this Rest API will then need to set any of these API keys values in the x-api-key header of their request. This is only necessary for functions where the private property is set to true.
935
936
937
+
#### Request Schema Validators
938
+
939
+
To use [request schema validation](https://serverless.com/framework/docs/providers/aws/events/apigateway/#request-schema-validators) with API gateway, add the [JSON Schema](https://json-schema.org/) for your content type. Since JSON Schema is represented in JSON, it's easier to include it from a file.
940
+
941
+
```yaml
942
+
stepFunctions:
943
+
stateMachines:
944
+
create:
945
+
events:
946
+
- http:
947
+
path: posts/create
948
+
method: post
949
+
request:
950
+
schemas:
951
+
application/json: ${file(create_request.json)}
952
+
```
953
+
954
+
In addition, you can also customize created model with name and description properties.
955
+
956
+
```yaml
957
+
stepFunctions:
958
+
stateMachines:
959
+
create:
960
+
events:
961
+
- http:
962
+
path: posts/create
963
+
method: post
964
+
request:
965
+
schemas:
966
+
application/json:
967
+
schema: ${file(create_request.json)}
968
+
name: PostCreateModel
969
+
description: 'Validation model for Creating Posts'
970
+
```
971
+
972
+
To reuse the same model across different events, you can define global models on provider level. In order to define global model you need to add its configuration to `provider.apiGateway.request.schemas`. After defining a global model, you can use it in the event by referencing it by the key. Provider models are created for application/json content type.
973
+
974
+
```yaml
975
+
provider:
976
+
...
977
+
apiGateway:
978
+
request:
979
+
schemas:
980
+
post-create-model:
981
+
name: PostCreateModel
982
+
schema: ${file(api_schema/post_add_schema.json)}
983
+
description: "A Model validation for adding posts"
984
+
985
+
stepFunctions:
986
+
stateMachines:
987
+
create:
988
+
events:
989
+
- http:
990
+
path: posts/create
991
+
method: post
992
+
request:
993
+
schemas:
994
+
application/json: post-create-model
995
+
```
996
+
997
+
A sample schema contained in `create_request.json` might look something like this:
**NOTE:** schema validators are only applied to content types you specify. Other content types are not blocked. Currently, API Gateway [supports](https://docs.aws.amazon.com/apigateway/latest/developerguide/models-mappings.html) JSON Schema draft-04.
1018
+
936
1019
### Schedule
937
1020
938
1021
The following config will attach a schedule event and causes the stateMachine `crawl` to be called every 2 hours. The configuration allows you to attach multiple schedules to the same stateMachine. You can either use the `rate` or `cron` syntax. Take a look at the [AWS schedule syntax documentation](http://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html) for more details.
0 commit comments