首页 > 解决方案 > GCP API Gateway:路径参数作为查询参数传递

问题描述

我正在尝试使用 GCP API Gateway 为我的几个后端服务(A、B、C、D)创建一个端点,每个端点都有自己的路径结构。我为以下服务之一配置了网关:

swagger: '2.0'
info:
  title: <TITLE>
  description: <DESC>
  version: 1.0.0
schemes:
  - https
produces:
  - application/json
paths:
  /service_a/match/{id_}:
    get:
      summary: <SUMMARY>
      description: <DESC>
      operationId: match_id_
      parameters:
        - required: true
          type: string
          name: id_
          in: path
        - required: true
          type: boolean
          default: false
          name: bool_first
          in: query
        - required: false
          type: boolean
          default: false
          name: bool_Second
          in: query
      x-google-backend:
        address: <cloud_run_url>/match/{id_}
        deadline: 60.0
      responses:
        '200':
          description: Successful Response
        '422':
          description: Validation 

这部署得很好。但是当我到达端点时gateway_url/service_a/match/123,它会被路由到cloud_run_url/match/%7Bid_%7D?id_=123而不是cloud_run_url/match/123.

我怎样才能解决这个问题?

标签: apigoogle-cloud-platformapi-gatewaygoogle-cloud-api-gatewaygoogle-api-gateway

解决方案


编辑我的答案,因为我误解了这个问题。

似乎{从您的配置中泄漏为 ASCII 代码,所以当您调用

x-google-backend:
        address: <cloud_run_url>/match/{id_}
        deadline: 60.0

它没有显示正确的 ID。

因此,这应该是您的文件中的泄漏问题,您可以使用与此线程中有关使用路径参数yaml的相同方式来解决此问题


推荐阅读