-
Notifications
You must be signed in to change notification settings - Fork 51
Description
Issue
References to ($refs with a relative path) in the first file loaded by rdme are resolved in reference to the current working.
Expected behavior
From the spec:
Relative references used in $ref are processed as per JSON Reference, using the URL of the current document as the base URI. See also the Reference Object.
The references should be resolved from the file's url. This does not seem to be an issue for files that are further referenced from referenced files.
Workaround
Change to the directory of the file being called in the cli command or use the --working-directory flag.
Example
/example/f1/spec.yaml:
openapi: 3.1.0
info:
title: test
version: "0"
paths:
/event:
get:
operationId: event
summary: Event
responses:
"200":
description: Success
content:
application/json:
schema:
$ref: "../f2/spec.yaml#/components/schemas/Event"/example/f2/spec.yaml:
openapi: 3.1.0
info:
title: test
version: "0"
components:
schemas:
Event:
type: object
properties:
id:
type: string
name:
$ref: "./f3/spec.yaml#/components/schemas/Name"/example/f2/f3/spec.yaml:
openapi: 3.1.0
info:
title: test
version: "0"
components:
schemas:
Name:
type: string
description: The name of the eventRunning from /example directory, rdme openapi validate f1/spec.yaml
✖ Validating the API definition located at f1/1.yaml...
Error opening file /f2/2.yaml: ENOENT: no such file or directory, open '/f2/2.yaml'
I have included a second test to show that this is only an issue with references in the file passed to the cli command.
Running from /example/f1 directory, rdme openapi validate spec.yaml
1.yaml is a valid OpenAPI API definition!