GCP 端点中 openapi-run.yaml 的“无法加载 RELATIVE ref”

问题描述

我使用 Google Cloud Build 构建 GCP Endpoints,它依赖于 openapi-run.yaml 来定义 API。我有一个很大的 JSON 模式文件,我想在 openapi-run.yaml 中引用它:

  /testRef:
    get:
      summary: test for Reference
      operationId: testRef
      responses:
        '200':
          description: A successful response
          schema: 
            $ref: "/workspace/src/models/myLargeSchema.json#/Account"  

但是当我运行 gcloud endpoints services deploy openapi-run.yaml --project myProject 时,它给了我一个错误提示 "OpenAPI spec in file {openapi-run.yaml} is ill formed and cannot be parsed: Unable to load RELATIVE ref: /workspace/src/models/myLargeSchema.json"

我使用 ls 命令再次检查并确认架构文件可检索:

- name: 'gcr.io/cloud-builders/gcloud'
  entrypoint: 'bash'
  args: [ '-c','ls ./src/models -la']

输出

Step #0: drwxr-xr-x  2 501 dialout    4096 Jan 27 13:12 .
Step #0: drwxr-xr-x 15 501 dialout    4096 Dec  6 22:53 ..
Step #0: -rw-r--r--  1 501 dialout    2912 Dec 31 11:30 JSONSchemaValidator.ts
Step #0: -rw-r--r--  1 501 dialout 3370813 Jan 27 13:12 myLargeSchema.json
Step #0: -rw-r--r--  1 501 dialout     539 Dec 19 19:58 user.ts

问题 如何编写我的 openapi-run.yaml 以便它可以在另一个文件中引用我的 JSON 架构?

解决方法

我发现在 GCP Endpoints 中 NOT 支持中调用外部引用:https://cloud.google.com/endpoints/docs/openapi/openapi-limitations#external_type_references

,

您使用的是绝对文件名,而不是相对文件名。尝试从 /workspace/ 中的路径中删除前导 $ref