Skip to content

Commit

Permalink
Require unique items in arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
theory committed Jul 19, 2024
1 parent 7d92d3a commit e0a88b8
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions schema/v1/license.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"items": { "$ref": "#/$defs/validLicense" },
"description": "A list of shortcuts to identify well-known licenses for the distribution.",
"minItems": 1,
"uniqueItems": true,
"examples": [["apache_2_0", "postgresql"], ["mit"]]
},
{
Expand Down
1 change: 1 addition & 0 deletions schema/v1/maintainer.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"type": "string",
"minLength": 1
},
"uniqueItems": true,
"minItems": 1
}
],
Expand Down
1 change: 1 addition & 0 deletions schema/v1/no_index.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
{
"type": "array",
"minItems": 1,
"uniqueItems": true,
"items": {
"type": "string",
"description": "Relative path in unix convention to a file to ignore.",
Expand Down
1 change: 1 addition & 0 deletions schema/v2/maintainers.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"type": "array",
"items": { "$ref": "#/$defs/maintainer" },
"minItems": 1,
"uniqueItems": true,
"examples": [
[
{
Expand Down
4 changes: 4 additions & 0 deletions tests/v1_schema_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ fn test_v1_license() -> Result<(), Box<dyn Error>> {
json!([]),
json!({}),
json!({"foo": ":hello"}),
json!(["mit", "mit"]),
] {
if schemas.validate(&invalid_license, idx).is_ok() {
panic!("{} unexpectedly passed!", invalid_license)
Expand Down Expand Up @@ -566,6 +567,7 @@ fn test_v1_maintainer() -> Result<(), Box<dyn Error>> {
("false", json!(false)),
("null", json!(null)),
("object", json!({})),
("dupe", json!(["x", "x"])),
] {
if schemas.validate(&invalid_maintainer.1, idx).is_ok() {
panic!("{} unexpectedly passed!", invalid_maintainer.0)
Expand Down Expand Up @@ -738,6 +740,8 @@ fn test_v1_no_index() -> Result<(), Box<dyn Error>> {
("directory null", json!({"directory": null})),
("unknown field", json!({"file": ["x"], "hi": 0})),
("bare x_", json!({"file": ["x"], "x_": 0})),
("dupe", json!({"file": ["x", "x"]})),
("dupe", json!({"dir": ["x", "x"]})),
("missing required", json!({"x_y": 0})),
] {
if schemas.validate(&invalid_no_index.1, idx).is_ok() {
Expand Down
7 changes: 7 additions & 0 deletions tests/v2_schema_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,13 @@ fn test_v2_maintainers() -> Result<(), Box<dyn Error>> {
"url and email only",
json!([{"url": "x:y", "email": "[email protected]"}]),
),
(
"dupe",
json!([
{"name": "x", "email": "[email protected]"},
{"name": "x", "email": "[email protected]"},
]),
),
// Name
("empty name", json!([{"name": "", "url": "x:y"}])),
("null name", json!([{"name": null, "url": "x:y"}])),
Expand Down

0 comments on commit e0a88b8

Please sign in to comment.