jspg checkpoint
This commit is contained in:
@ -81,7 +81,6 @@ fn resolve_in_place(
|
||||
let mut merged_required = HashSet::new();
|
||||
let mut merged_display = HashSet::new();
|
||||
let mut merged_dependencies = serde_json::Map::new();
|
||||
let mut merged_pattern_props = serde_json::Map::new();
|
||||
|
||||
// Read current values first to let host override included properties
|
||||
if let Some(req) = current.get("required").and_then(|v| v.as_array()) {
|
||||
@ -103,11 +102,7 @@ fn resolve_in_place(
|
||||
merged_dependencies.insert(k.clone(), v.clone());
|
||||
}
|
||||
}
|
||||
if let Some(pat_props) = current.get("patternProperties").and_then(|v| v.as_object()) {
|
||||
for (k, v) in pat_props {
|
||||
merged_pattern_props.insert(k.clone(), v.clone());
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(props) = current.get("properties").and_then(|v| v.as_object()) {
|
||||
for (k, v) in props {
|
||||
merged_props.insert(k.clone(), v.clone());
|
||||
@ -119,7 +114,10 @@ fn resolve_in_place(
|
||||
if visited.contains(inc_name) {
|
||||
errors.push(Error {
|
||||
code: "CIRCULAR_INCLUDE_DETECTED".to_string(),
|
||||
values: Some(HashMap::from([("include".to_string(), inc_name.to_string())])),
|
||||
values: Some(HashMap::from([(
|
||||
"include".to_string(),
|
||||
inc_name.to_string(),
|
||||
)])),
|
||||
details: ErrorDetails {
|
||||
schema: Some(schema_id.to_string()),
|
||||
path: Some(path.to_string()),
|
||||
@ -156,18 +154,6 @@ fn resolve_in_place(
|
||||
}
|
||||
}
|
||||
|
||||
// Merge patternProperties (host overrides trait)
|
||||
if let Some(target_pat_props) = resolved_target
|
||||
.get("patternProperties")
|
||||
.and_then(|v| v.as_object())
|
||||
{
|
||||
for (k, v) in target_pat_props {
|
||||
if !merged_pattern_props.contains_key(k) {
|
||||
merged_pattern_props.insert(k.clone(), v.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Merge required
|
||||
if let Some(target_req) = resolved_target.get("required").and_then(|v| v.as_array()) {
|
||||
for r in target_req {
|
||||
@ -218,7 +204,6 @@ fn resolve_in_place(
|
||||
if let Some(obj) = current.as_object_mut() {
|
||||
for (k, v) in resolved_target.as_object().unwrap() {
|
||||
if k != "properties"
|
||||
&& k != "patternProperties"
|
||||
&& k != "required"
|
||||
&& k != "display"
|
||||
&& k != "dependencies"
|
||||
@ -233,7 +218,10 @@ fn resolve_in_place(
|
||||
} else {
|
||||
errors.push(Error {
|
||||
code: "TRAIT_NOT_FOUND".to_string(),
|
||||
values: Some(HashMap::from([("include".to_string(), inc_name.to_string())])),
|
||||
values: Some(HashMap::from([(
|
||||
"include".to_string(),
|
||||
inc_name.to_string(),
|
||||
)])),
|
||||
details: ErrorDetails {
|
||||
schema: Some(schema_id.to_string()),
|
||||
path: Some(path.to_string()),
|
||||
@ -248,12 +236,7 @@ fn resolve_in_place(
|
||||
if !merged_props.is_empty() {
|
||||
obj.insert("properties".to_string(), Value::Object(merged_props));
|
||||
}
|
||||
if !merged_pattern_props.is_empty() {
|
||||
obj.insert(
|
||||
"patternProperties".to_string(),
|
||||
Value::Object(merged_pattern_props),
|
||||
);
|
||||
}
|
||||
|
||||
if !merged_required.is_empty() {
|
||||
let mut req_vec: Vec<Value> = merged_required.into_iter().map(Value::String).collect();
|
||||
req_vec.sort_by(|a, b| a.as_str().unwrap().cmp(b.as_str().unwrap()));
|
||||
@ -289,22 +272,7 @@ fn resolve_in_place(
|
||||
);
|
||||
}
|
||||
}
|
||||
if let Some(pat_props) = obj
|
||||
.get_mut("patternProperties")
|
||||
.and_then(|v| v.as_object_mut())
|
||||
{
|
||||
for (k, v) in pat_props {
|
||||
resolve_in_place(
|
||||
v,
|
||||
traits,
|
||||
schemas,
|
||||
errors,
|
||||
schema_id,
|
||||
&format!("{}/{}", path, k),
|
||||
visited,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(items) = obj.get_mut("items") {
|
||||
resolve_in_place(
|
||||
items,
|
||||
@ -316,30 +284,6 @@ fn resolve_in_place(
|
||||
visited,
|
||||
);
|
||||
}
|
||||
if let Some(prefix_items) = obj.get_mut("prefixItems").and_then(|v| v.as_array_mut()) {
|
||||
for (i, v) in prefix_items.iter_mut().enumerate() {
|
||||
resolve_in_place(
|
||||
v,
|
||||
traits,
|
||||
schemas,
|
||||
errors,
|
||||
schema_id,
|
||||
&format!("{}/prefixItems/{}", path, i),
|
||||
visited,
|
||||
);
|
||||
}
|
||||
}
|
||||
if let Some(additional_props) = obj.get_mut("additionalProperties") {
|
||||
resolve_in_place(
|
||||
additional_props,
|
||||
traits,
|
||||
schemas,
|
||||
errors,
|
||||
schema_id,
|
||||
&format!("{}/additionalProperties", path),
|
||||
visited,
|
||||
);
|
||||
}
|
||||
if let Some(one_of) = obj.get_mut("oneOf").and_then(|v| v.as_array_mut()) {
|
||||
for (i, v) in one_of.iter_mut().enumerate() {
|
||||
resolve_in_place(
|
||||
|
||||
Reference in New Issue
Block a user