Skip to content
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 for additionalItems #89

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions parser/src/json/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const DEFAULT_DRAFT: Draft = Draft::Draft202012;
const TYPES: [&str; 6] = ["null", "boolean", "number", "string", "array", "object"];

// Keywords that are implemented in this module
const IMPLEMENTED: [&str; 22] = [
const IMPLEMENTED: [&str; 23] = [
// Core
"anyOf",
"oneOf",
Expand All @@ -26,6 +26,7 @@ const IMPLEMENTED: [&str; 22] = [
"type",
// Array
"items",
"additionalItems",
"prefixItems",
"minItems",
"maxItems",
Expand Down Expand Up @@ -610,7 +611,14 @@ fn compile_type(ctx: &Context, tp: &str, schema: &HashMap<&str, &Value>) -> Resu
get("minItems"),
get("maxItems"),
get("prefixItems"),
get("items"),
match (get("items"), get("additionalItems")) {
(Some(items), None) => Some(items),
(None, Some(additional_items)) => Some(additional_items),
(Some(_), Some(_)) => {
bail!("Cannot specify both 'items' and 'additionalItems'")
}
_ => None,
},
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could alternatively only look for the one that's valid under the detected draft? That being said, I don't think a lot of folks actually annotate their schema with the draft, so that may be kind of useless... thoughts @mmoskal ?

),
"object" => compile_object(
ctx,
Expand Down
Loading