Skip to content

Commit 06013b9

Browse files
authored
Merge pull request #576 from thekaveman/policy-schema
Policy JSON Schema
2 parents 2e035b8 + a09d3be commit 06013b9

29 files changed

Lines changed: 1989 additions & 379 deletions

agency/get_stops.json

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,8 @@
111111
},
112112
"devices": {
113113
"$id": "#/definitions/stop/properties/devices",
114-
"type": "array",
115-
"description": "List of device_id for vehicles currently at this Stop.",
116-
"items": {
117-
"$ref": "#/definitions/uuid"
118-
}
114+
"$ref": "#/definitions/uuid_array",
115+
"description": "List of device_id for vehicles currently at this Stop."
119116
}
120117
}
121118
},
@@ -171,6 +168,15 @@
171168
],
172169
"pattern": "^([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$"
173170
},
171+
"uuid_array": {
172+
"$id": "#/definitions/uuid_array",
173+
"type": "array",
174+
"description": "Array of UUID",
175+
"items": {
176+
"$id": "#/definitions/uuid_array/items",
177+
"$ref": "#/definitions/uuid"
178+
}
179+
},
174180
"vehicle_type_counts": {
175181
"$id": "#/definitions/vehicle_type_counts",
176182
"type": "object",

agency/get_vehicle.json

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,12 @@
77
"propulsion_types": {
88
"$id": "#/definitions/propulsion_types",
99
"type": "array",
10-
"description": "The type of propulsion; allows multiple values",
10+
"description": "Array of propulsion types, allowing multiple values",
1111
"items": {
12-
"type": "string",
13-
"enum": [
14-
"combustion",
15-
"electric",
16-
"electric_assist",
17-
"human"
18-
]
12+
"$id": "#/definitions/propulsion_types/items",
13+
"$ref": "#/definitions/propulsion_type"
1914
},
20-
"uniqueItems": true,
21-
"minItems": 1
15+
"uniqueItems": true
2216
},
2317
"string": {
2418
"$id": "#/definitions/string",
@@ -31,6 +25,13 @@
3125
],
3226
"pattern": "^(.*)$"
3327
},
28+
"timestamp": {
29+
"$id": "#/definitions/timestamp",
30+
"type": "number",
31+
"description": "Integer milliseconds since Unix epoch",
32+
"multipleOf": 1.0,
33+
"minimum": 0
34+
},
3435
"vehicle_type": {
3536
"$id": "#/definitions/vehicle_type",
3637
"type": "string",
@@ -43,13 +44,6 @@
4344
"other"
4445
]
4546
},
46-
"timestamp": {
47-
"$id": "#/definitions/timestamp",
48-
"type": "number",
49-
"description": "Integer milliseconds since Unix epoch",
50-
"multipleOf": 1.0,
51-
"minimum": 0
52-
},
5347
"uuid": {
5448
"$id": "#/definitions/uuid",
5549
"type": "string",
@@ -155,7 +149,8 @@
155149
"propulsion_types": {
156150
"$id": "#/definitions/vehicle/properties/propulsion_types",
157151
"$ref": "#/definitions/propulsion_types",
158-
"description": "The type of propulsion; allows multiple values"
152+
"description": "The type of propulsion; allows multiple values",
153+
"minItems": 1
159154
},
160155
"year": {
161156
"$id": "#/properties/year",

agency/post_stops.json

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,8 @@
111111
},
112112
"devices": {
113113
"$id": "#/definitions/stop/properties/devices",
114-
"type": "array",
115-
"description": "List of device_id for vehicles currently at this Stop.",
116-
"items": {
117-
"$ref": "#/definitions/uuid"
118-
}
114+
"$ref": "#/definitions/uuid_array",
115+
"description": "List of device_id for vehicles currently at this Stop."
119116
}
120117
}
121118
},
@@ -171,6 +168,15 @@
171168
],
172169
"pattern": "^([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$"
173170
},
171+
"uuid_array": {
172+
"$id": "#/definitions/uuid_array",
173+
"type": "array",
174+
"description": "Array of UUID",
175+
"items": {
176+
"$id": "#/definitions/uuid_array/items",
177+
"$ref": "#/definitions/uuid"
178+
}
179+
},
174180
"vehicle_type_counts": {
175181
"$id": "#/definitions/vehicle_type_counts",
176182
"type": "object",

agency/post_vehicle.json

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,12 @@
77
"propulsion_types": {
88
"$id": "#/definitions/propulsion_types",
99
"type": "array",
10-
"description": "The type of propulsion; allows multiple values",
10+
"description": "Array of propulsion types, allowing multiple values",
1111
"items": {
12-
"type": "string",
13-
"enum": [
14-
"combustion",
15-
"electric",
16-
"electric_assist",
17-
"human"
18-
]
12+
"$id": "#/definitions/propulsion_types/items",
13+
"$ref": "#/definitions/propulsion_type"
1914
},
20-
"uniqueItems": true,
21-
"minItems": 1
15+
"uniqueItems": true
2216
},
2317
"string": {
2418
"$id": "#/definitions/string",
@@ -79,7 +73,8 @@
7973
"propulsion_types": {
8074
"$id": "#/definitions/vehicle/properties/propulsion_types",
8175
"$ref": "#/definitions/propulsion_types",
82-
"description": "The type of propulsion; allows multiple values"
76+
"description": "The type of propulsion; allows multiple values",
77+
"minItems": 1
8378
},
8479
"year": {
8580
"$id": "#/properties/year",

policy/README.md

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Versioning must be implemented as specified in the [Versioning section][versioni
3939

4040
## Background
4141

42-
The goal of this specification is to enable Agencies to create, revise, and publish machine-readable policies, as sets of rules for individual and collective device behavior exhibited by both _mobility as a service_ Providers and riders / users. [Examples](examples.md) of policies include:
42+
The goal of this specification is to enable Agencies to create, revise, and publish machine-readable policies, as sets of rules for individual and collective device behavior exhibited by both _mobility as a service_ Providers and riders / users. [Examples](./examples/README.md) of policies include:
4343

4444
- City-wide and localized caps (e.g. "Minimum 500 and maximum 3000 scooters within city boundaries")
4545
- Exclusion zones (e.g. "No scooters are permitted in this district on weekends")
@@ -50,7 +50,7 @@ The goal of this specification is to enable Agencies to create, revise, and publ
5050

5151
The machine-readable format allows Providers to obtain policies and compute compliance where it can be determined entirely by data obtained internally.
5252

53-
**See the [Policy Examples](examples.md) for ways these can be implemented.**
53+
**See the [Policy Examples](./examples/README.md) for ways these can be implemented.**
5454

5555
[Top][toc]
5656

@@ -139,7 +139,7 @@ The `updated` field in the payload wrapper should be set to the time of publishi
139139

140140
#### Example `policies.json`
141141

142-
```json
142+
```jsonc
143143
{
144144
"version": "0.4.0",
145145
"updated": 1570035222868,
@@ -161,7 +161,7 @@ The optional `end_date` field applies to all policies represented in the file.
161161

162162
#### Example `geographies.json`
163163

164-
```json
164+
```jsonc
165165
{
166166
"version": "0.4.0",
167167
"updated": 1570035222868,
@@ -186,7 +186,7 @@ All response fields must use `lower_case_with_underscores`.
186186

187187
Response bodies must be a `UTF-8` encoded JSON object and must minimally include the MDS `version`, a timestamp indicating the last time the data was `updated`, and a `data` payload:
188188

189-
```json
189+
```jsonc
190190
{
191191
"version": "x.y.z",
192192
"updated": 1570035222868,
@@ -196,6 +196,12 @@ Response bodies must be a `UTF-8` encoded JSON object and must minimally include
196196
}
197197
```
198198

199+
### JSON Schema
200+
201+
The JSON Schema file is available in this repository: [`policy.json`](./policy.json).
202+
203+
Before publishing a new Policy document, the document should be validated against the schema to ensure it has the correct format and fields.
204+
199205
[Top][toc]
200206

201207
### Policy
@@ -208,7 +214,7 @@ An individual `Policy` object is defined by the following fields:
208214
| `policy_id` | UUID | Required | Unique ID of policy |
209215
| `provider_ids` | UUID[] | Optional | Providers for whom this policy is applicable; empty arrays and `null`/absent implies all Providers. See MDS [provider list](/providers.csv). |
210216
| `description` | String | Required | Description of policy |
211-
| `currency` | String | Optional | An ISO 4217 Alphabetic Currency Code representing the [currency](../provider#costs--currencies) of all Rules of [type](#rule-types) `rate`.|
217+
| `currency` | String | Optional | An ISO 4217 Alphabetic Currency Code representing the [currency](../general-information.md#costs-and-currencies) of all Rules of [type](#rule-types) `rate`.|
212218
| `start_date` | [timestamp][ts] | Required | Beginning date/time of policy enforcement |
213219
| `end_date` | [timestamp][ts] | Optional | End date/time of policy enforcement |
214220
| `published_date` | [timestamp][ts] | Required | Timestamp that the policy was published |
@@ -227,8 +233,8 @@ An individual `Rule` object is defined by the following fields:
227233
| `rule_id` | UUID | Required | Unique ID of the rule |
228234
| `rule_type` | enum | Required | Type of policy (see [Rule Types](#rule-types)) |
229235
| `geographies` | UUID[] | Required | List of Geography UUIDs (non-overlapping) specifying the covered geography |
230-
| `states` | `{ state: event[] }` | Required | [Vehicle state][vehicle-states] to which this rule applies. Optionally provide a list of specific [vehicle events][#vehicle-events] as a subset of a given status for the rule to apply to. An empty list or `null`/absent defaults to "all". |
231-
| `rule_units` | enum | Required | Measured units of policy (see [Rule Units](#rule-units)) |
236+
| `states` | `{ state: event[] }` | Required | [Vehicle state][vehicle-states] to which this rule applies. Optionally provide a list of specific [vehicle events][#vehicle-events] as a subset of a given status for the rule to apply to. An empty list or `null`/absent defaults to "all". |
237+
| `rule_units` | enum | Conditionally Required | Measured units of policy (see [Rule Units](#rule-units)) |
232238
| `vehicle_types` | `vehicle_type[]` | Optional | Applicable vehicle types, default "all". |
233239
| `propulsion_types` | `propulsion_type[]` | Optional | Applicable vehicle [propulsion types][propulsion-types], default "all". |
234240
| `minimum` | integer | Optional | Minimum value, if applicable (default 0) |
@@ -257,16 +263,18 @@ An individual `Rule` object is defined by the following fields:
257263

258264
### Rule Units
259265

260-
| Name | Rule Types | Description |
261-
| --------- | -------------- | ------------------- |
262-
| `seconds` | `time` | Seconds |
263-
| `minutes` | `time` | Minutes |
264-
| `hours` | `time` | Hours |
265-
| `days` | `time` | Days |
266-
| `mph` | `speed` | Miles per hour |
267-
| `kph` | `speed` | Kilometers per hour |
268-
| `devices` | `count` | Devices |
269-
| `amount` | `rate` | Cost (in [local currency](/general-information.md#costs-and-currencies)) |
266+
| Name | Rule Types | Description |
267+
| --------- | ---------------------- | ------------------- |
268+
| `seconds` | `rate`, `time` | Seconds |
269+
| `minutes` | `rate`, `time` | Minutes |
270+
| `hours` | `rate`, `time` | Hours |
271+
| `days` | `rate`, `time` | Days |
272+
| `amount` | `rate` | Cost (in [local currency](/general-information.md#costs-and-currencies)) |
273+
| `mph` | `speed` | Miles per hour |
274+
| `kph` | `speed` | Kilometers per hour |
275+
| `devices` | `count` | Devices |
276+
277+
[Rule type](#rule-types) `user` has no associated Rule units; `rule_units` is not required when the Rule type is `user`.
270278

271279
[Top][toc]
272280

@@ -290,9 +298,9 @@ Rate recurrences specify when a rate is applied – either once, or periodicall
290298

291299
| Name | Description |
292300
| --------- | ------------------- |
293-
| `once` | Rate is applied once to vehicles entering a matching status from a non-matching status. |
301+
| `once` | Rate is applied once to vehicles entering a matching status from a non-matching status. |
294302
| `each_time_unit` | During each `time_unit`, rate is applied once to vehicles entering or remaining in a matching status. Requires a `time_unit` to be specified using `rule_units`. |
295-
| `per_complete_time_unit` | Rate is applied once per complete `time_unit` that vehicles remain in a matching status. Requires a `time_unit` to be specified using `rule_units`. |
303+
| `per_complete_time_unit` | Rate is applied once per complete `time_unit` that vehicles remain in a matching status. Requires a `time_unit` to be specified using `rule_units`. |
296304

297305
[Top][toc]
298306

@@ -344,9 +352,11 @@ The internal mechanics of ordering are up to the Policy editing and hosting soft
344352
[Top][toc]
345353

346354
[beta]: /general-information.md#beta
355+
[error-messages]: /general-information.md#error-messages
347356
[iana]: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
348357
[muni-boundary]: ../provider/README.md#municipality-boundary
349358
[propulsion-types]: /general-information.md#propulsion-types
359+
[responses]: /general-information.md#responses
350360
[ts]: /general-information.md#timestamps
351361
[toc]: #table-of-contents
352362
[vehicle-events]: /general-information.md#vehicle-state-events

0 commit comments

Comments
 (0)