fix: Allow using empty arrays or arrays with non-unique elements for the `enum` keyword in schemas

Signed-off-by: Dmitry Dygalo <dadygalo@gmail.com>
This commit is contained in:
Dmitry Dygalo 2021-07-26 09:31:54 +02:00 committed by Dmitry Dygalo
parent f03a8f5f24
commit 7d8364ec9c
6 changed files with 26 additions and 10 deletions

View File

@ -2,6 +2,10 @@
## [Unreleased]
### Fixed
- Allow using empty arrays or arrays with non-unique elements for the `enum` keyword in schemas. [#258](https://github.com/Stranger6667/jsonschema-rs/issues/258)
## [0.12.0] - 2021-07-24
### Added

View File

@ -2,6 +2,10 @@
## [Unreleased]
### Fixed
- Allow using empty arrays or arrays with non-unique elements for the `enum` keyword in schemas. [#258](https://github.com/Stranger6667/jsonschema-rs/issues/258)
## [0.12.0] - 2021-07-24
### Changed

View File

@ -120,9 +120,7 @@
}
},
"enum": {
"type": "array",
"minItems": 1,
"uniqueItems": true
"type": "array"
},
"type": {
"anyOf": [

View File

@ -130,9 +130,7 @@
"propertyNames": { "$ref": "#" },
"const": {},
"enum": {
"type": "array",
"minItems": 1,
"uniqueItems": true
"type": "array"
},
"type": {
"anyOf": [

View File

@ -142,9 +142,7 @@
"const": true,
"enum": {
"type": "array",
"items": true,
"minItems": 1,
"uniqueItems": true
"items": true
},
"type": {
"anyOf": [

View File

@ -185,8 +185,9 @@ pub(crate) mod tests_util {
#[cfg(test)]
mod tests {
use super::is_valid;
use super::{is_valid, Draft, JSONSchema};
use serde_json::json;
use test_case::test_case;
#[test]
fn test_is_valid() {
@ -196,4 +197,17 @@ mod tests {
assert!(is_valid(&schema, &valid));
assert!(!is_valid(&schema, &invalid));
}
#[test_case(Draft::Draft4)]
#[test_case(Draft::Draft6)]
#[test_case(Draft::Draft7)]
fn meta_schemas(draft: Draft) {
// See GH-258
for schema in [json!({"enum": [0, 0.0]}), json!({"enum": []})] {
assert!(JSONSchema::options()
.with_draft(draft)
.compile(&schema)
.is_ok())
}
}
}