Closed as not planned
Description
Description
I'd really like to be able to support relative file refs. The spec appears to allow them and absolute file paths are impractical for my use case.
Proposal
I was able to use this to deal with the first layer of refs:
const rawWithFullPaths = raw.replaceAll(
/\$ref: '(\..*)'/g,
(match, p1) => `$ref: 'file://${path.resolve(path.dirname(apiFileName), p1)}'`
);
const parsed = yml.load(rawWithFullPaths) as OpenAPI3;
const schema = await openapiTS(parsed);
but that breaks down if there are nested refs.
The docs sort of imply that passing a cwd
should work
Specify current working directory (cwd) to resolve remote schemas on disk (not needed for remote URL schemas)
const parsed = yml.load(raw) as OpenAPI3;
const schema = await openapiTS(parsed, {
cwd: path.dirname(apiFileName),
});
but that still throws
✘ Can’t resolve "../../../lib/@clc/health/schema/health-check-response.schema.json" from dynamic JSON. Load this schema from a URL instead.
Would it be practical for openapiTS()
to accept a resolver function? By default, it wouldn't necessarily need to do anything more than maintain current behavior (though supporting e.g. node module resolve would be nice 🙂), but it would enable folks to write their own resolvers.
Checklist
- I’m willing to open a PR for this (see CONTRIBUTING.md)