Skip to content

Commit

Permalink
fix: Missing array type in error messages for type validators con…
Browse files Browse the repository at this point in the history
…taining multiple values

Ref: #216
  • Loading branch information
Stranger6667 committed May 5, 2021
1 parent 2c399ac commit 81ca4f7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Fixed

- Skipped validation on an unsupported regular expression in `patternProperties`. [#213](https://github.com/Stranger6667/jsonschema-rs/issues/213)
- Missing `array` type in error messages for `type` validators containing multiple values. [#216](https://github.com/Stranger6667/jsonschema-rs/issues/216)

## [0.8.2] - 2021-05-03

Expand Down
28 changes: 26 additions & 2 deletions jsonschema/src/primitive_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{convert::TryFrom, fmt, ops::BitOrAssign};

/// For faster error handling in "type" keyword validator we have this enum, to match
/// with it instead of a string.
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
#[allow(missing_docs)]
pub enum PrimitiveType {
Array,
Expand Down Expand Up @@ -121,7 +121,7 @@ impl IntoIterator for PrimitiveTypesBitMap {
type IntoIter = PrimitiveTypesBitMapIterator;
fn into_iter(self) -> Self::IntoIter {
PrimitiveTypesBitMapIterator {
range: 1..7,
range: 0..7,
bit_map: self,
}
}
Expand Down Expand Up @@ -159,3 +159,27 @@ impl Iterator for PrimitiveTypesBitMapIterator {
}
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_multiple_types() {
let mut types = PrimitiveTypesBitMap::new();
types |= PrimitiveType::Null;
types |= PrimitiveType::String;
types |= PrimitiveType::Array;
assert!(types.contains_type(PrimitiveType::Null));
assert!(types.contains_type(PrimitiveType::String));
assert!(types.contains_type(PrimitiveType::Array));
assert_eq!(
types.into_iter().collect::<Vec<PrimitiveType>>(),
vec![
PrimitiveType::Array,
PrimitiveType::Null,
PrimitiveType::String
]
)
}
}

0 comments on commit 81ca4f7

Please # to comment.