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

Consider using JSON Schema #46

Closed
ian-r-rose opened this issue Sep 11, 2018 · 6 comments
Closed

Consider using JSON Schema #46

ian-r-rose opened this issue Sep 11, 2018 · 6 comments
Milestone

Comments

@ian-r-rose
Copy link
Contributor

The mobility spec already provides some nice narrative description of the inputs and outputs for the REST API. However, there is still some room for ambiguity, and it would be useful to be able to test providers/agencies against regressions and compliance with the spec.

One commonly-used approach to this problem is to use a JSON schema. This allows you to describe JSON data structures in a well-typed fashion. This allows for

  • validation
  • regression testing
  • a source of truth for the spec to guard against different interpretations of the narrative.
  • Easier tracking of spec versions

For instance, a schema for the response body of the /deregister-vehicle might look something like:

{
  "properties": {
    "unique_id": {
      "type": "string"
    },
    "device_id": {
      "type": "string"
    },
    "reason_code": {
      "type": "string",
      "enum": ["rebalancing", "maintenance"]
    }
  },
  "type": "object",
  "additionalProperties": false
}

High-quality JSON-schema validators should exist in most web-friendly languages.

@thekaveman
Copy link
Collaborator

I think this is a great idea.

I will start putting together a PR for provider using JSON-schema so we can explore this idea further.

@hunterowens
Copy link
Collaborator

Agreed. We call out using JSON API (which includes JSON Schema) in the provider spec currently but the implementation is not there yet.

For Agency I believe we should enforce as well. @toddapetersen

@thekaveman
Copy link
Collaborator

I started putting something together over here: https://github.com/CityofSantaMonica/mobility-data-specification/blob/json-schema/provider/schema.json

Take a look at let me know if this seems like the right direction. I generated this using some sample data I cooked up and the tool at https://www.jsonschema.net/

@ian-r-rose
Copy link
Contributor Author

@thekaveman that's awesome. Can you open a PR to allow for commenting?

@hunterowens
Copy link
Collaborator

This would be a breaking change, tagging as a 0.2.0 milestone.

@hunterowens
Copy link
Collaborator

#53 is merged. closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants