-
-
Notifications
You must be signed in to change notification settings - Fork 97
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
Validating individual definitions #432
Comments
I am facing the same problem with internal references. Were you able to figure it out? |
@VoltaireNoir with a very ugly hack: https://github.com/sztomi/dap-rs/blob/main/integration_tests/src/lib.rs#L27 |
Ah, I arrived at the same solution: to replace the references with the appropriate schema. I guess I'll stick with it until jsonschema is able to resolve local/internal references correctly. |
I have complex schema with dependencies between files and defined objects. I can't extract an object like @sztomi has shown in his example. Is it still possible to use this subschema to validate? |
I believe this library supports resolving web and file based references. Try enabling the |
This solves a small portion of my goal. I have several files In current setup I use another validator (as it's a Python project) where I able to load given files into registry and then during application startup add referencing schemas to create an actual validator. Referencing schemas are anonymous schemas with references to an actual object defined in the registry, e.g. containing only Could you please help me how to do a similar thing using this library? |
This is a very useful crate. Nicely done. example:
This is inefficient from a compile time & memory perspective, so I'd like to +1 this request. Options I can think of would be:
I tried to implement a facsimile of (1) by making a version of I think (1) would also help with this issue: #452 |
Hello folks! Sorry for the delay, but I hope that as As suggested in the JSON Schema Slack channel by Greg Dennis, the easiest way would be to create a new schema that directly references the one you need. For example, this test passes as of version #[test]
fn test_subschema() {
// Your root schema
let root = json!({
"$id": "https://example.com/root-schema",
"definitions": {
"NextRequest": {
"type": "object",
"properties": {
"seq": { "type": "integer" },
"type": { "type": "string" },
"command": { "type": "string" },
"arguments": { "$ref": "#/definitions/NextArguments" }
},
"required": ["seq", "type", "command"]
},
"NextArguments": {
"type": "object",
"properties": {
"threadId": { "type": "integer" }
},
"required": ["threadId"]
}
}
});
// Schema for `NextRequest`
let schema = json!({
"$id": "new-schema",
"$ref": "https://example.com/root-schema#/definitions/NextRequest"
});
let validator = jsonschema::options()
.with_resource(
// Make sure you add your root schema
"https://example.com/root-schema",
jsonschema::Resource::from_contents(root).expect("Invalid specification"),
)
.build(&schema)
.expect("Invalid schema");
let valid = json!({
"seq": 153,
"type": "request",
"command": "next",
"arguments": {
"threadId": 3
}
});
let invalid = json!({
"seq": 123,
"type": "request",
"command": "next",
"arguments": {
// This property is invalid
"threadId": "bug"
}
});
assert!(validator.is_valid(&valid));
assert!(!validator.is_valid(&invalid));
} I think it should be enough to solve the original issue for @sztomi. In other words, the solution is already there but I think it is completely unclear how to approach this use case effectively. At least, I didn't have a clue for quite some time. Therefore I plan to do the following in the next couple of releases:
It also seems to me that #452 and #365 are achievable with exactly the same solution above. Tagging the authors for visibility. @jeromegn @VoltaireNoir Please, let me know if I've missed anything or if the proposed solution is not enough. |
Thank you for that explanation, @Stranger6667. That just blew my mind even though it is so simple. Applying it to a real-life case, there is one issue left at least slightly related to this: There are It's not a big deal as I have to use a custom receiver for multiple reasons anyway (YAML, preprocessing that adds EDIT: That is pretty much #640 |
I'm trying to validate JSON snippets against the DAP JSON schema: https://microsoft.github.io/debug-adapter-protocol/debugAdapterProtocol.json
Each type of message is a separate definition. I can extract and compile the relevant definition, but references are not resolved. I think I need to use the
with_document
function, but I'm not sure what the ID is supposed to be.This results in
I tried an empty string as well, but that didn't work either. Any clues?
The text was updated successfully, but these errors were encountered: