mirror of
https://github.com/deepseek-ai/deepseek-recipe.git
synced 2026-10-28 17:17:08 +08:00
Preserve standard and custom JSON Schema string formats
This commit is contained in:
parent
935817c66f
commit
3d2ae00163
@ -75,7 +75,7 @@ pub(crate) enum JsonSchemaType {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pattern: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
format: Option<StringFormat>,
|
||||
format: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
r#enum: Option<Vec<String>>,
|
||||
},
|
||||
@ -135,17 +135,6 @@ pub(crate) enum JsonSchemaType {
|
||||
},
|
||||
}
|
||||
|
||||
/// A `format` keyword value retained for a string schema.
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub(crate) enum StringFormat {
|
||||
Email,
|
||||
Hostname,
|
||||
Ipv4,
|
||||
Ipv6,
|
||||
Uuid,
|
||||
}
|
||||
|
||||
impl JsonSchema {
|
||||
/// Normalize every object in the schema for strict decoding.
|
||||
///
|
||||
@ -364,3 +353,23 @@ mod tests {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod contribution_regression {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn string_formats_are_not_limited_to_a_small_enum() {
|
||||
for format in [
|
||||
"date-time",
|
||||
"date",
|
||||
"time",
|
||||
"uri",
|
||||
"duration",
|
||||
"custom-format",
|
||||
] {
|
||||
let result = normalize_strict_schema(serde_json::json!({"type":"object","properties":{"value":{"type":"string","format":format}}}), true, |e|e.to_string(), "root").unwrap();
|
||||
assert_eq!(result["properties"]["value"]["format"], format);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user