Skip to content

Commit b9fb25f

Browse files
Zantierrlouf
authored andcommitted
Add array and object to enum
Need to allow for whitespace
1 parent 1d82e6f commit b9fb25f

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/json_schema/mod.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,10 +580,22 @@ mod tests {
580580
r#"(0|1)"#,
581581
vec!["0", "1"], vec!["a"],
582582
),
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+
),
583595
// Enum mix of types
584596
(
585-
r#"{"title": "Foo", "enum": [6, 5.3, "potato", true, null]}"#,
586-
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"\})"#,
587599
vec!["6", "5.3", r#""potato""#, "true", "null"], vec!["none", "53"],
588600
),
589601
// ==========================================================

src/json_schema/parsing.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,15 @@ impl<'a> Parser<'a> {
237237
let choices: Result<Vec<String>> = enum_values
238238
.iter()
239239
.map(|choice| match choice {
240-
Value::Null | Value::Bool(_) | Value::Number(_) | Value::String(_) => {
240+
Value::Null
241+
| Value::Bool(_)
242+
| Value::Number(_)
243+
| Value::String(_)
244+
| Value::Array(_)
245+
| Value::Object(_) => {
241246
let json_string = serde_json::to_string(choice)?;
242247
Ok(regex::escape(&json_string))
243248
}
244-
_ => Err(Error::UnsupportedEnumDataType(Box::new(choice.clone()))),
245249
})
246250
.collect();
247251

0 commit comments

Comments
 (0)