Create an array of `Schema`'s from a list of named JSON Avro schemas (Record, Enum, and Fixed). It is allowed that the schemas have cross-dependencies; these will be resolved during parsing. If two of the input schemas have the same fullname, an Error will be returned.
(input: impl IntoIterator<Item = impl AsRef<str>>)
| 538 | /// |
| 539 | /// If two of the input schemas have the same fullname, an Error will be returned. |
| 540 | pub fn parse_list(input: impl IntoIterator<Item = impl AsRef<str>>) -> AvroResult<Vec<Schema>> { |
| 541 | let input = input.into_iter(); |
| 542 | let input_len = input.size_hint().0; |
| 543 | let mut input_schemas: HashMap<Name, JsonValue> = HashMap::with_capacity(input_len); |
| 544 | let mut input_order: Vec<Name> = Vec::with_capacity(input_len); |
| 545 | for json in input { |
| 546 | let json = json.as_ref(); |
| 547 | let schema: JsonValue = serde_json::from_str(json).map_err(Details::ParseSchemaJson)?; |
| 548 | if let JsonValue::Object(inner) = &schema { |
| 549 | // Only clone the values needed for the name parsing, can be a significant time/memory |
| 550 | // save on large schemas |
| 551 | let mut name_json = Map::with_capacity(2); |
| 552 | if let Some(v) = inner.get("name") { |
| 553 | name_json.insert("name".into(), v.clone()); |
| 554 | } |
| 555 | if let Some(v) = inner.get("namespace") { |
| 556 | name_json.insert("namespace".into(), v.clone()); |
| 557 | } |
| 558 | let name = Name::parse(&mut name_json, None)?; |
| 559 | let previous_value = input_schemas.insert(name.clone(), schema); |
| 560 | if previous_value.is_some() { |
| 561 | return Err(Details::NameCollision(name.fullname(None)).into()); |
| 562 | } |
| 563 | input_order.push(name); |
| 564 | } else { |
| 565 | return Err(Details::GetNameField.into()); |
| 566 | } |
| 567 | } |
| 568 | let mut parser = Parser::new( |
no test coverage detected