2017-12-16 9 views
0

私はx-amazon-apigateway-request-validatorを使用してリクエストパラメータを検証しようとしていますが、残念ながら動作しません。以下はスワッガーファイルですAWS APIゲートウェイクエリパラメータの検証

{ 
    "swagger": "2.0", 
    "info": { 
    "title": "API Gateway - Request Validation Demo" 
    }, 
    "schemes": [ 
    "https" 
    ], 
    "produces": [ 
    "application/json" 
    ], 
    "x-amazon-apigateway-request-validators" : { 
    "full" : { 
     "validateRequestBody" : true, 
     "validateRequestParameters" : true 
    }, 
    "body-only" : { 
     "validateRequestBody" : true, 
     "validateRequestParameters" : false 
    } 
    }, 
    "x-amazon-apigateway-request-validator" : "full", 
    "paths": { 
    "/orders": { 
     "post": { 
     "x-amazon-apigateway-request-validator": "body-only", 
     "parameters": [ 
      { 
      "in": "body", 
      "name": "CreateOrders", 
      "required": true, 
      "schema": { 
       "$ref": "#/definitions/CreateOrders" 
      } 
      } 
     ], 
     "responses": { 
      "200": { 
      "schema": { 
       "$ref": "#/definitions/Message" 
      } 
      }, 
      "400" : { 
      "schema": { 
       "$ref": "#/definitions/Message" 
      } 
      } 
     }, 
     "x-amazon-apigateway-integration": { 
      "responses": { 
      "default": { 
       "statusCode": "200", 
       "responseTemplates": { 
       "application/json": "{\"message\" : \"Orders successfully created\"}" 
       } 
      } 
      }, 
      "requestTemplates": { 
      "application/json": "{\"statusCode\": 200}" 
      }, 
      "passthroughBehavior": "never", 
      "type": "mock" 
     } 
     }, 
     "get": { 
     "x-amazon-apigateway-request-validator": "full", 
     "parameters": [ 
      { 
      "in": "header", 
      "name": "Account-Id", 
      "required": true 
      }, 
      { 
      "in": "query", 
      "name": "type", 
      "required": false, 
      "schema": { 
       "$ref": "#/definitions/InputOrders" 
      } 
      } 
     ], 
     "responses": { 
      "200" : { 
      "schema": { 
       "$ref": "#/definitions/Orders" 
      } 
      }, 
      "400" : { 
      "schema": { 
       "$ref": "#/definitions/Message" 
      } 
      } 
     }, 
     "x-amazon-apigateway-integration": { 
      "responses": { 
      "default": { 
       "statusCode": "200", 
       "responseTemplates": { 
       "application/json": "[{\"order-id\" : \"qrx987\",\n \"type\" : \"STOCK\",\n \"symbol\" : \"AMZN\",\n \"shares\" : 100,\n \"time\" : \"1488217405\",\n \"state\" : \"COMPLETED\"\n},\n{\n \"order-id\" : \"foo123\",\n \"type\" : \"STOCK\",\n \"symbol\" : \"BA\",\n \"shares\" : 100,\n \"time\" : \"1488213043\",\n \"state\" : \"COMPLETED\"\n}\n]" 
       } 
      } 
      }, 
      "requestTemplates": { 
      "application/json": "{\"statusCode\": 200}" 
      }, 
      "passthroughBehavior": "never", 
      "type": "mock" 
     } 
     } 
    } 
    }, 
    "definitions": { 
    "CreateOrders": { 
     "$schema": "http://json-schema.org/draft-04/schema#", 
     "title": "Create Orders Schema", 
     "type": "array", 
     "minItems" : 1, 
     "items": { 
     "type": "object", 
     "$ref" : "#/definitions/Order" 
     } 
    }, 
    "Orders" : { 
     "type": "array", 
     "$schema": "http://json-schema.org/draft-04/schema#", 
     "title": "Get Orders Schema", 
     "items": { 
     "type": "object", 
     "properties": { 
      "order_id": { "type": "string" }, 
      "time" : { "type": "string" }, 
      "state" : { 
      "type": "string", 
      "enum": [ 
       "PENDING", 
       "COMPLETED" 
      ] 
      }, 
      "order" : { 
      "$ref" : "#/definitions/Order" 
      } 
     } 
     } 
    }, 
    "Order" : { 
     "type": "object", 
     "$schema": "http://json-schema.org/draft-04/schema#", 
     "title": "Schema for a single Order", 
     "required": [ 
     "account-id", 
     "type", 
     "symbol", 
     "shares", 
     "details" 
     ], 
     "properties" : { 
     "account-id": { 
      "type": "string", 
      "pattern": "[A-Za-z]{6}[0-9]{6}" 
     }, 
     "type": { 
      "type" : "string", 
      "enum" : [ 
      "STOCK", 
      "BOND", 
      "CASH"] 
     }, 
     "symbol" : { 
      "type": "string", 
      "minLength": 1, 
      "maxLength": 4 
     }, 
     "shares": { 
      "type": "number", 
      "minimum": 1, 
      "maximum": 1000 
     }, 
     "details": { 
      "type": "object", 
      "required": [ 
      "limit" 
      ], 
      "properties": { 
      "limit": { 
       "type": "number" 
      } 
      } 
     } 
     } 
    }, 
    "InputOrder" : { 
     "type": "object", 
     "$schema": "http://json-schema.org/draft-04/schema#", 
     "title": "Schema for a Input Order", 
     "required": [ 
     "type" 
     ], 
     "properties" : { 
     "type": { 
      "type" : "string", 
      "enum" : [ 
      "STOCK", 
      "BOND", 
      "CASH"] 
     } 
     } 
    }, 
    "Message": { 
     "type": "object", 
     "properties": { 
     "message" : { 
      "type" : "string" 
     } 
     } 
    } 
    } 
} 

私はいくつかの正規表現とenum値に対してリクエストパラメータを検証しようとしています。

これが可能かどうかはわかりません。誰も私にこれを手伝ってもらえますか?

答えて

0

HTTPパラメータの検証では、API Gatewayは「required」とマークするだけです。パラメータのregex/enum値はサポートしていません。

+0

はい、私はたくさんのものを読んだ後に知りました。要約するとありがとうございます。 – Abie

関連する問題