mirror of
https://github.com/deepseek-ai/deepseek-recipe.git
synced 2026-10-28 17:17:08 +08:00
Merge d44bf1eb6250057b7c0a73e11310eeffaacad56c into 935817c66f5d6e64838f419692545f06787e485f
This commit is contained in:
commit
024d2028f5
@ -78,6 +78,8 @@ pub(crate) enum JsonSchemaType {
|
||||
format: Option<StringFormat>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
r#enum: Option<Vec<String>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
r#const: Option<String>,
|
||||
},
|
||||
#[serde(rename_all = "camelCase")]
|
||||
Number {
|
||||
@ -121,6 +123,8 @@ pub(crate) enum JsonSchemaType {
|
||||
Boolean {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
description: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
r#const: Option<bool>,
|
||||
},
|
||||
#[serde(rename_all = "camelCase")]
|
||||
Array {
|
||||
@ -364,3 +368,28 @@ mod tests {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod contribution_regression {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn primitive_constants_survive_normalization() {
|
||||
for property in [
|
||||
serde_json::json!({"type":"string","const":"fixed"}),
|
||||
serde_json::json!({"type":"boolean","const":true}),
|
||||
] {
|
||||
let result = normalize_strict_schema(
|
||||
serde_json::json!({"type":"object","properties":{"value":property.clone()}}),
|
||||
true,
|
||||
|e| e.to_string(),
|
||||
"root",
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(result["properties"]["value"], property);
|
||||
let validator = jsonschema::options().offline().build(&result).unwrap();
|
||||
assert!(validator.is_valid(&serde_json::json!({"value":property["const"]})));
|
||||
assert!(!validator.is_valid(&serde_json::json!({"value":if property["type"] == "string" {serde_json::json!("other")} else {serde_json::json!(false)}})));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user