| 1 | use serde_json::Value; |
| 2 | |
| 3 | use crate::{resource::InnerResourcePtr, Error, Resolver, Segments}; |
| 4 | |
| 5 | use super::subresources::{self, SubresourceIteratorInner}; |
| 6 | |
| 7 | pub(crate) fn object_iter<'a>( |
| 8 | (key, value): (&'a String, &'a Value), |
| 9 | ) -> SubresourceIteratorInner<'a> { |
| 10 | match key.as_str() { |
| 11 | "additionalItems" | "additionalProperties" | "contains" | "not" | "propertyNames" => { |
| 12 | SubresourceIteratorInner::Once(value) |
| 13 | } |
| 14 | "allOf" | "anyOf" | "oneOf" => { |
| 15 | if let Some(arr) = value.as_array() { |
| 16 | SubresourceIteratorInner::Array(arr.iter()) |
| 17 | } else { |
| 18 | SubresourceIteratorInner::Empty |
| 19 | } |
| 20 | } |
| 21 | "definitions" | "patternProperties" | "properties" => { |
| 22 | if let Some(obj) = value.as_object() { |
| 23 | SubresourceIteratorInner::Object(obj.values()) |
| 24 | } else { |
| 25 | SubresourceIteratorInner::Empty |
| 26 | } |
| 27 | } |
| 28 | "items" => match value { |
| 29 | Value::Array(arr) => SubresourceIteratorInner::Array(arr.iter()), |
| 30 | _ => SubresourceIteratorInner::Once(value), |
| 31 | }, |
| 32 | "dependencies" => { |
| 33 | if let Some(obj) = value.as_object() { |
| 34 | SubresourceIteratorInner::FilteredObject(obj.values()) |
| 35 | } else { |
| 36 | SubresourceIteratorInner::Empty |
| 37 | } |
| 38 | } |
| 39 | _ => SubresourceIteratorInner::Empty, |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | pub(crate) fn maybe_in_subresource<'r>( |
| 44 | segments: &Segments, |
| 45 | resolver: &Resolver<'r>, |
| 46 | subresource: &InnerResourcePtr, |
| 47 | ) -> Result<Resolver<'r>, Error> { |
| 48 | const IN_VALUE: &[&str] = &[ |
| 49 | "additionalItems", |
| 50 | "additionalProperties", |
| 51 | "contains", |
| 52 | "not", |
| 53 | "propertyNames", |
| 54 | ]; |
| 55 | const IN_CHILD: &[&str] = &[ |
| 56 | "allOf", |
| 57 | "anyOf", |
| 58 | "oneOf", |
| 59 | "definitions", |
| 60 | "patternProperties", |
| 61 | "properties", |
| 62 | ]; |
| 63 | subresources::maybe_in_subresource_with_items_and_dependencies( |
| 64 | segments, |
| 65 | resolver, |
| 66 | subresource, |
| 67 | IN_VALUE, |
| 68 | IN_CHILD, |
| 69 | ) |
| 70 | } |