Gateway API对接Cloud Function的YAML配置错误排查及传参设置咨询
YAML配置错误修复
你当前的配置存在两处不符合Swagger 2.0规范的语法问题,是触发报错的核心原因:
parameters字段格式错误:Swagger 2.0 中请求体参数需要先声明参数位置、名称、必填属性,再通过schema字段定义结构体,不能直接在parameters下写属性定义deal字段缺少类型声明:嵌套对象必须显式声明type: object,不能直接写子属性
修复后的完整配置如下:
swagger: '2.0' info: title: gateway-homologation gateway for homologation of the project cycle description: "Send a deal object for the data to be treated" version: "1.0.0" schemes: - https produces: - application/json paths: /dispatcher: post: x-google-backend: address: https://<替换为你的Cloud Function实际触发URL> description: "Jailson esteve aqui =)" operationId: "dispatcher" parameters: - in: body name: dealRequest required: true schema: type: object properties: request_type: type: string deal: type: object properties: name: type: string responses: 200: description: "#OK" schema: type: string 400: description: "#OPS"
网关向Cloud Function发送请求的配置方法
- 基础透传配置:只需把上述配置中
x-google-backend.address替换为你的Cloud Function触发URL(可在Cloud Function控制台的触发器页面获取),网关默认会把客户端发送的请求头、请求体完整透传给Cloud Function - 路径透传配置:如果需要把网关请求的路径拼接到Cloud Function地址后,可在
x-google-backend下添加path_translation: APPEND_PATH_TO_ADDRESS配置 - 身份认证配置:如果你的Cloud Function开启了身份校验,需要先给网关的服务账号授予
Cloud Functions Invoker权限,再在x-google-backend下添加jwt_audience: "<你的Cloud Function触发URL>"配置,网关会自动附带合法的身份凭证调用函数 - 自定义请求转换:如果需要修改请求头、请求体内容,可在
x-google-backend同级添加x-google-api-management规则,配置自定义的请求转换逻辑
内容的提问来源于stack exchange,提问作者Lucas de Lagos Pandolfi
相关产品推荐
相关产品推荐

