77import common
88
99
10- def get_stops_schema (common_definitions ):
10+ def get_stops_schema ():
1111 """
1212 Create the schema for the Agency GET /stops endpoint.
1313 """
1414 # load schema template and insert definitions
1515 schema = common .load_json ("./templates/agency/get_stops.json" )
16- stops = common .stop_definitions (common_definitions )
16+ stops = common .stop_definitions ()
1717 schema ["definitions" ].update (stops )
1818
1919 # verify and return
2020 return common .check_schema (schema )
2121
2222
23- def post_stops_schema (common_definitions ):
23+ def post_stops_schema ():
2424 """
2525 Create the schema for the Agency POST /stops endpoint.
2626 """
2727 # load schema template and insert definitions
2828 schema = common .load_json ("./templates/agency/post_stops.json" )
29- stops = common .stop_definitions (common_definitions )
29+ stops = common .stop_definitions ()
3030 schema ["definitions" ].update (stops )
3131
3232 # verify and return
3333 return common .check_schema (schema )
3434
3535
36- def put_stops_schema (common_definitions ):
36+ def put_stops_schema ():
3737 """
3838 Create the schema for the Agency POST /stops endpoint.
3939 """
@@ -42,60 +42,62 @@ def put_stops_schema(common_definitions):
4242 # the PUT body allows a small subset of fields
4343 schema = common .load_json ("./templates/agency/put_stops.json" )
4444
45- stop_defs = common .stop_definitions (common_definitions )
45+ stops = common .stop_definitions ()
4646 needed_defs = ["stop_status" , "uuid" , "vehicle_type_counts" ]
47- for key in [k for k in stop_defs .keys () if k not in needed_defs ]:
48- del stop_defs [key ]
47+ for key in [k for k in stops .keys () if k not in needed_defs ]:
48+ del stops [key ]
4949
50- schema ["definitions" ].update (stop_defs )
50+ schema ["definitions" ].update (stops )
5151
5252 # verify and return
5353 return common .check_schema (schema )
5454
5555
56- def get_vehicle_schema (common_definitions ):
56+ def get_vehicle_schema ():
5757 """
5858 Create the schema for the Agency GET /vehicles endpoint.
5959 """
6060 # load schema template and insert definitions
6161 schema = common .load_json ("./templates/agency/get_vehicle.json" )
62- schema ["definitions" ] = {
63- "propulsion_types" : common_definitions ["propulsion_types" ],
64- "string" : common_definitions ["string" ],
65- "vehicle_type" : common_definitions ["vehicle_type" ],
66- "timestamp" : common_definitions ["timestamp" ],
67- "uuid" : common_definitions ["uuid" ]
68- }
62+ definitions = common .load_definitions (
63+ "propulsion_types" ,
64+ "string" ,
65+ "timestamp" ,
66+ "vehicle_type" ,
67+ "uuid"
68+ )
69+ schema ["definitions" ].update (definitions )
6970
7071 # merge the state machine definitions and transition combinations rule
71- state_machine_defs , transitions = common .vehicle_state_machine (common_definitions , "state" , "prev_events" )
72+ state_machine_defs , transitions = common .vehicle_state_machine ("state" , "prev_events" )
7273 schema ["definitions" ].update (state_machine_defs )
7374 schema ["allOf" ].append (transitions )
7475
7576 # merge common vehicle information, with Agency tweaks
76- vehicle = common .vehicle_definition (common_definitions , provider_name = False )
77+ vehicle = common .vehicle_definition (provider_name = False )
7778 schema ["required" ] = vehicle ["required" ] + schema ["required" ]
7879 schema ["properties" ] = { ** vehicle ["properties" ], ** schema ["properties" ] }
7980
8081 # verify and return
8182 return common .check_schema (schema )
8283
8384
84- def post_vehicle_schema (common_definitions ):
85+ def post_vehicle_schema ():
8586 """
8687 Create the schema for the Agency POST /vehicles endpoint.
8788 """
8889 # load schema template and insert definitions
8990 schema = common .load_json ("./templates/agency/post_vehicle.json" )
90- schema ["definitions" ] = {
91- "propulsion_types" : common_definitions ["propulsion_types" ],
92- "string" : common_definitions ["string" ],
93- "vehicle_type" : common_definitions ["vehicle_type" ],
94- "uuid" : common_definitions ["uuid" ]
95- }
91+ definitions = common .load_definitions (
92+ "propulsion_types" ,
93+ "string" ,
94+ "vehicle_type" ,
95+ "uuid"
96+ )
97+ schema ["definitions" ].update (definitions )
9698
9799 # merge common vehicle information, with Agency tweaks
98- vehicle = common .vehicle_definition (common_definitions , provider_name = False , provider_id = False )
100+ vehicle = common .vehicle_definition (provider_name = False , provider_id = False )
99101
100102 schema ["required" ] = vehicle ["required" ] + schema ["required" ]
101103 schema ["properties" ] = { ** vehicle ["properties" ], ** schema ["properties" ] }
@@ -104,42 +106,44 @@ def post_vehicle_schema(common_definitions):
104106 return common .check_schema (schema )
105107
106108
107- def post_vehicle_event_schema (common_definitions ):
109+ def post_vehicle_event_schema ():
108110 """
109111 Create the schema for the Agency POST /vehicles/:id/event endpoint.
110112 """
111113 # load schema template and insert definitions
112114 schema = common .load_json ("./templates/agency/post_vehicle_event.json" )
113- schema ["definitions" ] = {
114- "telemetry" : common_definitions ["telemetry" ],
115- "timestamp" : common_definitions ["timestamp" ],
116- "uuid" : common_definitions ["uuid" ]
117- }
115+ definitions = common .load_definitions (
116+ "telemetry" ,
117+ "timestamp" ,
118+ "uuid"
119+ )
120+ schema ["definitions" ].update (definitions )
118121
119122 # merge the state machine definitions and transition combinations rule
120- state_machine_defs , transitions = common .vehicle_state_machine (common_definitions , "vehicle_state" , "event_types" )
123+ state_machine_defs , transitions = common .vehicle_state_machine ("vehicle_state" , "event_types" )
121124 schema ["definitions" ].update (state_machine_defs )
122125 schema ["allOf" ].append (transitions )
123126
124127 # add the conditionally-required trip_id rule
125- trip_id_ref = common_definitions [ "trip_id_reference" ]
128+ trip_id_ref = common . load_definitions ( "trip_id_reference" )
126129 schema ["allOf" ].append (trip_id_ref )
127130
128131 # verify and return
129132 return common .check_schema (schema )
130133
131134
132- def post_vehicle_telemetry_schema (common_definitions ):
135+ def post_vehicle_telemetry_schema ():
133136 """
134137 Create the schema for the Agency POST /vehicles/telemetry endpoint.
135138 """
136139 # load schema template and insert definitions
137140 schema = common .load_json ("./templates/agency/post_vehicle_telemetry.json" )
138- schema ["definitions" ] = {
139- "telemetry" : common_definitions ["telemetry" ],
140- "timestamp" : common_definitions ["timestamp" ],
141- "uuid" : common_definitions ["uuid" ]
142- }
141+ definitions = common .load_definitions (
142+ "telemetry" ,
143+ "timestamp" ,
144+ "uuid"
145+ )
146+ schema ["definitions" ].update (definitions )
143147
144148 # verify and return
145149 return common .check_schema (schema )
@@ -164,14 +168,14 @@ def schema_generators():
164168 }
165169
166170
167- def write_schema_files (common_definitions ):
171+ def write_schema_files ():
168172 """
169173 Create each of the Agency endpoint schema files in the appropriate directory.
170174 """
171175 print ("\n Starting to generate Agency JSON Schemas...\n " )
172176
173177 for name , generator in schema_generators ().items ():
174- schema = generator (common_definitions )
178+ schema = generator ()
175179 with open (f"../agency/{ name } .json" , "w" ) as schemafile :
176180 schemafile .write (json .dumps (schema , indent = 2 ))
177181 print (f"Wrote { name } .json" )
0 commit comments