-
Notifications
You must be signed in to change notification settings - Fork 4
/
noxfile.py
71 lines (61 loc) · 1.92 KB
/
noxfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import nox
from microjson.model import GeoJSON, MicroJSON
import json
@nox.session(python="3.9")
def generate_geojson_pydantic(session):
session.install("-r", "requirements-nox.txt")
session.install("-e", ".")
session.run(
"datamodel-codegen",
"--reuse-model",
"--snake-case-field",
"--input",
"external",
"--output",
"geojson",
"--target",
"3.9",
)
@nox.session(python="3.9")
def generate_roundtrip_json_schema(session):
session.install("-r", "requirements-nox.txt")
session.install("-e", ".")
# generate GeoJSON schema
# Get the schema for the model as a dictionary
schema_dict = GeoJSON.model_json_schema()
# Add 'null' to the list of allowed types for the 'geometry' field of
# Feature object
schema_dict = schema_dict["$defs"]["Feature"]
schema_dict["properties"]["geometry"]["anyOf"].append({"type": "null"})
with open("geojson_schema.json", "w") as f:
f.write(json.dumps(GeoJSON.model_json_schema(), indent=4))
with open("microjson_schema.json", "w") as f:
f.write(json.dumps(MicroJSON.model_json_schema(), indent=4))
@nox.session(python="3.9")
def generate_roundtrip_pydantic(session):
# generate pydantic model from the GeoJSON schema
session.install("-r", "requirements-nox.txt")
session.run(
"datamodel-codegen",
"--reuse-model",
"--snake-case-field",
"--input",
"geojson_schema.json",
"--output",
"geojson/roundtrip.py",
"--target",
"3.9",
)
@nox.session
def typescript(session):
# Install json-schema-to-typescript
session.run("npm", "install", "json-schema-to-typescript", external=True)
# Use json-schema-to-typescript
session.run(
"npx",
"json-schema-to-typescript",
"microjson_schema.json",
"-o",
"microjson.d.ts",
external=True,
)