由于Body Mapping模板-代理更好。
我不喜欢使用Body Mapping模板,因为在导出的Swagger中它被转义了,例如:
uri: "arn:aws:apigateway:us-east-1:dynamodb:action/UpdateItem"
responses:
default:
statusCode: "200"
requestTemplates:
application/json: "{\n \"TableName\": \"happy-marketer\",\n \"Key\"\
: {\n \"pk\": {\n \"S\": \"project\"\n },\n \
\ \"sk\": {\n \"S\": \"$context.authorizer.claims.email\
\ $util.urlDecode($input.params('name'))\"\n }\n },\n \"\
UpdateExpression\": \"SET projectStatus = :c\",\n \"ExpressionAttributeValues\"\
: {\n \":c\": {\n \"S\": \"Completed\"\n\n }\n\
\ }\n}"
passthroughBehavior: "never"
httpMethod: "POST"
type: "aws"
/projects/{name}/status/restore:
options:
consumes:
- "application/json"
produces:
- "application/json"
parameters:
- name: "name"
in: "path"
正如您所理解的那样-在本地编辑并部署此Swagger文件是不好的。而且,当您在浏览器中编辑请求体映射模板时,您将无法收到有关错误的JSON / Apache Velocity的信息。例如,在这里我们犯了一个错误:
{
"email": "$context.authorizer.claims.email",
"nameOld": "$util.urlDecode($input.params('name'))",
#if ($input.path('$.nameNew') != "")
"nameNew": "$util.urlDecode($input.path('$.nameNew'))",
#end
#if ($input.path('$.ownerNew') != "")
"ownerNew": "$input.path('$.ownerNew')",
#end
#if ($input.path('$.shared') != "")
"shared": $input.json('$.shared')
#end
#if ($input.path('$.StartDate') != "")
, "startDate": "$input.path('$.StartDate')"
#end
#if ($input.path('$.DueDate') != "")
, "dueDate": "$input.path('$.DueDate')"
#end
}
错误在于 - 在
startDate
之前有一个错误的
,
。我的Go后端代码没有这样的错误。我不想为Apache Velocity编写测试。
另外,也许代理集成更快 - 因为缺少“中间服务”。