验证AWS API网关的请求路径参数?

时间:2017-11-09 06:01:14

标签: amazon-web-services aws-api-gateway swagger-2.0

我们说我的路径为//{pets}/{pets}/pet。现在我尝试验证路径{pets}参数,以便只有具有长度为6的字母数字字符的路径才会被验证并处理到后端lambda,所有其他路径将被拒绝。我尝试了以下swagger模式,指定参数的格式和类型。我甚至尝试在架构中使用模式,但它似乎无法正常工作。我是否知道如何仅限制某些ID的路径参数。

{
  ......
  "/{pets}/pet": {
      "get": {
          "consumes": [
              "application/json"
          ],
          "produces": [
              "application/json"
          ],
          "parameters": [{
              "name": "pets",
              "in": "path",
              "required": true,
              "schema": {
                  "type": "string",
                  "pattern": "[A-Za-z0-9]{6}"
              }
          }],
          "responses": {
              "200": {
                  "description": "200 response",
                  "schema": {
                      "$ref": "#/definitions/Empty"
                  }
              }
          },
          "x-amazon-apigateway-request-validator": "Validate query string parameters and headers",
          "x-amazon-apigateway-integration": {
              "responses": {
                  "default": {
                      "statusCode": "200"
                  }
              },
              "requestTemplates": {
                  "application/json": "##  See ...."
              },
              "uri": "........",
              "passthroughBehavior": "when_no_templates",
              "httpMethod": "POST",
              "contentHandling": "CONVERT_TO_TEXT",
              "type": "aws"
          }
      }
  }
  .....
}

我想要实现的目标:

https://api.example.com/aacc77/pet -- Accept
https://api.example.com/aacc77s/pet -- Reject
https://api.example.com/aacc7/pet -- Reject
https://api.example.com/aacc_7/pet -- Reject

基本上,我想将此正则表达式模式用于路径 [A-Za-z0-9] {6}

"pets": {
  "$schema": "http://json-schema.org/draft-04/schema#",
  "title": "Pets Schema",
  "type": "string",
  "pattern": "[A-Za-z0-9]{6}"
}

我看到有一个相关的问题here,我想知道是否有可用的解决方案。

0 个答案:

没有答案