libopenapi
libopenapi copied to clipboard
Relative references do not resolve properly if they are in an array
Hi, I'm trying to parse a spec that is split in several files and has nested components with relative references to one another.
It appears that if a $ref is given as an array entry then the resolver uses the basePath to resolve the relative paths, instead of whatever nested path that file may be in.
I'm wondering if you know anyway around this issue.
Below is a minimal example where this issue occurs: ./openapi.yaml:
openapi: '3.0.3'
paths:
'/foo':
$ref: './components/foo.yaml'
./components/foo.yaml:
get:
parameters:
- $ref: './param.yaml'
responses:
'200':
$ref: './resp.yaml'
./components/param.yaml:
name: id
in: path
description: user id
required: true
schema:
type: string
./components/resp.yaml:
description: "success"
content:
application/json:
schema:
properties:
message:
type: string
Trying to parse the openapi.yaml file I see the following logs:
{"time":"2025-04-17T17:04:10.156555-06:00","level":"ERROR","msg":"unable to open the rolodex file, check specification references and base path","file":"./param.yaml","error":"open /path/to/project/param.yaml: no such file or directory"}
{"time":"2025-04-17T17:04:10.157939-06:00","level":"ERROR","msg":"unable to locate reference anywhere in the rolodex","reference":"./param.yaml"}
I believe this issue only exists for references as array entries, because there is no error for resp.yaml.
Thank you in advance!