Skip to content

Commit d7e0b6b

Browse files
authored
Generate ISO currency schemas using jq templates (#65)
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
1 parent 70abf40 commit d7e0b6b

30 files changed

Lines changed: 3414 additions & 3062 deletions

Makefile

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
JSONSCHEMA ?= jsonschema
22
SHELLCHECK ?= shellcheck
3+
JQ ?= jq
34
PYTHON ?= python3
45
CURL ?= curl
56
TAR ?= tar
@@ -15,13 +16,32 @@ TESTS = $(shell find test/ -type f -name '*.json')
1516

1617
VERSION = $(shell tr -d '\n\r' < VERSION)
1718

19+
GENERATED = \
20+
schemas/iso/currency/2015/alpha-code.json \
21+
schemas/iso/currency/2015/alpha-currency.json \
22+
schemas/iso/currency/2015/alpha-fund.json \
23+
schemas/iso/currency/2015/alpha-precious-metal.json \
24+
schemas/iso/currency/2015/alpha-test.json \
25+
schemas/iso/currency/2015/alpha-unknown.json \
26+
schemas/iso/currency/2015/numeric-code-additional.json \
27+
schemas/iso/currency/2015/numeric-code.json \
28+
schemas/iso/currency/2015/numeric-currency.json \
29+
schemas/iso/currency/2015/numeric-fund.json \
30+
schemas/iso/currency/2015/numeric-precious-metal.json \
31+
schemas/iso/currency/2015/numeric-test.json \
32+
schemas/iso/currency/2015/numeric-unknown.json \
33+
schemas/iso/currency/2015/historical/alpha-code.json \
34+
schemas/iso/currency/2015/historical/alpha-currency.json \
35+
schemas/iso/currency/2015/historical/numeric-code.json \
36+
schemas/iso/currency/2015/historical/numeric-currency.json
37+
1838
# TODO: Make `jsonschema fmt` automatically detect test files
1939
all: common test
2040
$(JSONSCHEMA) fmt schemas meta --verbose
2141
$(JSONSCHEMA) fmt test --verbose --default-dialect "https://json-schema.org/draft/2020-12/schema"
2242

2343
.PHONY: common
24-
common:
44+
common: $(GENERATED)
2545
$(JSONSCHEMA) metaschema schemas meta --verbose
2646
$(JSONSCHEMA) lint schemas meta --verbose
2747
$(JSONSCHEMA) validate meta/schemas-root.json --verbose $(SCHEMAS)
@@ -42,10 +62,27 @@ test:
4262

4363
build/iso/currency/list-%.json: scripts/xml2json.py vendor/data/iso/currency/list-%.xml
4464
$(PYTHON) $< $(word 2,$^) $@
45-
generate-iso-currency: generate/iso/currency/main.py \
46-
build/iso/currency/list-one.json \
47-
build/iso/currency/list-three.json
48-
$(PYTHON) $<
65+
schemas/iso/currency/2015/historical/alpha-code.json: build/iso/currency/list-three.json templates/iso/currency/2015/historical/alpha-code.jq
66+
$(MKDIRP) $(dir $@)
67+
$(JQ) --from-file $(word 2,$^) $< > $@
68+
$(JSONSCHEMA) fmt $@
69+
schemas/iso/currency/2015/historical/alpha-currency.json: build/iso/currency/list-three.json templates/iso/currency/2015/historical/alpha-currency.jq
70+
$(MKDIRP) $(dir $@)
71+
$(JQ) --from-file $(word 2,$^) $< > $@
72+
$(JSONSCHEMA) fmt $@
73+
schemas/iso/currency/2015/historical/numeric-code.json: build/iso/currency/list-three.json templates/iso/currency/2015/historical/numeric-code.jq
74+
$(MKDIRP) $(dir $@)
75+
$(JQ) --from-file $(word 2,$^) $< > $@
76+
$(JSONSCHEMA) fmt $@
77+
schemas/iso/currency/2015/historical/numeric-currency.json: build/iso/currency/list-three.json templates/iso/currency/2015/historical/numeric-currency.jq
78+
$(MKDIRP) $(dir $@)
79+
$(JQ) --from-file $(word 2,$^) $< > $@
80+
$(JSONSCHEMA) fmt $@
81+
schemas/iso/currency/2015/%.json: build/iso/currency/list-one.json templates/iso/currency/2015/%.jq
82+
$(MKDIRP) $(dir $@)
83+
$(JQ) --from-file $(word 2,$^) $< > $@
84+
$(JSONSCHEMA) fmt $@
85+
4986
generate-iso-language: generate/iso/language/main.py
5087
$(PYTHON) $<
5188
generate-iso-country: generate/iso/country/main.py

generate/iso/currency/main.py

Lines changed: 0 additions & 380 deletions
This file was deleted.

0 commit comments

Comments
 (0)