将google端点中的路径参数传递到后端不起作用



我的设置包含以谷歌云功能为后台的谷歌端点。

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我试着在上面的swaggerapi中添加x-google-backend参数。(path_translation: APPEND_PATH_TO_ADDRESS(。

然而,这并不奏效。我收到一个未经授权的错误(403(,因为端点前端没有命中云功能。

目前,我使用了一个丑陋的解决方案,没有path_translation参数,该参数将谷歌端点路径变量转换为云函数后端中同名的查询参数。即在后端调用url/documents?document_id=xyz

(我试图实现的是通过后端url/documents/{document_id}的调用(

有人知道如何正确配置基于路径的参数,以便将其正确传递到云功能后端吗?

提前谢谢。

谨致问候,Sebastian

TL;博士:我认为你的403错误不是正确的错误。它应该是一个404,但由于端点是未知的,我想403是有答案的。

Cloud Endpoint对此行为感到沮丧。对于path_translation: APPEND_PATH_TO_ADDRESS,您认为您的最终被叫地址将是/documents/{document_id},但。完整的openAPI路径附加到您的后端地址,在您的情况下为:/documents/api/documents/{document_id}

这就是端点不存在的原因,您应该有一个404(而不是403(。

有关更多详细信息,您可以查看此页面。

注意:我在这个话题上与谷歌团队有联系,在更新这个行为之前需要一段时间

相关内容

  • 没有找到相关文章

最新更新