-
Notifications
You must be signed in to change notification settings - Fork 40
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
Feature request: Allow validation of $schema specified in JSON file #310
Comments
Hi there; I'm happy to see if there's a way to meet your needs with a new feature, but I don't think what you're looking for is That keyword is defined rather specifically. It defines the dialect of JSON Schema used by a schema document. It isn't defined for use in any non-schema documents, and I would be very hesitant to use it there. I think there are other ways we can address this, but I'll need to make sure I understand your use case and think about it more. Is your situation basically that you want to be able to embed a reference to a schema in your instances, and have each instance validate against its referenced schema? |
Hmm, jsonls also provides extensive autocompletion for using $schema values. (json.schemastore.org). Vscode respects the schema set also. See https://code.visualstudio.com/docs/languages/json#_mapping-in-the-json for the docs. It confirms that specifying it this way is non-standard, but it seems like an established procedure.
Yeah, a project might have json files for different schemas. Having such info inside the documents will ensure that IDEs provide proper autocompletion without having to manually configure them. Same for the actual linting, where one would otherwise need a mapper-like config file. But those are not standardized in different text editors/IDEs AFAIK. |
I asked around a little to see if the spec maintainers have strong feelings about this usage. My plan is therefore to add a flag for this. Exact name TBD, but my first thought is I'll need to take some time to work out behavior for this. There are some details to work out -- e.g. if given multiple files, do you load all of their relevant schemas first, or do you process them one-at-a-time? -- but I'm sure everything is solvable. |
How would that flag work in case I run it on files where only some of them have $schema set? And would that flag discard the schemafile that might be provided as another option? (not allowing both to be set could be valid too)
Amazing! Thanks a lot :) |
I presume it should fail on those files. The interface would be something like
During such usage -- where everything is fully explicit -- if Realistic usage may look more like
But that doesn't move the needle significantly. First because that's "just" a shorthand which expands to some explicit argument list. But second, what if the caller meant to specify only files with
The two would be mutually exclusive, like the other schema selection options which exist today. ( If I had designed |
What if you'd like to scan all |
Heyho,
I have created a generic schema that I want to run against json files in different projects. This works great by passing in a schemafile to the validator. But some projects/files could use a more specific schema based on the generic one.
I could specify a $schema in the json contents, but that would get ignored in favor of the schemafile passed in as a CLI argument. In case the user uses a json language server, they would get the proper typehints.
Could the $schema be respected by this cli tool? Maybe even opt-in.
The text was updated successfully, but these errors were encountered: