gpt4 book ai didi

google-cloud-platform - 将谷歌端点中的路径参数传递给后端不起作用

转载 作者:行者123 更新时间:2023-12-03 21:15:56 24 4
gpt4 key购买 nike

我的设置包含以 google-cloud-functions 作为后端的 google-endpoints。

Google 端点使用以下 swagger v2 yaml 定义:

swagger: "2.0"
info:
description: "yada..."
version: "0.0.1"
title: "yadada.."
termsOfService: "http://swagger.io/terms/"
contact:
name: "blah"
email: "email@mail.com"
url: "https://example.com"
host: "(generated service url by google when endpoints is deployed, i.e. 'api-gateway-xyz123123-ew.a.run.app')"
tags:
- name: "Documents"
description: "blah"
schemes:
- "https"
paths:
/api/documents:
post:
tags:
- "Documents"
summary: "Add a new document"
description: ""
security:
- firebase: []
operationId: "addDocument"
x-google-backend:
address: "(cloud functions http url)/documents"
consumes:
- "application/json"
produces:
- "application/json"
parameters:
- in: "body"
name: "body"
description: "Document supplied"
required: true
schema:
$ref: "#/definitions/Document"
responses:
201:
description: "The document was successfully created."
schema:
$ref: "#/definitions/Document"
400:
description: "Invalid input. See response for details"
schema:
items:
$ref: "#/definitions/Error"
/api/documents/{document_id}:
get:
tags:
- "Documents"
summary: "Get a document with the given ID"
description: ""
security:
- firebase: []
operationId: "getDocument"
x-google-backend:
address: "(cloud function http url)/documents/"
path_translation: APPEND_PATH_TO_ADDRESS
produces:
- "application/json"
parameters:
- in: "path"
name: "document_id"
description: "ID of the document to modify"
required: true
type: "string"
responses:
200:
description: "success."
schema:
type: "array"
items:
$ref: "#/definitions/Document"
404:
description: "Document not found"
schema:
items:
$ref: "#/definitions/Error"
securityDefinitions:
firebase:
authorizationUrl: ""
flow: "implicit"
type: "oauth2"
x-google-issuer: "https://securetoken.google.com/%%GOOGLE_PROJECT_ID%%"
x-google-jwks_uri: "https://www.googleapis.com/service_accounts/v1/metadata/x509/securetoken@system.gserviceaccount.com"
x-google-audiences: "%%GOOGLE_PROJECT_ID%%"
definitions:
(a lot of type definitions)

这适用于 POST 端点,没有任何问题。

问题在于 GET REST 端点,其中路径变量未正确传递到后端。

https://cloud.google.com/endpoints/docs/openapi/openapi-extensions我尝试像上面的 swagger api 一样添加 x-google-backend 参数。 ( path_translation: APPEND_PATH_TO_ADDRESS )。

但是,这不起作用。
我收到未经授权的错误 (403),因为端点前端未命中云功能。

目前,我使用了一种不带 path_translation 参数的丑陋解决方法,该参数将 google 端点路径变量转换为云函数后端中具有相同名称的查询参数。 IE。在后端网址 /documents?document_id=xyz叫做。

(我试图实现的是使用后端 url /documents/{document_id} 传递调用)

有谁知道如何正确配置基于路径的参数,以便将它们正确传递到云函数后端?

先感谢您。

问候,
塞巴斯蒂安

最佳答案

特尔;博士:
我假设您的 403 错误不是正确的错误。它应该是 404,但因为端点未知,我猜 403 得到了回答。

Cloud Endpoint 对这种行为感到沮丧。与 path_translation: APPEND_PATH_TO_ADDRESS ,你认为你最终被调用的地址是 /documents/{document_id} ,但是 .完整的 openAPI 路径附加到您的后端地址,在您的情况下:/documents/api/documents/{document_id}
这就是端点不存在的原因,您应该有一个 404(而不是 403)。

更多详情,您可以查看this page .

注意:我与 Google 团队就此主题保持联系,并且需要时间才能对此行为进行更新。

关于google-cloud-platform - 将谷歌端点中的路径参数传递给后端不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60711968/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com