Skip to content

Commit

Permalink
Merge pull request #1081 from aqaengineering/intro-doc-fix
Browse files Browse the repository at this point in the history
docs: update `01-intro.md`'s `validator` usage
  • Loading branch information
willfarrell authored Aug 2, 2023
2 parents b9f6bff + f604f4f commit 11f846b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions website/docs/intro/01-intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import middy from '@middy/core' // esm Node v14+
import jsonBodyParser from '@middy/http-json-body-parser'
import httpErrorHandler from '@middy/http-error-handler'
import validator from '@middy/validator'
import { transpileSchema } from '@middy/validator/transpile'

// This is your common handler, in no way different than what you are used to doing every day in AWS Lambda
const lambdaHandler = async (event, context) => {
Expand All @@ -43,7 +44,7 @@ const lambdaHandler = async (event, context) => {
// Notice that in the handler you only added base business logic (no deserialization,
// validation or error handler), we will add the rest with middlewares

const eventSchema = {
const schema = {
type: 'object',
properties: {
body: {
Expand All @@ -64,7 +65,7 @@ const eventSchema = {
// Let's "middyfy" our handler, then we will be able to attach middlewares to it
const handler = middy()
.use(jsonBodyParser()) // parses the request body when it's a JSON and converts it to an object
.use(validator({eventSchema})) // validates the input
.use(validator({eventSchema: transpile(schema)})) // validates the input
.use(httpErrorHandler()) // handles common http errors and returns proper responses
.handler(lambdaHandler)

Expand Down

0 comments on commit 11f846b

Please sign in to comment.