假设我有一个带有路径的 api/
and /{pets}
and /{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,我想知道是否有解决方案可用。