解决了!Google 端点路径模板“路径与任何要求 URI 模板都不匹配。”

Sky*_*awk 2 templates path google-cloud-endpoints openapi google-cloud-endpoints-v2

大家好,我创建并使用了 yaml 的 openAPI,我创建了映射 2 个云函数的端点,这些函数使用路径模板来路由调用,google sdk cli 没有错误。现在我通过 POST 调用,https://myendpointname-3p5hncu3ha-ew.a.run.app/v1/setdndforrefcli/12588/dnd?key=[apikey]因为它是由下面的开放 api 映射的,然后回复我“路径与任何要求 URI 模板都不匹配。”。我不知道为什么端点中的路径模板不起作用我添加了 path_translation: APPEND_PATH_TO_ADDRESS以避免谷歌使用 CONSTANT_ADDRESS 默认值,它在查询字符串中附加 id 与 [云函数名称]?GETid=12588 并覆盖具有相同名称的查询参数。有人可以告诉我如何调试端点或 openAPI 中的错误(端点中有绿色的检查确定图标)?

# [START swagger]
swagger: '2.0'
info:
  description: "Get data "
  title: "Cloud Endpoint + GCF"
  version: "1.0.0"
host: myendpointname-3p5hncu3ha-ew.a.run.app
# [END swagger]
basePath: "/v1"
#consumes:
#  - application/json
#produces:
#  - application/json
schemes:
  - https
paths:
  /setdndforrefcli/{id}/dnd:
    post:
      summary: 
      operationId: setdndforrefcli
      parameters:
       - name: id         # is the id parameter in the path
         in: path         # is the parameter where is in query for rest or path for restful
         required: true
         type: integer
         format: int64
         minimum: 1
      security:
        - api_key: []
      x-google-backend:
        address: https://REGION-PROJECT-ID.cloudfunctions.net/mycloudfunction
        path_translation: APPEND_PATH_TO_ADDRESS
        protocol: h2
      responses:
        '200':
          description: A successful response
          schema:
            type: string
# [START securityDef]
securityDefinitions:
  # This section configures basic authentication with an API key.
  api_key:
    type: "apiKey"
    name: "key"
    in: "query"
# [END securityDef]
Run Code Online (Sandbox Code Playgroud)

And*_*lle 7

我有同样的错误,但在做了一些测试之后,我能够成功使用路径模板 (/endpoint/{id})。我解决了这个问题如下:

1 .- gcloud 端点服务部署openapi-functions.yaml \ --project 项目

在这里,您将获得一个新的服务配置,您将在接下来的步骤中使用该配置。

2.-
chmod +x gcloud_build_image ./gcloud_build_image -s SERVICE \ -c NEWSERVICECONFIGURATION -p project

Its very important change the service configuration with every new deployment of the managed service.

3.- gcloud run deploy SERVICE \ --image="gcr.io/PROJECT/endpoints-runtime-serverless:SERVICE-NEW_SERVICE_CONFIGURATION" \ --allow-unauthenticated \ --platform managed \ --project=PROJECT