Skip to content

Commit 748efb6

Browse files
committed
deduplicate Provider schema generation
This is a refactor of the Provider schema templates and generation process to make more reuse of common types and structures: * The repeated structure from outside wrapper has been refactored into templates/provider/endpoint.json * Common vehicle information (provider_id, vehicle_type, etc.) has been refactored into a defintion in templates/common.json, which is added to the list of definitions for each endpoint * Each endpoint specific template has been refactored to contain only those properties and definitions specific to the endpoint; common properties and definitions are merged at generation time * The generation script was improved for readability and runtime feedback * The generation script accepts arguments for selectively generating Agency and/or Provider schemas (default is still to generate both)
1 parent 13589b5 commit 748efb6

12 files changed

Lines changed: 1149 additions & 1051 deletions

File tree

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
.venv/
1+
.venv/
2+
.vscode
3+
__pycache__

provider/dockless/events.json

Lines changed: 180 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,152 @@
11
{
22
"$id": "https://raw.githubusercontent.com/openmobilityfoundation/mobility-data-specification/main/provider/dockless/events.json",
33
"$schema": "http://json-schema.org/draft-06/schema#",
4-
"title": "The MDS Provider Schema, events payload",
4+
"title": "Schema for MDS Provider events payloads",
55
"type": "object",
66
"definitions": {
7+
"Point": {
8+
"$id": "#/definitions/Point",
9+
"title": "GeoJSON Point",
10+
"type": "object",
11+
"required": [
12+
"type",
13+
"coordinates"
14+
],
15+
"properties": {
16+
"type": {
17+
"type": "string",
18+
"enum": [
19+
"Point"
20+
]
21+
},
22+
"coordinates": {
23+
"type": "array",
24+
"minItems": 2,
25+
"items": [
26+
{
27+
"type": "number",
28+
"minimum": -180.0,
29+
"maximum": 180.0
30+
},
31+
{
32+
"type": "number",
33+
"minimum": -90.0,
34+
"maximum": 90.0
35+
}
36+
],
37+
"maxItems": 2
38+
},
39+
"bbox": {
40+
"type": "array",
41+
"minItems": 4,
42+
"items": {
43+
"type": "number"
44+
}
45+
}
46+
}
47+
},
48+
"MDS_Feature_Point": {
49+
"$id": "#/definitions/MDS_Feature_Point",
50+
"title": "MDS GeoJSON Feature Point",
51+
"type": "object",
52+
"required": [
53+
"type",
54+
"properties",
55+
"geometry"
56+
],
57+
"properties": {
58+
"type": {
59+
"type": "string",
60+
"enum": [
61+
"Feature"
62+
]
63+
},
64+
"properties": {
65+
"type": "object",
66+
"required": [
67+
"timestamp"
68+
],
69+
"properties": {
70+
"timestamp": {
71+
"$ref": "#/definitions/timestamp"
72+
}
73+
}
74+
},
75+
"geometry": {
76+
"$ref": "#/definitions/Point"
77+
},
78+
"bbox": {
79+
"type": "array",
80+
"minItems": 4,
81+
"items": {
82+
"type": "number"
83+
}
84+
}
85+
}
86+
},
87+
"propulsion_type": {
88+
"$id": "#/definitions/propulsion_type",
89+
"type": "array",
90+
"description": "The type of propulsion; allows multiple values",
91+
"items": {
92+
"type": "string",
93+
"enum": [
94+
"combustion",
95+
"electric",
96+
"electric_assist",
97+
"human"
98+
]
99+
},
100+
"minItems": 1
101+
},
102+
"string": {
103+
"$id": "#/definitions/string",
104+
"type": "string",
105+
"description": "A length-limited string type",
106+
"maxLength": 255,
107+
"default": "",
108+
"examples": [
109+
"ABC123"
110+
],
111+
"pattern": "^(.*)$"
112+
},
113+
"timestamp": {
114+
"$id": "#/definitions/timestamp",
115+
"title": "Integer milliseconds since Unix epoch",
116+
"type": "number",
117+
"multipleOf": 1.0,
118+
"minimum": 0
119+
},
120+
"uuid": {
121+
"$id": "#/definitions/uuid",
122+
"type": "string",
123+
"title": "A UUID used to uniquely identifty an object",
124+
"default": "",
125+
"examples": [
126+
"3c9604d6-b5ee-11e8-96f8-529269fb1459"
127+
],
128+
"pattern": "^([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$"
129+
},
130+
"vehicle_type": {
131+
"$id": "#/definitions/vehicle_type",
132+
"type": "string",
133+
"description": "The type of vehicle",
134+
"enum": [
135+
"bicycle",
136+
"car",
137+
"scooter",
138+
"moped"
139+
]
140+
},
141+
"version": {
142+
"$id": "#/definitions/version",
143+
"type": "string",
144+
"title": "The MDS Provider version this data represents",
145+
"examples": [
146+
"0.4.0"
147+
],
148+
"pattern": "^0\\.4\\.[0-9]+$"
149+
},
7150
"links": {
8151
"$id": "#/definitions/links",
9152
"type": "object",
@@ -65,18 +208,14 @@
65208
}
66209
},
67210
"required": [
68-
"version",
69-
"data"
211+
"data",
212+
"version"
70213
],
71214
"properties": {
72-
"version": {
73-
"$id": "#/properties/version",
74-
"$ref": "#/definitions/version"
75-
},
76215
"data": {
77216
"$id": "#/properties/data",
78217
"type": "object",
79-
"title": "The page of data",
218+
"description": "The data records in this payload",
80219
"required": [
81220
"status_changes"
82221
],
@@ -89,6 +228,7 @@
89228
"$id": "#/properties/data/properties/status_changes/items",
90229
"type": "object",
91230
"title": "The status_change item schema",
231+
"additionalProperties": false,
92232
"required": [
93233
"provider_name",
94234
"provider_id",
@@ -103,64 +243,57 @@
103243
],
104244
"properties": {
105245
"provider_name": {
106-
"$id": "#/properties/data/properties/status_changes/items/properties/provider_name",
107-
"type": "string",
108-
"description": "The public-facing name of the Provider",
109-
"examples": [
110-
"Provider Name"
111-
],
112-
"pattern": "^(.*)$"
246+
"$id": "#/definitions/vehicle/properties/provider_name",
247+
"$ref": "#/definitions/string",
248+
"description": "The public-facing name of the Provider"
113249
},
114250
"provider_id": {
115-
"$id": "#/properties/data/properties/status_changes/items/properties/provider_id",
116-
"description": "The UUID for the Provider, unique within MDS",
117-
"$ref": "#/definitions/uuid"
251+
"$id": "#/definitions/vehicle/properties/provider_id",
252+
"$ref": "#/definitions/uuid",
253+
"description": "The UUID for the Provider, unique within MDS"
118254
},
119255
"device_id": {
120-
"$id": "#/properties/data/properties/status_changes/items/properties/device_id",
121-
"description": "A unique device ID in UUID format",
122-
"$ref": "#/definitions/uuid"
256+
"$id": "#/definitions/vehicle/properties/device_id",
257+
"$ref": "#/definitions/uuid",
258+
"description": "A unique device ID in UUID format"
123259
},
124260
"vehicle_id": {
125-
"$id": "#/properties/data/properties/status_changes/items/properties/vehicle_id",
126-
"type": "string",
127-
"description": "The Vehicle Identification Number visible on the vehicle itself",
128-
"default": "",
129-
"examples": [
130-
"ABC123"
131-
],
132-
"pattern": "^(.*)$"
261+
"$id": "#/definitions/vehicle/properties/vehicle_id",
262+
"$ref": "#/definitions/string",
263+
"description": "The Vehicle Identification Number visible on the vehicle itself"
133264
},
134265
"vehicle_type": {
135-
"$id": "#/properties/data/properties/status_changes/items/properties/vehicle_type",
266+
"$id": "#/definitions/vehicle/properties/vehicle_type",
136267
"$ref": "#/definitions/vehicle_type",
137268
"description": "The type of vehicle"
138269
},
139270
"propulsion_type": {
140-
"$id": "#/properties/data/properties/status_changes/items/properties/propulsion_type",
141-
"description": "The type of propulsion; allows multiple values",
142-
"$ref": "#/definitions/propulsion_type"
271+
"$id": "#/definitions/vehicle/properties/propulsion_type",
272+
"$ref": "#/definitions/propulsion_type",
273+
"description": "The type of propulsion; allows multiple values"
143274
},
144275
"event_time": {
145276
"$id": "#/properties/data/properties/status_changes/items/properties/event_time",
146-
"description": "The time the event occurred, expressed as a Unix Timestamp",
147-
"$ref": "#/definitions/timestamp"
277+
"$ref": "#/definitions/timestamp",
278+
"description": "The time the event occurred, expressed as a Unix Timestamp"
148279
},
149280
"publication_time": {
150281
"$id": "#/properties/data/properties/status_changes/items/properties/publication_time",
151-
"description": "The time the event became available through the status changes endpoint, expressed as a Unix Timestamp",
152-
"$ref": "#/definitions/timestamp"
282+
"$ref": "#/definitions/timestamp",
283+
"description": "The time the event became available through the status changes endpoint, expressed as a Unix Timestamp"
153284
},
154285
"event_location": {
155286
"$id": "#/properties/data/properties/status_changes/items/properties/event_location",
156-
"description": "The GPS or GNSS coordinates of where the event occurred",
157-
"$ref": "#/definitions/MDS_Feature_Point"
287+
"$ref": "#/definitions/MDS_Feature_Point",
288+
"description": "The GPS or GNSS coordinates of where the event occurred"
158289
},
159290
"event_type": {
291+
"$id": "#/properties/data/properties/status_changes/items/properties/event_type",
160292
"type": "string",
161293
"description": "The type of the event"
162294
},
163295
"event_type_reason": {
296+
"$id": "#/properties/data/properties/status_changes/items/properties/event_type_reason",
164297
"type": "string",
165298
"description": "The reason for the event"
166299
},
@@ -179,11 +312,12 @@
179312
},
180313
"associated_trip": {
181314
"$id": "#/properties/data/properties/status_changes/items/properties/associated_trip",
182-
"description": "Trip UUID, required if event_type_reason is user_pick_up or user_drop_off",
183-
"$ref": "#/definitions/uuid"
315+
"$ref": "#/definitions/uuid",
316+
"description": "Trip UUID, required if event_type is user_pick_up or user_drop_off"
184317
},
185318
"associated_ticket": {
186-
"type": "string",
319+
"$id": "#/properties/data/properties/status_changes/items/properties/associated_ticket",
320+
"$ref": "#/definitions/string",
187321
"description": "Identifier for an associated ticket inside an Agency-maintained 311 or CRM system."
188322
}
189323
},
@@ -285,6 +419,10 @@
285419
},
286420
"additionalProperties": false
287421
},
422+
"version": {
423+
"$id": "#/properties/version",
424+
"$ref": "#/definitions/version"
425+
},
288426
"links": {
289427
"$id": "#/properties/links",
290428
"$ref": "#/definitions/links"

0 commit comments

Comments
 (0)