GCP API网关:无法使用路径参数

2023-11-24

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

这是我的 Open API yaml:

swagger: '2.0'
info:
  description: |
    Blah blah
  version: 0.0.1
  title: SSAuth
  contact:
    email: [email protected]
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: [email protected]
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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

GCP API网关:无法使用路径参数 的相关文章

随机推荐

  • Laravel redirect::route 在页面加载之间显示一条消息

    我目前正在使用 Laravel 开发一个网络应用程序 直到最近该应用程序都运行得很好 我不知道是什么触发了它 但这是我遇到的问题的摘要 登录过去可以正常工作 因为我有一个 AccountController 可以执行以下操作 auth Au
  • 实现安全 nullptr

    我想让我的代码在旧版 C 使用 NULL 的 C 代码 和新的 C 11 标准 使用 nullptr 的 C 代码 上都可编译 我正在使用 GCC 但计划在完成最重要的事情时也为 VS 重新编译整个代码库 我是否应该期望 GCC 和 VS
  • 为什么 Files.lines (和类似的 Streams)不会自动关闭?

    Stream 的 javadoc 指出 流有一个 BaseStream close 方法并实现 AutoCloseable 但几乎所有流实例在使用后实际上并不需要关闭 通常 只有源是 IO 通道的流 例如由 Files lines Path
  • 通过多个索引引用 PHP 数组

    这可能是某种奇怪的较长捷径 如果我的思路有误 请纠正我 我有一个数据矩阵 如下所示 unique id url other random data unique id url other random data unique id url
  • 查找数据框中每行的前 N ​​列

    给定一个包含一个描述性列和 X 个数字列的数据框 对于每一行 我想识别具有较高值的 前 N 列 并将其保存为新数据框上的行 例如 考虑以下数据框 df pd DataFrame df index A B C D E F df option1
  • vb.net 应用程序出现 OutOfMemoryException

    在我的 VB Net 应用程序之一中 我在运行该应用程序时遇到错误 这个错误并不总是出现 所以我也无法重现该错误 也没有重现错误的确切顺序 堆栈 System OutOfMemoryException 内存不足 在 System Drawi
  • 在 Visual Studio 2012 中,Librarian 和 Linker 之间有什么区别?

    我正在将我的项目配置为使用 x86 和 x64 位进行构建 为此 我必须更改不同配置的目标计算机 我试图找到为我的本机 C 库设置目标机器的位置 我发现这个帖子 然而我没有Linker在本机 C 库项目中 我有 配置属性 gt Linker
  • 如何在VS 2010中指定单元测试结果的位置?

    我使用VS2010进行单元测试 有谁知道如何指定 VS 2010 放置 TestResults 的位置 默认情况下 它将 TestResults 文件夹放在解决方案文件夹中 我想将其移到其他地方 谢谢 射线 目前 无法从 IDE 内进行控制
  • PyQt4 到 PyQt5 怎么样?

    我的代码是用 PyQt4 创建的 我想将其转换为 PyQt5 我尝试过一些脚本来转换代码 但是 除了名字之外 什么都没有改变 为了使代码与 PyQt5 一起工作 我需要手动更改什么 这是我的代码的第一部分 import sys from p
  • 交叉引用和垃圾收集

    有一个具有广泛对象图的应用程序 该图主要由一组子图组成 这些子图通过唯一引用连接到图的其余部分 但在内部 每个这样的子图在对象之间都有一定数量的交叉引用 有时这样的子图需要被丢弃 只需将指向该子图的唯一引用设置为 null 就足够了吗 我担
  • QuerySet 对象在 Django Rest Framework 上没有属性“user”

    在 Django Rest Framework 上执行请求时 我无法序列化模型来获取结果 模型 py class Karfarma models Model user models OneToOneField User related na
  • C++:对 Singleton 类中的实例的未定义​​引用

    我目前正在尝试将工厂实现为单例 我实际上使用了单例模式的教科书示例 这是 h 文件 namespace oxygen class ImpFactory public static boost shared ptr
  • 如何保护 Android 应用程序中的秘密字符串?

    在我的 Android 应用程序中 我使用 Microsoft 翻译器 它需要两个字符串 clientId 和 clientSecret 目前 我对这两个字符串进行了硬编码 由于我发现classes dex可以转换为jar 然后 class
  • Python 相当于 Ruby 的each_slice(count)

    python 相当于 Ruby 的什么each slice count 我想为每次迭代从列表中取出 2 个元素 像 1 2 3 4 5 6 我想处理1 2然后在第一次迭代中3 4 then 5 6 当然 还有一种使用索引值的迂回方式 但是有
  • PHPMailer $mail->From 标头不适用于 gmail

    我使用以下代码在使用 PHP 邮件程序类提交表单后发送邮件https github com Synchro PHPMailer 邮件发送并成功接收 唯一不起作用的是以下内容 mail gt From email email是用户将在表单上输
  • 以编程方式将搜索栏快速添加到表格视图中

    我有一个文本字段 它代表一个表视图作为其输入视图 我想在这个表格视图中添加两件事 1 添加搜索栏 2 在表格视图顶部添加取消按钮 class enterYourDealVC UIViewController UITableViewDataS
  • 创建未知数量的循环

    这是我要生成的简单代码 一组的所有可能组合 例子 1 2 3 展示 123 132 213 第231章 第312章 321 我想创建可变数量的 for 循环 让用户确定给定字符串的长度 有谁有想法吗 提前致谢 type TNumber 0
  • Web API 2.1 Windows 身份验证 CORS Firefox

    这是场景 我创建了一个 web api 项目和一个 mvc 项目 如下所示 http www asp net web api overview security enabling cross origin requests in web a
  • LINQWhere() 和 FirstOrDefault() 之间的逻辑差异

    我知道这听起来可能是重复的问题 比如this or this 但我想清楚地了解此查询中将发生的迭代次数 我的假设如下 假设我收藏了 1000 件物品 在Where 查询中 它迭代每个项目并将其添加到IEnumerable 即它总是需要 O
  • GCP API网关:无法使用路径参数

    我正在努力将路径参数从网关传递到实际端点 这是我的 Open API yaml swagger 2 0 info description Blah blah version 0 0 1 title SSAuth contact email