Skip to content

Commit

Permalink
Implement validation keywords for arrays (#18)
Browse files Browse the repository at this point in the history
* Added structure for parsing minItems and maxItems in the SchemaInteger type

* Run validation against minItems and maxItems

* Check if minItems is greater than maxItems before returning a valid schema

* Minor cosmetic changes to some tests

* Added construction and validation tests for minItems and maxItems

* Added uniqueItems flag to arrays

* Simplified array instantiation, and fixed some test cases checking for wrong errors.

* Implemented 'contains' functionality
  • Loading branch information
MathiasPius authored Feb 23, 2020
1 parent 2cc3cf1 commit 2a9efc5
Show file tree
Hide file tree
Showing 6 changed files with 499 additions and 64 deletions.
3 changes: 2 additions & 1 deletion yaml-validator/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ mod tests {
level2:
type: object
items:
leaf: hello
leaf:
notype: hello
"#,
);

Expand Down
8 changes: 8 additions & 0 deletions yaml-validator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ enum PropertyType<'schema> {
impl<'schema> TryFrom<&'schema Yaml> for PropertyType<'schema> {
type Error = SchemaError<'schema>;
fn try_from(yaml: &'schema Yaml) -> Result<Self, Self::Error> {
if yaml.as_hash().is_none() {
return Err(SchemaErrorKind::WrongType {
expected: "hash",
actual: yaml.type_to_str(),
}
.into());
}

let reference = yaml
.lookup("$ref", "string", Yaml::as_str)
.map(Option::from)
Expand Down
Loading

0 comments on commit 2a9efc5

Please sign in to comment.