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
39 changes: 28 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ GENERATED = \
schemas/xbrl/utr/volume-item-type-normative.json \
schemas/xbrl/utr/volume-item-type.json \
schemas/xbrl/utr/volume-per-monetary-item-type-normative.json \
schemas/xbrl/utr/volume-per-monetary-item-type.json
schemas/xbrl/utr/volume-per-monetary-item-type.json \
schemas/iso/country/2020/alpha-2.json \
schemas/iso/country/2020/alpha-3.json \
schemas/iso/country/2020/numeric.json

# TODO: Make `jsonschema fmt` automatically detect test files
all: common test
Expand Down Expand Up @@ -113,25 +116,37 @@ lint: common
test:
$(JSONSCHEMA) test ./test

build/iso/currency/list-%.json: scripts/xml2json.py vendor/data/iso/currency/list-%.xml
build/iso/currency/list-%.json: \
scripts/xml2json.py \
vendor/data/iso/currency/list-%.xml
$(PYTHON) $< $(word 2,$^) $@
schemas/iso/currency/2015/historical/alpha-code.json: build/iso/currency/list-three.json templates/iso/currency/2015/historical/alpha-code.jq
schemas/iso/currency/2015/historical/alpha-code.json: \
build/iso/currency/list-three.json \
templates/iso/currency/2015/historical/alpha-code.jq
$(MKDIRP) $(dir $@)
$(JQ) --from-file $(word 2,$^) $< > $@
$(JSONSCHEMA) fmt $@
schemas/iso/currency/2015/historical/alpha-currency.json: build/iso/currency/list-three.json templates/iso/currency/2015/historical/alpha-currency.jq
schemas/iso/currency/2015/historical/alpha-currency.json: \
build/iso/currency/list-three.json \
templates/iso/currency/2015/historical/alpha-currency.jq
$(MKDIRP) $(dir $@)
$(JQ) --from-file $(word 2,$^) $< > $@
$(JSONSCHEMA) fmt $@
schemas/iso/currency/2015/historical/numeric-code.json: build/iso/currency/list-three.json templates/iso/currency/2015/historical/numeric-code.jq
schemas/iso/currency/2015/historical/numeric-code.json: \
build/iso/currency/list-three.json \
templates/iso/currency/2015/historical/numeric-code.jq
$(MKDIRP) $(dir $@)
$(JQ) --from-file $(word 2,$^) $< > $@
$(JSONSCHEMA) fmt $@
schemas/iso/currency/2015/historical/numeric-currency.json: build/iso/currency/list-three.json templates/iso/currency/2015/historical/numeric-currency.jq
schemas/iso/currency/2015/historical/numeric-currency.json: \
build/iso/currency/list-three.json \
templates/iso/currency/2015/historical/numeric-currency.jq
$(MKDIRP) $(dir $@)
$(JQ) --from-file $(word 2,$^) $< > $@
$(JSONSCHEMA) fmt $@
schemas/iso/currency/2015/%.json: build/iso/currency/list-one.json templates/iso/currency/2015/%.jq
schemas/iso/currency/2015/%.json: \
build/iso/currency/list-one.json \
templates/iso/currency/2015/%.jq
$(MKDIRP) $(dir $@)
$(JQ) --from-file $(word 2,$^) $< > $@
$(JSONSCHEMA) fmt $@
Expand All @@ -144,10 +159,12 @@ schemas/xbrl/utr/%.json: build/xbrl/utr/utr.json templates/xbrl/utr/%.jq
$(JQ) --from-file $(word 2,$^) $< > $@
$(JSONSCHEMA) fmt $@

generate-iso-language: generate/iso/language/main.py
$(PYTHON) $<
generate-iso-country: generate/iso/country/main.py
$(PYTHON) $<
schemas/iso/country/2020/%.json: \
vendor/iso3166/all/all.json \
templates/iso/country/2020/%.jq
$(MKDIRP) $(dir $@)
$(JQ) --from-file $(word 2,$^) $< > $@
$(JSONSCHEMA) fmt $@


# TODO: Add a `jsonschema pkg` command instead
Expand Down
211 changes: 0 additions & 211 deletions generate/iso/country/main.py

This file was deleted.

27 changes: 27 additions & 0 deletions templates/iso/country/2020/alpha-2.jq
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "ISO 3166-1:2020 Alpha-2 Country Code",
"description": "A two-letter country code from ISO 3166-1",
"examples": (
map(select(.["alpha-2"] != null and .["alpha-2"] != ""))
| sort_by(.["alpha-2"])
| .[0:4]
| map(.["alpha-2"])
),
"x-license": "https://github.com/sourcemeta/std/blob/main/LICENSE",
"x-links": ["https://www.iso.org/iso-3166-country-codes.html"],
"anyOf": (
map(select(.["alpha-2"] != null and .["alpha-2"] != ""))
| sort_by(.["alpha-2"])
| map({
"title": .name,
"x-alpha-3": .["alpha-3"],
"x-numeric": (.["country-code"] | tonumber)
} +
(if .region != null and .region != "" then {"x-region": .region} else {} end) +
(if .["sub-region"] != null and .["sub-region"] != "" then {"x-sub-region": .["sub-region"]} else {} end) +
{
"const": .["alpha-2"]
})
)
}
27 changes: 27 additions & 0 deletions templates/iso/country/2020/alpha-3.jq
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "ISO 3166-1:2020 Alpha-3 Country Code",
"description": "A three-letter country code from ISO 3166-1",
"examples": (
map(select(.["alpha-3"] != null and .["alpha-3"] != ""))
| sort_by(.["alpha-3"])
| .[0:4]
| map(.["alpha-3"])
),
"x-license": "https://github.com/sourcemeta/std/blob/main/LICENSE",
"x-links": ["https://www.iso.org/iso-3166-country-codes.html"],
"anyOf": (
map(select(.["alpha-3"] != null and .["alpha-3"] != ""))
| sort_by(.["alpha-3"])
| map({
"title": .name,
"x-alpha-2": .["alpha-2"],
"x-numeric": (.["country-code"] | tonumber)
} +
(if .region != null and .region != "" then {"x-region": .region} else {} end) +
(if .["sub-region"] != null and .["sub-region"] != "" then {"x-sub-region": .["sub-region"]} else {} end) +
{
"const": .["alpha-3"]
})
)
}
27 changes: 27 additions & 0 deletions templates/iso/country/2020/numeric.jq
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "ISO 3166-1:2020 Numeric Country Code",
"description": "A three-digit numeric country code from ISO 3166-1",
"examples": (
map(select(.["country-code"] != null and .["country-code"] != ""))
| sort_by(.["country-code"])
| .[0:4]
| map(.["country-code"] | tonumber)
),
"x-license": "https://github.com/sourcemeta/std/blob/main/LICENSE",
"x-links": ["https://www.iso.org/iso-3166-country-codes.html"],
"anyOf": (
map(select(.["country-code"] != null and .["country-code"] != ""))
| sort_by(.["country-code"])
| map({
"title": .name,
"x-alpha-2": .["alpha-2"],
"x-alpha-3": .["alpha-3"]
} +
(if .region != null and .region != "" then {"x-region": .region} else {} end) +
(if .["sub-region"] != null and .["sub-region"] != "" then {"x-sub-region": .["sub-region"]} else {} end) +
{
"const": (.["country-code"] | tonumber)
})
)
}