Skip to content

Commit

Permalink
Use type and properties objects for arrays, tweak required field synt…
Browse files Browse the repository at this point in the history
…ax (#37)

Many arrays defined in GBFS schemas define item properties directly in
the containing object. In this commit, we provide a schema for
these array items to be validated against. Because in most cases array
items are objects, this amounted to adding "type": "object" and moving
the properties that were defined under a "properties" key.

Additionally, in some cases, array properties would be marked required
by setting "required": "true" below the "items" property. We also now
use the more common syntax of requiring fields by setting "required" to
a list of strings.
  • Loading branch information
grahamalama authored Mar 30, 2021
1 parent 0e3651f commit b177066
Show file tree
Hide file tree
Showing 10 changed files with 680 additions and 628 deletions.
147 changes: 75 additions & 72 deletions free_bike_status.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,73 +31,76 @@
"bikes": {
"type": "array",
"items": {
"bike_id": {
"description": "Rotating (as of v2.0) identifier of a vehicle.",
"type": "string"
},
"lat": {
"description": "The latitude of the vehicle.",
"type": "number",
"minimum": -90,
"maximum": 90
},
"lon": {
"description": "The longitude of the vehicle.",
"type": "number",
"minimum": -180,
"maximum": 180
},
"is_reserved": {
"description": "Is the vehicle currently reserved?",
"type": "boolean"
},
"is_disabled": {
"description": "Is the vehicle currently disabled (broken)?",
"type": "boolean"
},
"rental_uris": {
"description": "Contains rental uris for Android, iOS, and web in the android, ios, and web fields (added in v1.1).",
"type": "object",
"properties": {
"android": {
"description": "URI that can be passed to an Android app with an intent (added in v1.1).",
"type": "string",
"format": "uri"
},
"ios": {
"description": "URI that can be used on iOS to launch the rental app for this vehicle (added in v1.1).",
"type": "string",
"format": "uri"
},
"web": {
"description": "URL that can be used by a web browser to show more information about renting this vehicle (added in v1.1).",
"type": "string",
"format": "uri"
"type":"object",
"properties": {
"bike_id": {
"description": "Rotating (as of v2.0) identifier of a vehicle.",
"type": "string"
},
"lat": {
"description": "The latitude of the vehicle.",
"type": "number",
"minimum": -90,
"maximum": 90
},
"lon": {
"description": "The longitude of the vehicle.",
"type": "number",
"minimum": -180,
"maximum": 180
},
"is_reserved": {
"description": "Is the vehicle currently reserved?",
"type": "boolean"
},
"is_disabled": {
"description": "Is the vehicle currently disabled (broken)?",
"type": "boolean"
},
"rental_uris": {
"description": "Contains rental uris for Android, iOS, and web in the android, ios, and web fields (added in v1.1).",
"type": "object",
"properties": {
"android": {
"description": "URI that can be passed to an Android app with an intent (added in v1.1).",
"type": "string",
"format": "uri"
},
"ios": {
"description": "URI that can be used on iOS to launch the rental app for this vehicle (added in v1.1).",
"type": "string",
"format": "uri"
},
"web": {
"description": "URL that can be used by a web browser to show more information about renting this vehicle (added in v1.1).",
"type": "string",
"format": "uri"
}
}
},
"vehicle_type_id": {
"description": "The vehicle_type_id of this vehicle (added in v2.1-RC).",
"type": "string"
},
"last_reported": {
"description": "The last time this vehicle reported its status to the operator's backend in POSIX time (added in v2.1-RC).",
"type": "number",
"minimum": 1450155600
},
"current_range_meters": {
"description": "The furthest distance in meters that the vehicle can travel without recharging or refueling with the vehicle's current charge or fuel (added in v2.1-RC).",
"type": "number",
"minimum": 0
},
"station_id": {
"description": "Identifier referencing the station_id if the vehicle is currently at a station (added in v2.1-RC2).",
"type": "string"
},
"pricing_plan_id": {
"description": "The plan_id of the pricing plan this vehicle is eligible for (added in v2.1-RC2).",
"type": "string"
}
},
"vehicle_type_id": {
"description": "The vehicle_type_id of this vehicle (added in v2.1-RC).",
"type": "string"
},
"last_reported": {
"description": "The last time this vehicle reported its status to the operator's backend in POSIX time (added in v2.1-RC).",
"type": "number",
"minimum": 1450155600
},
"current_range_meters": {
"description": "The furthest distance in meters that the vehicle can travel without recharging or refueling with the vehicle's current charge or fuel (added in v2.1-RC).",
"type": "number",
"minimum": 0
},
"station_id": {
"description": "Identifier referencing the station_id if the vehicle is currently at a station (added in v2.1-RC2).",
"type": "string"
},
"pricing_plan_id": {
"description": "The plan_id of the pricing plan this vehicle is eligible for (added in v2.1-RC2).",
"type": "string"
},
"required": [
"bike_id",
"is_reserved",
Expand All @@ -108,13 +111,13 @@
"bikes"
]
}
},
"required": [
"last_updated",
"ttl",
"version",
"data"
]
}
}
}
},
"required": [
"last_updated",
"ttl",
"version",
"data"
]
}
8 changes: 5 additions & 3 deletions gbfs_versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@
"url"
]
}
},
"required": true
}
},
"required": [
"versions"
],
"additionalProperties": false
}
},
Expand All @@ -75,4 +77,4 @@
"version",
"data"
]
}
}
Loading

0 comments on commit b177066

Please sign in to comment.