Skip to content

Wrong implementation on json schema validation #374

@4t145

Description

@4t145

Describe the bug
A clear and concise description of what the bug is.

current implementation

/// Validate that a JSON value conforms to basic type constraints from a schema.
///
/// Note: This is a basic validation that only checks type compatibility.
/// For full JSON Schema validation, a dedicated validation library would be needed.
pub fn validate_against_schema(
    value: &serde_json::Value,
    schema: &JsonObject,
) -> Result<(), crate::ErrorData> {
    // Basic type validation
    if let Some(schema_type) = schema.get("type").and_then(|t| t.as_str()) {
        let value_type = get_json_value_type(value);

        if schema_type != value_type {
            return Err(crate::ErrorData::invalid_params(
                format!(
                    "Value type does not match schema. Expected '{}', got '{}'",
                    schema_type, value_type
                ),
                None,
            ));
        }
    }

    Ok(())
}

Apparently this is too simple to do it, it only cover the basic types.

Type also could be other non-basic type like integer or multiple type like ["string", "number"]. So we need a correct implementation.

To Reproduce
Steps to reproduce the behavior:
1.

Expected behavior
A clear and concise description of what you expected to happen.

Logs
If applicable, add logs to help explain your problem.

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions