Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update JSON Schemas for reconciled state machine #526

Closed
thekaveman opened this issue Jun 19, 2020 · 3 comments
Closed

Update JSON Schemas for reconciled state machine #526

thekaveman opened this issue Jun 19, 2020 · 3 comments
Assignees
Labels
Agency Specific to the Agency API Provider Specific to the Provider API Schema Implications for JSON Schema or OpenAPI State Machine Changes in the vehicle state events and state machine diagram
Milestone

Comments

@thekaveman
Copy link
Collaborator

After #506 is merged, we'll have a reconciled state machine between Agency and Provider. A follow-up task is to update the JSON Schemas with the new set of vehicle_state and event_type.

If possible, we'd also like to indicate which combinations of those values are considered valid under the state machine as is done now within the status_changes.json Schema. This could be difficult because the new model allows an array of event_type per vehicle_state, and intermediate states are "hidden" by the final valid event transition. See discussion on #271 for more details.

@thekaveman thekaveman added Provider Specific to the Provider API Agency Specific to the Agency API Schema Implications for JSON Schema or OpenAPI State Machine Changes in the vehicle state events and state machine diagram labels Jun 19, 2020
@thekaveman thekaveman added this to the 1.0.0 milestone Jun 19, 2020
@thekaveman thekaveman self-assigned this Jun 19, 2020
@thekaveman
Copy link
Collaborator Author

As expected, indicating the valid vehicle_state and vehicle_events combinations proved to be a challenge.

In conversation with @karcass, we originally thought that the last entry in the vehicle_events array should be a valid event transition for the indicated vehicle_state, e.g.

{
    "vehicle_state": "non_operational",
    "event_types": ["trip_end", "battery_low"]
}

Here, the battery_low event is a valid transition into the non_operational state (while trip_end is not), and so it comes last in the array.

However, JSON Schema does not support the notion of checking the "last item in an array" - support is for checking a fixed number of items, or all items.

The solution I landed on was to simply check that the event_types array contains a valid event for the given vehicle_state. Thus, both the above example and the following would validate against the JSON Schema:

{
    "vehicle_state": "non_operational",
    "event_types": ["battery_low", "trip_end"]
}

I think this is an OK trade-off in that we'll ensure that each vehicle_state has a correspondingly valid event_type, but we do lose the inherent "ordering" of the event_types array, from the perspective of the JSON Schemas anyway.

@schnuerle
Copy link
Member

Thanks @thekaveman that looks like the best solution.

@thekaveman
Copy link
Collaborator Author

I just realized another approach: reverse the order, and have the first array item be the event_type that transitioned to the vehicle_state... so the events are in descending time order instead of ascending. We can revisit if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Agency Specific to the Agency API Provider Specific to the Provider API Schema Implications for JSON Schema or OpenAPI State Machine Changes in the vehicle state events and state machine diagram
Projects
None yet
Development

No branches or pull requests

2 participants