【问题标题】:GCP API Gateway: Path parameters are being passed as query paramsGCP API Gateway:路径参数作为查询参数传递
【发布时间】:2021-11-15 13:29:07
【问题描述】:

我正在尝试使用 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。

我该如何解决这个问题?

【问题讨论】:

    标签: api google-cloud-platform api-gateway google-cloud-api-gateway google-api-gateway


    【解决方案1】:

    由于我误解了问题而编辑我的答案。

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

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

    它没有显示正确的 ID。

    所以这应该是来自您的 yaml 文件的泄漏问题,您可以按照与此线程中有关 using path params 的相同方式处理此问题

    【讨论】:

    • 这不能回答我的问题。答案完全跑题了。
    • @Nissan 对我的误解深表歉意。请查看编辑后的答案,如果对您有帮助,请告诉我。
    猜你喜欢
    • 1970-01-01
    • 2013-01-25
    • 2016-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-25
    • 1970-01-01
    • 2021-12-02
    相关资源
    最近更新 更多