Skip to content
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions examples/ar/catalog.json
Original file line number Diff line number Diff line change
@@ -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"
],
Expand Down Expand Up @@ -73,4 +73,4 @@
"hreflang": "en-US"
}
]
}
}
2 changes: 1 addition & 1 deletion examples/ar/item.json
Original file line number Diff line number Diff line change
@@ -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"
],
Expand Down
4 changes: 2 additions & 2 deletions examples/catalog.json
Original file line number Diff line number Diff line change
@@ -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"
],
Expand Down Expand Up @@ -73,4 +73,4 @@
"hreflang": "en-US"
}
]
}
}
4 changes: 2 additions & 2 deletions examples/de/catalog.json
Original file line number Diff line number Diff line change
@@ -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"
],
Expand Down Expand Up @@ -73,4 +73,4 @@
"hreflang": "en-US"
}
]
}
}
4 changes: 2 additions & 2 deletions examples/de/item.json
Original file line number Diff line number Diff line change
@@ -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"
],
Expand Down Expand Up @@ -105,4 +105,4 @@
"hreflang": "de"
}
}
}
}
2 changes: 1 addition & 1 deletion examples/item.json
Original file line number Diff line number Diff line change
@@ -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"
],
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
54 changes: 54 additions & 0 deletions tests/schema.js
Original file line number Diff line number Diff line change
@@ -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.');