diff --git a/CHANGELOG.md b/CHANGELOG.md index 762f376..aacb671 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,8 +8,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- Validate `hreflang` on links and assets. + ### Changed +- Update the examples to STAC 1.1.0. + ### Deprecated ### Removed diff --git a/examples/ar/catalog.json b/examples/ar/catalog.json index cbdaa75..055fb8e 100644 --- a/examples/ar/catalog.json +++ b/examples/ar/catalog.json @@ -1,5 +1,5 @@ { - "stac_version": "1.0.0", + "stac_version": "1.1.0", "stac_extensions": [ "https://stac-extensions.github.io/language/v1.0.0/schema.json" ], @@ -73,4 +73,4 @@ "hreflang": "en-US" } ] -} \ No newline at end of file +} diff --git a/examples/ar/item.json b/examples/ar/item.json index d1deac9..6c47ee8 100644 --- a/examples/ar/item.json +++ b/examples/ar/item.json @@ -1,5 +1,5 @@ { - "stac_version": "1.0.0", + "stac_version": "1.1.0", "stac_extensions": [ "https://stac-extensions.github.io/language/v1.0.0/schema.json" ], diff --git a/examples/catalog.json b/examples/catalog.json index 9674022..99b6321 100644 --- a/examples/catalog.json +++ b/examples/catalog.json @@ -1,5 +1,5 @@ { - "stac_version": "1.0.0", + "stac_version": "1.1.0", "stac_extensions": [ "https://stac-extensions.github.io/language/v1.0.0/schema.json" ], @@ -73,4 +73,4 @@ "hreflang": "en-US" } ] -} \ No newline at end of file +} diff --git a/examples/de/catalog.json b/examples/de/catalog.json index d9abee0..9c09cd5 100644 --- a/examples/de/catalog.json +++ b/examples/de/catalog.json @@ -1,5 +1,5 @@ { - "stac_version": "1.0.0", + "stac_version": "1.1.0", "stac_extensions": [ "https://stac-extensions.github.io/language/v1.0.0/schema.json" ], @@ -73,4 +73,4 @@ "hreflang": "en-US" } ] -} \ No newline at end of file +} diff --git a/examples/de/item.json b/examples/de/item.json index 14500fe..1e327d3 100644 --- a/examples/de/item.json +++ b/examples/de/item.json @@ -1,5 +1,5 @@ { - "stac_version": "1.0.0", + "stac_version": "1.1.0", "stac_extensions": [ "https://stac-extensions.github.io/language/v1.0.0/schema.json" ], @@ -105,4 +105,4 @@ "hreflang": "de" } } -} \ No newline at end of file +} diff --git a/examples/item.json b/examples/item.json index 540d9d1..a690d03 100644 --- a/examples/item.json +++ b/examples/item.json @@ -1,5 +1,5 @@ { - "stac_version": "1.0.0", + "stac_version": "1.1.0", "stac_extensions": [ "https://stac-extensions.github.io/language/v1.0.0/schema.json" ], diff --git a/package.json b/package.json index 3defabd..0bd207d 100644 --- a/package.json +++ b/package.json @@ -2,12 +2,14 @@ "name": "stac-extensions", "version": "1.0.0", "scripts": { - "test": "npm run check-markdown && npm run check-examples", + "test": "npm run check-markdown && npm run check-examples && npm run check-schema", "check-markdown": "remark . -f -r .github/remark.yaml", "check-examples": "stac-node-validator . --lint --verbose --schemaMap https://stac-extensions.github.io/language/v1.0.0/schema.json=./json-schema/schema.json", + "check-schema": "node tests/schema.js", "format-examples": "stac-node-validator . --format --schemaMap https://stac-extensions.github.io/language/v1.0.0/schema.json=./json-schema/schema.json" }, "dependencies": { + "ajv": "^8.20.0", "remark-cli": "^8.0.0", "remark-lint": "^7.0.0", "remark-lint-no-html": "^2.0.0", diff --git a/tests/schema.js b/tests/schema.js new file mode 100644 index 0000000..9747ff6 --- /dev/null +++ b/tests/schema.js @@ -0,0 +1,54 @@ +const assert = require('node:assert/strict'); +const fs = require('node:fs'); +const path = require('node:path'); + +const Ajv = require('ajv'); + +const extensionId = 'https://stac-extensions.github.io/language/v1.0.0/schema.json'; +const schemaPath = path.join(__dirname, '..', 'json-schema', 'schema.json'); +const schema = JSON.parse(fs.readFileSync(schemaPath, 'utf8')); +const validate = new Ajv({allErrors: true, strict: false}).compile(schema); + +function assertInvalidHreflang(document, path) { + assert.equal(validate(document), false); + assert.ok( + validate.errors.some(error => error.instancePath === path), + `expected a validation error at ${path}` + ); +} + +assertInvalidHreflang( + { + stac_version: '1.1.0', + stac_extensions: [extensionId], + type: 'Catalog', + language: {code: 'en'}, + links: [ + { + rel: 'alternate', + href: 'de/catalog.json', + hreflang: 123 + } + ] + }, + '/links/0/hreflang' +); + +assertInvalidHreflang( + { + stac_version: '1.1.0', + stac_extensions: [extensionId], + type: 'Feature', + properties: {language: {code: 'en'}}, + links: [], + assets: { + metadata: { + href: 'metadata.xml', + hreflang: 123 + } + } + }, + '/assets/metadata/hreflang' +); + +console.log('Invalid hreflang values are rejected on links and assets.');