added limit 1 to arrays treated as a single value in schemas

This commit is contained in:
2026-07-16 13:43:08 -04:00
parent 1fedf5253c
commit c4bf6bde58
47 changed files with 616 additions and 586 deletions

View File

@ -1,4 +1,5 @@
use std::collections::{HashMap, HashSet};
use std::collections::HashSet;
use indexmap::IndexMap;
use serde_json::Value;
@ -38,7 +39,7 @@ impl<'a> ValidationContext<'a> {
} else {
result.errors.push(ValidationError {
code: "CONST_VIOLATED".to_string(), // Aligning with original const override errors natively
values: Some(HashMap::from([
values: Some(IndexMap::from([
("value".to_string(), type_str.to_string()),
])),
path: self.join_path("type"),
@ -49,7 +50,7 @@ impl<'a> ValidationContext<'a> {
// Because it's a global entity target, the payload must structurally provide a discriminator natively
result.errors.push(ValidationError {
code: "MISSING_TYPE".to_string(),
values: Some(HashMap::from([
values: Some(IndexMap::from([
("expected".to_string(), expected_type.to_string()),
])),
path: self.path.clone(), // Empty boundary
@ -104,7 +105,7 @@ impl<'a> ValidationContext<'a> {
{
result.errors.push(ValidationError {
code: "MIN_PROPERTIES_VIOLATED".to_string(),
values: Some(HashMap::from([
values: Some(IndexMap::from([
("count".to_string(), obj.len().to_string()),
("limit".to_string(), min.to_string()),
])),
@ -117,7 +118,7 @@ impl<'a> ValidationContext<'a> {
{
result.errors.push(ValidationError {
code: "MAX_PROPERTIES_VIOLATED".to_string(),
values: Some(HashMap::from([
values: Some(IndexMap::from([
("count".to_string(), obj.len().to_string()),
("limit".to_string(), max.to_string()),
])),
@ -131,7 +132,7 @@ impl<'a> ValidationContext<'a> {
if field == "type" {
result.errors.push(ValidationError {
code: "MISSING_TYPE".to_string(),
values: Some(HashMap::from([
values: Some(IndexMap::from([
("field_name".to_string(), "type".to_string()),
])),
path: self.join_path(field),
@ -139,7 +140,7 @@ impl<'a> ValidationContext<'a> {
} else {
result.errors.push(ValidationError {
code: "REQUIRED_FIELD_MISSING".to_string(),
values: Some(HashMap::from([
values: Some(IndexMap::from([
("field_name".to_string(), field.to_string()),
])),
path: self.join_path(field),
@ -158,7 +159,7 @@ impl<'a> ValidationContext<'a> {
if !obj.contains_key(req_prop) {
result.errors.push(ValidationError {
code: "DEPENDENCY_MISSING".to_string(),
values: Some(HashMap::from([
values: Some(IndexMap::from([
("property_name".to_string(), prop.to_string()),
("required_property".to_string(), req_prop.to_string()),
])),