Skip to content

Commit be46173

Browse files
committed
stub the Policy schema generator
1 parent e04170b commit be46173

4 files changed

Lines changed: 59 additions & 5 deletions

File tree

schema/README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ This directory contains the templates and code that _generate_ the official JSON
77
At a command prompt within this `schema` directory run:
88

99
```bash
10-
python generate_schemas.py [--agency] [--provider]
10+
python generate_schemas.py [--agency] [--policy] [--provider]
1111
```
1212

13-
The optional flags `--agency` and `--provider` can be used to specify which
13+
The optional flags `--agency`, `--policy`, and `--provider` can be used to specify which
1414
set of schemas to generate. The default is to generate all schemas.
1515

1616
## Updating Schemas
@@ -29,8 +29,6 @@ set of schemas to generate. The default is to generate all schemas.
2929

3030
1. Run the command to regenerate the schema(s).
3131

32-
[agency]: ../agency
3332
[common-module]: common.py
3433
[common-template]: templates/common.json
35-
[provider]: ../provider
3634
[templates]: templates/

schema/generate_schemas.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
Generate the JSON Schema documents for MDS endpoints.
33
44
USAGE:
5-
python generate_schemas.py [--agency] [--provider]
5+
python generate_schemas.py [--agency] [--policy] [--provider]
66
"""
77

88
import sys
99

1010
import agency
1111
import common
12+
import policy
1213
import provider
1314

1415

@@ -17,11 +18,15 @@
1718

1819
if len(sys.argv) == 1:
1920
agency.write_schema_files(common_definitions)
21+
policy.write_schema_files(common_definitions)
2022
provider.write_schema_files(common_definitions)
2123
else:
2224
if "--agency" in sys.argv:
2325
agency.write_schema_files(common_definitions)
2426
sys.argv.remove("--agency")
27+
if "--policy" in sys.argv:
28+
policy.write_schema_files(common_definitions)
29+
sys.argv.remove("--policy")
2530
if "--provider" in sys.argv:
2631
provider.write_schema_files(common_definitions)
2732
sys.argv.remove("--provider")

schema/policy.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""
2+
Schema generators for Policy endpoints.
3+
"""
4+
5+
import json
6+
7+
import common
8+
9+
10+
def policy_schema(common_definitions):
11+
print("Generating policy schema")
12+
13+
14+
def schema_generators():
15+
"""
16+
The dict of schema generators for Policy.
17+
18+
The key is the name of the schema file/template file.
19+
The value is the generator function, taking a dict of common definitions as an argument.
20+
The generator function should return the complete, validated schema document as a dict.
21+
"""
22+
return {
23+
"policy": policy_schema
24+
}
25+
26+
27+
def write_schema_files(common_definitions):
28+
"""
29+
Create each of the Policy endpoint schema files in the appropriate directory.
30+
"""
31+
print("\nStarting to generate Policy JSON Schemas...\n")
32+
33+
for name, generator in schema_generators().items():
34+
schema = generator(common_definitions)
35+
with open(f"../policy/{name}.json", "w") as schemafile:
36+
schemafile.write(json.dumps(schema, indent=2))
37+
print(f"Wrote {name}.json")
38+
39+
print("\nFinished generating Policy JSON Schemas")
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"$id": "https://raw.githubusercontent.com/openmobilityfoundation/mobility-data-specification/main/policy/policy.json",
3+
"$schema": "http://json-schema.org/draft-06/schema#",
4+
"title": "The MDS Policy Schema",
5+
"type": "object",
6+
"definitions": {},
7+
"required": [
8+
],
9+
"properties": {
10+
},
11+
"additionalProperties": false
12+
}

0 commit comments

Comments
 (0)