File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7,10 +7,10 @@ This directory contains the templates and code that _generate_ the official JSON
77At 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
1414set 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
30301 . 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/
Original file line number Diff line number Diff line change 22Generate the JSON Schema documents for MDS endpoints.
33
44USAGE:
5- python generate_schemas.py [--agency] [--provider]
5+ python generate_schemas.py [--agency] [--policy] [-- provider]
66"""
77
88import sys
99
1010import agency
1111import common
12+ import policy
1213import provider
1314
1415
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" )
Original file line number Diff line number Diff line change 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 ("\n Starting 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 ("\n Finished generating Policy JSON Schemas" )
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments