Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: Missing array type in error messages for type validators containing multiple values #217

Merged
merged 1 commit into from
May 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 1 addition & 0 deletions bindings/python/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.6.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
]
)
}
}