Skip to content

feat: Validate with JSON pointer#1075

Open
yahelnachum wants to merge 1 commit intoStranger6667:masterfrom
yahelnachum:validate-with-json-pointer
Open

feat: Validate with JSON pointer#1075
yahelnachum wants to merge 1 commit intoStranger6667:masterfrom
yahelnachum:validate-with-json-pointer

Conversation

@yahelnachum
Copy link
Copy Markdown

@yahelnachum yahelnachum commented Mar 16, 2026

Some documents, such as OpenAPI, do not contain a referenced root schema, but do contain multiple schemas that users would like to validate against. The current solution to this is to create a resource of this document and point into the resource with a small additional root schema. Instead, users should be able to compile the document and at a later time specify a subschema, using a JSON pointer, at execution time.

Summary of code changes:

  • Added an option to collect all <JSON pointer, subschema> pairs for compile-time
  • Added a function to validate with a JSON pointer for execution-time

@Stranger6667
Copy link
Copy Markdown
Owner

Sorry for the delay! I am going to review it next week - need to rework some parts of the registry-related workflows first.

@yahelnachum
Copy link
Copy Markdown
Author

No problem, let me know what you think!

@yahelnachum
Copy link
Copy Markdown
Author

@Stranger6667 have you had a chance to look at this? Thanks again for your time!

@Stranger6667
Copy link
Copy Markdown
Owner

@yahelnachum Sorry for the delay!

My main concern is that the Validator struct gains extra responsibility and transitions from "single validator" into "collection of validators" - my preference would be to have a separate "collection" type for this, that will have a small API surface on its own and will expose the current Validator from it.

Right now there are new error paths (when subschemas is None) that could be avoided if we organize structures differently (i.e. the user always constructs "collection" explicitly and there is nothing to check).

For example, it could be a new "build"-like method on ValidationOptions that will create this new structure (ValidatorMap so it is easier to maybe have some internal changes to map itself in the future / change the map type?), then each Validator can be accessed via a map-like API:

let map = jsonschema::options().build_map(&schema)?;
let user_validator = map["/components/schemas/User"];  # or map.get("...")
user_validator.is_valid(...);

I think this way, the API expansion scope is smaller and the feature itself is harder to misuse

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants