bluesky / event-model

data model for event-based data collection and analysis
https://blueskyproject.io/event-model
BSD 3-Clause "New" or "Revised" License
15 stars 31 forks source link

Projection Schema could provide stronger validation #183

Closed dylanmcreynolds closed 4 years ago

dylanmcreynolds commented 4 years ago

Several parts of the projection schema a mutually exclusive. For example, you can either have type=computed or a type=linked. Currently, the schema allows for linked types with computed attributes. It would be nice if the schema provided stronger validation for this case. There might be additional opportunities for stronger validation.

danielballan commented 4 years ago

Related to an old issue, https://github.com/bluesky/event-model/issues/76. Validation could be stricter across the board by leveraging jsonschema to a fuller extent and further by enforcing anything that cannot be expressed in jsonschema in Python code in the document composition function.

thomascobb commented 4 years ago

We have been using https://pydantic-docs.helpmanual.io/ for this. You can express your json schema in terms of Python dataclass-style classes, which can be exported to a json schema, and add custom validators in Python for the more difficult cases that will be picked up when you instantiate the objects.

danielballan commented 4 years ago

Thanks, @thomascobb. That seems like a good direction to go in here.

dylanmcreynolds commented 4 years ago

We just started using pydantic in a web project (because of FastAPI). So far I'm a fan, and have been considering embedding it deeper into the framework than just the REST layer. It is certainly much easier to read than jsonschema, at least for easy cases.