We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1d82e6f commit b9fb25fCopy full SHA for b9fb25f
src/json_schema/mod.rs
@@ -580,10 +580,22 @@ mod tests {
580
r#"(0|1)"#,
581
vec!["0", "1"], vec!["a"],
582
),
583
+ // Enum array
584
+ (
585
+ r#"{"title": "Foo", "enum": [[1,2],[3,4]], "type": "array"}"#,
586
+ r#"(\[1,2\]|\[3,4\])"#,
587
+ vec!["[1,2]", "[3,4]"], vec!["1", "[1,3]"],
588
+ ),
589
+ // Enum object
590
591
+ r#"{"title": "Foo", "enum": [{"a":"b"}, {"c":"d"}], "type": "object"}"#,
592
+ r#"(\{"a":"b"\}|\{"c":"d"\})"#,
593
+ vec![r#"{"a":"b"}"#, r#"{"c":"d"}"#], vec!["a", r#"{"a":"c"}"#],
594
595
// Enum mix of types
596
(
- r#"{"title": "Foo", "enum": [6, 5.3, "potato", true, null]}"#,
- r#"(6|5\.3|"potato"|true|null)"#,
597
+ r#"{"title": "Foo", "enum": [6, 5.3, "potato", true, null, [1,2], {"a":"b"}]}"#,
598
+ r#"(6|5\.3|"potato"|true|null|\[1,2\]|\{"a":"b"\})"#,
599
vec!["6", "5.3", r#""potato""#, "true", "null"], vec!["none", "53"],
600
601
// ==========================================================
src/json_schema/parsing.rs
@@ -237,11 +237,15 @@ impl<'a> Parser<'a> {
237
let choices: Result<Vec<String>> = enum_values
238
.iter()
239
.map(|choice| match choice {
240
- Value::Null | Value::Bool(_) | Value::Number(_) | Value::String(_) => {
+ Value::Null
241
+ | Value::Bool(_)
242
+ | Value::Number(_)
243
+ | Value::String(_)
244
+ | Value::Array(_)
245
+ | Value::Object(_) => {
246
let json_string = serde_json::to_string(choice)?;
247
Ok(regex::escape(&json_string))
248
}
- _ => Err(Error::UnsupportedEnumDataType(Box::new(choice.clone()))),
249
})
250
.collect();
251
0 commit comments