From 153482f5aac8a8b2d4aa2851fe34bee2a4e28a3d Mon Sep 17 00:00:00 2001 From: "David E. Wheeler" Date: Wed, 24 Jul 2024 14:29:06 -0400 Subject: [PATCH] Convert badge to badges --- schema/v1/resources.schema.json | 4 +- schema/v2/badge.schema.json | 29 ------------- schema/v2/badges.schema.json | 35 +++++++++++++++ tests/v2_schema_test.rs | 76 ++++++++++++++++++++------------- 4 files changed, 84 insertions(+), 60 deletions(-) delete mode 100644 schema/v2/badge.schema.json create mode 100644 schema/v2/badges.schema.json diff --git a/schema/v1/resources.schema.json b/schema/v1/resources.schema.json index 373173a..557a97d 100644 --- a/schema/v1/resources.schema.json +++ b/schema/v1/resources.schema.json @@ -1,8 +1,8 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "https://pgxn.org/meta/v1/resources.schema.json", - "title": "Source Control Repository", - "description": "An Extension is provided by a distribution.", + "title": "Resources", + "description": "Resources related to this distribution.", "type": "object", "properties": { "homepage": { diff --git a/schema/v2/badge.schema.json b/schema/v2/badge.schema.json deleted file mode 100644 index f10f302..0000000 --- a/schema/v2/badge.schema.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://pgxn.org/meta/v2/badge.schema.json", - "title": "Badge", - "description": "*Badge* represents a link to a [Shields](https://github.com/badges/shields/blob/master/spec/SPECIFICATION.md \"Shields badge specification\")-conformant badge.", - "type": "object", - "properties": { - "src": { - "type": "string", - "format": "uri", - "description": "The URI for the badge." - }, - "alt": { - "type": "string", - "minLength": 4, - "maxLength": 4048, - "description": "Alternate text for accessability." - } - }, - "required": ["src", "alt"], - "patternProperties": { "^[xX]_.": { "description": "Custom key" } }, - "additionalProperties": false, - "examples": [ - { - "alt": "Test Status", - "src": "https://test.packages.postgresql.org/github.com/example/pair.svg" - } - ] -} diff --git a/schema/v2/badges.schema.json b/schema/v2/badges.schema.json new file mode 100644 index 0000000..2f45395 --- /dev/null +++ b/schema/v2/badges.schema.json @@ -0,0 +1,35 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://pgxn.org/meta/v2/badges.schema.json", + "title": "Badges", + "description": "*Badges* represents links to a [Shields](https://github.com/badges/shields/blob/master/spec/SPECIFICATION.md \"Shields badge specification\")-conformant badges.", + "type": "array", + "minItems": 1, + "items": { + "type": "object", + "properties": { + "src": { + "type": "string", + "format": "uri", + "description": "The URI for the badge." + }, + "alt": { + "type": "string", + "minLength": 4, + "maxLength": 4048, + "description": "Alternate text for accessability." + } + }, + "required": ["src", "alt"], + "patternProperties": { "^[xX]_.": { "description": "Custom key" } }, + "additionalProperties": false + }, + "examples": [ + [ + { + "alt": "Test Status", + "src": "https://test.packages.postgresql.org/github.com/example/pair.svg" + } + ] + ] +} diff --git a/tests/v2_schema_test.rs b/tests/v2_schema_test.rs index 0a644d1..18fc50b 100644 --- a/tests/v2_schema_test.rs +++ b/tests/v2_schema_test.rs @@ -392,6 +392,7 @@ fn test_v2_platforms() -> Result<(), Box> { json!(["linux/amd64"]), json!(["x86_64"]), json!(["darwin_23.5.0_arm64"]), + json!([]), json!([null]), json!(["0"]), json!([0]), @@ -2169,26 +2170,37 @@ fn test_v2_variations() -> Result<(), Box> { } #[test] -fn test_v2_badge() -> Result<(), Box> { +fn test_v2_badges() -> Result<(), Box> { // Load the schemas and compile the maintainer schema. let mut compiler = new_compiler("schema/v2")?; let mut schemas = Schemas::new(); - let id = id_for(SCHEMA_VERSION, "badge"); + let id = id_for(SCHEMA_VERSION, "badges"); let idx = compiler.compile(&id, &mut schemas)?; for valid in [ - ("short", json!({"src": "x:y", "alt": "food"})), + ("short", json!([{"src": "x:y", "alt": "food"}])), ( "long", - json!({ + json!([{ "src": "https://github.com/theory/kv-pair/workflows/CI/badge.svg", "alt": "CI/CD Test Status", - }), + }]), + ), + ( + "multi", + json!([ + {"src": "x:y", "alt": "food"}, + {"src": "a:b", "alt": "tests"}, + {"src": "mailto:x@example.com", "alt": "Contact Me!"}, + ]), + ), + ( + "custom x_", + json!([{"src": "x:y", "alt": "food", "x_y": 1}]), ), - ("custom x_", json!({"src": "x:y", "alt": "food", "x_y": 1})), ( "custom X_", - json!({"src": "x:y", "alt": "food", "X_z": true}), + json!([{"src": "x:y", "alt": "food", "X_z": true}]), ), ] { if let Err(e) = schemas.validate(&valid.1, idx) { @@ -2197,35 +2209,41 @@ fn test_v2_badge() -> Result<(), Box> { } for invalid in [ - ("array", json!([])), + ("empty array", json!([])), ("string", json!("web")), ("empty string", json!("")), ("true", json!(true)), ("false", json!(false)), ("null", json!(null)), - ("empty object", json!({})), - ("only x_", json!({"x_y": 0})), - ("only X_", json!({"X_y": 0})), - ("bare x_", json!({"src": "x:y", "alt": "food", "x_": 0})), - ("bare X_", json!({"src": "x:y", "alt": "food", "x_": 0})), - ("unknown", json!({"src": "x:y", "alt": "food", "foo": 0})), + ("object", json!({})), + ("empty item", json!([{}])), + ("array item", json!([[]])), + ("string item", json!([""])), + ("null item", json!([null])), + ("number item", json!([42])), + ("bool item", json!([true])), + ("only x_", json!([{"x_y": 0}])), + ("only X_", json!([{"X_y": 0}])), + ("bare x_", json!([{"src": "x:y", "alt": "food", "x_": 0}])), + ("bare X_", json!([{"src": "x:y", "alt": "food", "x_": 0}])), + ("unknown", json!([{"src": "x:y", "alt": "food", "foo": 0}])), // src - ("src array", json!({"src": []})), - ("src object", json!({"src": {}})), - ("src empty", json!({"src": ""})), - ("src bool", json!({"src": true})), - ("src number", json!({"src": 42})), - ("src null", json!({"src": null})), - ("src invalid", json!({"src": "xyz"})), - ("src invalid", json!({"src": "not a uri"})), + ("src array", json!([{"alt": "abcd", "src": []}])), + ("src object", json!([{"alt": "abcd", "src": {}}])), + ("src empty", json!([{"alt": "abcd", "src": ""}])), + ("src bool", json!([{"alt": "abcd", "src": true}])), + ("src number", json!([{"alt": "abcd", "src": 42}])), + ("src null", json!([{"alt": "abcd", "src": null}])), + ("src invalid", json!([{"alt": "abcd", "src": "xyz"}])), + ("src invalid", json!([{"alt": "abcd", "src": "not a uri"}])), // alt - ("alt array", json!({"alt": []})), - ("alt object", json!({"alt": {}})), - ("alt empty", json!({"alt": ""})), - ("alt bool", json!({"alt": true})), - ("alt number", json!({"alt": 42})), - ("alt null", json!({"alt": null})), - ("alt too short", json!({"alt": ["xyz"]})), + ("alt array", json!([{"src": "x:y", "alt": []}])), + ("alt object", json!([{"src": "x:y", "alt": {}}])), + ("alt empty", json!([{"src": "x:y", "alt": ""}])), + ("alt bool", json!([{"src": "x:y", "alt": true}])), + ("alt number", json!([{"src": "x:y", "alt": 42}])), + ("alt null", json!([{"src": "x:y", "alt": null}])), + ("alt too short", json!([{"src": "x:y", "alt": ["xyz"]}])), ] { if schemas.validate(&invalid.1, idx).is_ok() { panic!("{} unexpectedly passed!", invalid.0)