google-cloud-platform - GCP API 网关 : Cannot use path params

标签 google-cloud-platform yaml openapi google-cloud-api-gateway

我正在努力将路径参数从我的网关传递到实际端点。

这是我的 Open API yaml:

swagger: '2.0'
info:
  description: |
    Blah blah
  version: 0.0.1
  title: SSAuth
  contact:
    email: blah@gmail.com
schemes:
  - https
produces:
  - application/json
paths:
  /v0/auth/users/echo:
    get:
      summary: check the health of api
      operationId: healthCheck
      consumes:
        - application/json
      produces:
        - application/json
      responses:
        200:
          description: OK
      x-google-backend:
        address: https://path-to-my-cloud-run-service/v0/auth/users/echo
      security:
        - api_key: []

  /v0/auth/users/type/{type}:
    post:
      summary: Add a new user to the user
      operationId: addUser
      consumes:
        - application/json
      produces:
        - application/json
      parameters:
        - name: type
          in: path
          description: provider type of the user
          required: true
          type: string
      responses:
        400:
          description: Invalid input
        200:
          description: OK
      x-google-backend:
        address: https://path-to-my-cloud-run-service/v0/auth/users/type/`type`
      security:
        - api_key: []

securityDefinitions:
  api_key:
    type: apiKey
    name: X-API-Key
    in: header

当我获取第一条路径时,它起作用了。但是在第二条路径中,有一个路径参数,我找不到将参数传递给我的 Cloud Run URL 的方法。在日志中,我看到这个 https://path-to-my-cloud-run-service/v0/auth/users/type/%60type%60?type=email 而不是 https://path-to-my-cloud-run-service/v0/auth/users/type/email,这导致我的服务因类型无效而被拒绝。

我需要在我的 yaml 中更改什么才能使其正常工作?

我遇到的另一个问题是,如果我将 json 放入正文,即使我指定它使用 application/json,GET 请求也会收到 400 个错误请求。

最佳答案

挖掘后找到解决方案here .

这是 path_transaltion,这是工作 yaml:

swagger: '2.0'
info:
  description: |
    Blahblah
  version: 0.0.1
  title: Title
  contact:
    email: blah@gmail.com
schemes:
  - https
produces:
  - application/json
paths:
  /v0/auth/users/echo:
    get:
      summary: check the health of api
      operationId: healthCheck
      consumes:
        - application/json
      produces:
        - application/json
      responses:
        200:
          description: OK
      x-google-backend:
        address: https://path-to-my-service
        path_translation: APPEND_PATH_TO_ADDRESS
      security:
        - api_key: []

  /v0/auth/users/type/{type}:
    post:
      summary: Add a new user to the user
      operationId: addUser
      consumes:
        - application/json
      produces:
        - application/json
      parameters:
        - name: type
          in: path
          description: provider type of the user
          required: true
          type: string
      responses:
        400:
          description: Invalid input
        200:
          description: OK
      x-google-backend:
        address: https://path-to-my-service
        path_translation: APPEND_PATH_TO_ADDRESS
      security:
        - api_key: []

securityDefinitions:
  api_key:
    type: apiKey
    name: X-API-Key
    in: header

关于google-cloud-platform - GCP API 网关 : Cannot use path params,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64804727/

相关文章:

google-cloud-platform - 使用服务帐户的 Google Group 访问 BigQuery 数据集

java - Spring Boot 将 yaml 列表加载为 map

elasticsearch - 选择配置文件启动弹性集群

json - OpenAPI 路径/查询参数嵌套结构序列化

multithreading - Google Compute Engine 上的 1 个 vCPU 基本上是 1 个物理 CPU 核心的一半吗?

node.js - 您可以通过 Cloud Spanner API 检查表是否存在吗? (在 Node.js 中)

kubernetes - "permanent"GKE kubectl 服务帐号认证

java - 用于运行 JUnit 测试的 YML 文件

c# - 在我的电脑上哪里可以找到 swagger.json 文件(称为 "localhost")?

go - 如何解决从openapi go代码生成器获取使用应用程序/x-www-form-urlencoded内容类型的API的验证错误?