urbanobservatory / standards

Standards and schema documentation for the observatories programme
2 stars 0 forks source link

Introduction of schemas and a TDD approach #16

Open lukeshope opened 4 years ago

lukeshope commented 4 years ago

Introduction of schemas and a TDD approach

Following up on the discussions in #13, I obviously needed to do some more work to convince people my grand plan was a sensible one. This PR and the changes in the schema branch are a work in progress intended to do that.

I have made a start on some code, and some tools, and some examples. There is still much more to do, but I wanted to put this down so people can start asking questions.

What are the problems?

How do we enforce these restrictions? Using JSON Schema. It allows these constraints to be expressed, where restrictions on type (for above example, not an array), requirements, regular expressions, etc. can all be described.

See this example of a schema for a SensorCollection that requires all of the members to be Sensor.

JSON Schema allows us to validate an instance of a sensor, platform, observation etc. at run-time, using packages such as ajv. Better yet though, we can generate TypeScript interfaces from the JSON Schema documents.

See this example of a TypeScript interface generated from this schema, using this code. See this example of some automated tests on the SensorCollection (not complete, more tests to be added).

JSON Hyper-Schema will describe these. It allows constraints to be imposed just as it does on documents, for example you can only use a __gt filter on a value that is numeric.

We should write the JSON Schema and JSON Hyper-Schema documents, then generate the documentation automatically using the contents of these files. It should be possible to generate an OpenAPI document from an API that references these documents, and if we have an OpenAPI document, we can use tools like spectacle to generate HTML documentation like this.

The key concepts

The technologies we use are:

Next steps

I am going to trawl through the SSN/SOSA ontology and pull out all of the restrictions it imposes (that are relevant to us), and write stub tests for them. I will then write an example instance of:

What else do we need?

SiBell commented 4 years ago

Luke, this all looks great.

I'm also using deployment and featureOfInterest, but I'm sure once we see some examples for the other classes it'll be easy to figure out the equivalent for others such as these.