red*_*888 8 amazon-web-services aws-lambda aws-api-gateway
如果内容类型不是 json api 网关不进行验证而只是通过。我使用代理集成,所以没有映射模板,只能使用“when_no_match”。我使用内联招摇。
我可以检查标题是否存在但不能检查值 - 我该怎么做?
/myMethod:
post:
x-amazon-apigateway-request-validator : "myvalidator"
parameters:
# How do I also validate Content-Type value is "application/json"
- name: Content-Type
in: header
required: true
Run Code Online (Sandbox Code Playgroud)
我想要 API 网关来验证这一点,所以我不必在代码中检查它
在Integration Request
您的终端选项卡中,单击Mapping Templates
,设置Request body passthrough
为never
,添加映射模板application/javascript
,然后单击Method Request Passthrough
旁边的下拉菜单Generate template
。
这是招摇的片段:
requestTemplates:
application/json: |
## See http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html
## This template will pass through all parameters including path, querystring, header, stage variables, and context through to the integration endpoint via the body/payload
#set($allParams = $input.params())
{
"body-json" : $input.json('$'),
"params" : {
#foreach($type in $allParams.keySet())
#set($params = $allParams.get($type))
"$type" : {
#foreach($paramName in $params.keySet())
"$paramName" : "$util.escapeJavaScript($params.get($paramName))"
#if($foreach.hasNext),#end
#end
}
#if($foreach.hasNext),#end
#end
},
"stage-variables" : {
#foreach($key in $stageVariables.keySet())
"$key" : "$util.escapeJavaScript($stageVariables.get($key))"
#if($foreach.hasNext),#end
#end
},
"context" : {
"account-id" : "$context.identity.accountId",
"api-id" : "$context.apiId",
"api-key" : "$context.identity.apiKey",
"authorizer-principal-id" : "$context.authorizer.principalId",
"caller" : "$context.identity.caller",
"cognito-authentication-provider" : "$context.identity.cognitoAuthenticationProvider",
"cognito-authentication-type" : "$context.identity.cognitoAuthenticationType",
"cognito-identity-id" : "$context.identity.cognitoIdentityId",
"cognito-identity-pool-id" : "$context.identity.cognitoIdentityPoolId",
"http-method" : "$context.httpMethod",
"stage" : "$context.stage",
"source-ip" : "$context.identity.sourceIp",
"user" : "$context.identity.user",
"user-agent" : "$context.identity.userAgent",
"user-arn" : "$context.identity.userArn",
"request-id" : "$context.requestId",
"resource-id" : "$context.resourceId",
"resource-path" : "$context.resourcePath"
}
}
passthroughBehavior: "never"
httpMethod: "POST"
type: "aws"
归档时间: |
|
查看次数: |
2240 次 |
最近记录: |