0

I want to do (http) request parameters validation for lambda functions using serverless framework.

This answer explains how to do it, using API Gateway request validation using JSON Schema draft.

It allows one to validate a given endpoint, using a JSON like this:

{
  "definitions": {},
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "title": "user Schema",
  "required": ["name", "age"],
  "properties": {
    "name": {
      "type": "string",
      "title": "Name",
      "pattern": "(?=^.{6,23}$)(^(\\p{L}\\p{M}*)+$)"
    }
  }
}

where a property name inside body is expected to have between 6 and 23 characters, through a Regex validator.

However, I'd like to have these values be exported from a file, to be more organized, such as a yml file:

# validator-config.yml
VALIDATOR_USERNAME_MIN_LENGTH: 6
VALIDATOR_USERNAME_MAX_LENGTH: 23
VALIDATOR_REGEX_CHARACTER: "(\\p{L}\\p{M}*)"

and use it as:

{
  "definitions": {},
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "title": "user Schema",
  "required": ["name", "age"],
  "properties": {
    "name": {
      "type": "string",
      "title": "Name",
      "pattern": "(?=^.{VALIDATOR_USERNAME_MIN_LENGTH,VALIDATOR_USERNAME_MAX_LENGTH}$)(^VALIDATOR_REGEX_CHARACTER+$)"
    }
  }
}

Is there an easy way to accomplish this?

Bersan
  • 1,032
  • 1
  • 17
  • 28

0 Answers0