-
-
Notifications
You must be signed in to change notification settings - Fork 532
Add support for custom ref resolvers #1307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Actually, maybe this is just a documentation request. I managed to get the following working: import $RefParser from 'json-schema-ref-parser';
import type {OpenAPI3} from 'openapi-typescript';
import openapiTS from 'openapi-typescript';
async function foo() {
const bundled: OpenAPI3 = await $RefParser.bundle(apiFileName);
const schema = await openapiTS(bundled);
} My only complaint is I lose all the named objects I used to have via |
Yeah this has been reported in other places; this just seems like a bug. I think there are just more tests that need to be written for path resolution. I’m open to the general idea of a resolver, but that should only be needed for aliased paths (which AFAIK the spec doesn’t allow like most JS tools do). The I’m also not opposed to either bundling the spec or encouraging using a 3rd-party library. I just haven’t taken that route yet mostly out of simplicity (it’s annoying for people to use) and I haven’t tested a bundling tool well enough to know it wouldn’t break the TS naming pattern this library uses. All that said, I think resolving the bugs here would be quickest/least disruptive, but again I’m open to all your proposals if that can’t happen for some reason |
I did a lot of reading between opening this ticket and my first comment, so I have new thoughts :)
Agreed, yea, I don't think openapi-typescript needs any special path resolution for things like node style resolution. Instead, folks should use something like what I posted above and pass a resolver to the RefParser.
Any idea why it wouldn't work in this case?
Agreed, I think instead of my original request, these might make more sense:
|
Just released Also added a test specifically for your usecase to make sure it’s working as intended. Hopefully that resolves the issue without the need for an external library or adding a resolver feature, but let me know if the latest version still gives you trouble. |
Thanks! it looks like it's almost working, but I think there's a slight bug.
It's trying to load
when it should be trying to load
My calling code is const apiFileName = path.resolve(projectRootPath, 'api.yml');
const schema = await openapiTS(raw, {
cwd: path.dirname(apiFileName),
}); However, this works: const apiFileName = path.resolve(projectRootPath, 'api.yml');
const schema = await openapiTS(raw, {
cwd: apiFileName
}); I think the solution here is actually to just rename |
Wanted to point out that the upcoming v7 (#1368) uses Redocly for resolving schemas, which seems to be pretty bulletproof. Would love to know if this is still an issue with that upgrade. |
This issue is stale because it has been open for 90 days with no activity. If there is no activity in the next 7 days, the issue will be closed. |
This issue was closed because it has been inactive for 7 days since being marked as stale. Please open a new issue if you believe you are encountering a related problem. |
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:
but that breaks down if there are nested refs.
The docs sort of imply that passing a
cwd
should workbut that still throws
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
The text was updated successfully, but these errors were encountered: