Cupid Chan
Cupid Chan

Reputation: 865

"Unable to load RELATIVE ref" for openapi-run.yaml in GCP Endpoints

I use Google Cloud Build to build GCP Endpoints which relies on openapi-run.yaml to define the API. I have a large JSON schema file of which I want to refer to in the 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"  

But when I run gcloud endpoints services deploy openapi-run.yaml --project myProject, it gives me an error saying "OpenAPI spec in file {openapi-run.yaml} is ill formed and cannot be parsed: Unable to load RELATIVE ref: /workspace/src/models/myLargeSchema.json"

I double-checked using ls command and confirm that the schema file is retrievable:

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

Output

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

Question How can I write my openapi-run.yaml so that it can refers to my JSON schema in another file?

Upvotes: 0

Views: 5540

Answers (2)

Cupid Chan
Cupid Chan

Reputation: 865

I have found out that calling for external references in NOT supporting in GCP Endpoints: https://cloud.google.com/endpoints/docs/openapi/openapi-limitations#external_type_references

Upvotes: 1

Ether
Ether

Reputation: 53966

You are using an absolute filename, not a relative one. Try dropping the leading /workspace/ from the path in $ref.

Upvotes: 0

Related Questions