-
-
Notifications
You must be signed in to change notification settings - Fork 242
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
Support resolving JSON refs relative to the initial root #717
Comments
@danielgtaylor |
That would be fantastic :) Even better if this could be exposed as an argument to the |
@danielgtaylor spectral.run(doc, {
resolve: {
documentUri: './paths/root.yaml' // base path. I know it's called documentUri, but any path can be used here :D
},
}); Note - it must be any file under |
@P0lip apologies for the delayed response. I'm a bit confused by the usage -- which OAS file should I provide as the Edit: I think I've figured it out. I can get Spectral working with split files but I had to pass in a custom
Is it possible to update the documentation with this info? |
Yup, it's certainly something we could document. Regarding CLI - I believe the ideal solution would be to allow custom resolvers, so that you can fully customize it. I thought of a |
Yeah I agree. I thought about this yesterday and I've decided to revise the way we construct the
a reference in
and now looks like:
which is a valid relative filesystem path. We used the original method because we thought it'd be easier for users to type, but we can make tooling to address this. This works perfectly with Spectral using a custom resolver and passing in the extra params to |
User story.
As a user, I want to specify all of my
$ref
values as relative paths from the root of the collection of my OAS files, so I don't need to use relative paths and backtracking (i.e.../../
) on very deeply nested OAS files.Is your feature request related to a problem?
The
ResolveRunner
treats all$ref
s as being relative to the directory of the file where it's declared.In the structure below,
paths/v2/greetings/greetings.yaml
needs to referenceschemas/GreetingsObject.yaml
. If the reference is declared asthe resolve fails as it tries to target
/paths/v2/greetings/schemas/GreetingsObject.yaml
as it considered thepaths/v2/greetings
folder to be the parent.Describe the solution you'd like
Spectral should allow for
$ref
values to be resolved as relative paths where the parent is the directory at the root of the OAS collection. The root is the parent folder of the input file to thelint
CLI command:which results in
project
as the parent for all relative$ref
paths.CC @nogates @davidlopezre
The text was updated successfully, but these errors were encountered: