Skip to content

Commit

Permalink
feat: Adds validation to POST & PUT methods
Browse files Browse the repository at this point in the history
NOTE: The requestValidatorOptions had to be broken out into individual
objects. Refer to: aws/aws-cdk#7613
  • Loading branch information
therealvio committed Nov 19, 2022
1 parent a90182d commit c81e80c
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions backend/ops/src/stacks/backend-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class BackendStack extends cdk.Stack {
modelName: "playerHandv1",
schema: {
schema: apigateway.JsonSchemaVersion.DRAFT4,
title: "PlayerHandPost",
title: "PlayerHand",
type: apigateway.JsonSchemaType.OBJECT,
required: ["handInfo"],
properties: {
Expand Down Expand Up @@ -112,22 +112,45 @@ export class BackendStack extends cdk.Stack {
const formationPostMethod = formation.addMethod("POST", apiIntegration, {
apiKeyRequired: false,
}) //Set apiKeyRequired to `true` when ready to start locking down the API

//Need to create individual validator objects, refer to: https://github.com/aws/aws-cdk/issues/7613
const playerHandPostValidator = new apigateway.RequestValidator(
this,
"playerHandPostValidator",
{
restApi: api,
requestValidatorName: "playerHandPostValidator",
validateRequestBody: true,
validateRequestParameters: false,
}
)
const playerHandPutValidator = new apigateway.RequestValidator(
this,
"playerHandPutValidator",
{
restApi: api,
requestValidatorName: "playerHandPutValidator",
validateRequestBody: true,
validateRequestParameters: false,
}
)

const playerHandPost = playerHand.addMethod("POST", apiIntegration, {
apiKeyRequired: true,
requestModels: {
"application/json": playerHandModel,
},
requestValidatorOptions: {
requestValidatorName: "playerHandValidator",
validateRequestBody: true,
validateRequestParameters: false,
},
requestValidator: playerHandPostValidator,
})
const playerHandGet = playerHand.addMethod("GET", apiIntegration, {
apiKeyRequired: true,
})
const playerHandPut = playerHand.addMethod("PUT", apiIntegration, {
apiKeyRequired: true,
requestModels: {
"application/json": playerHandModel,
},
requestValidator: playerHandPutValidator,
})

const plan = api.addUsagePlan("legalBrawlUsagePlan", {
Expand Down

0 comments on commit c81e80c

Please sign in to comment.