openactive / models-php

PHP Models for the OpenActive Opportunity and Booking Specifications
MIT License
6 stars 8 forks source link

Validator: A ScheduledSession must be a subEvent of another Event. #96

Open drinkynet opened 2 years ago

drinkynet commented 2 years ago

Might be worth the library throwing a RuntimeException here so that the error can be picked up in development before using the validator.

nathansalter commented 2 years ago

When would you throw the error? The event not having a parent event set is only really an error during serialization, but we don't have enough context in the serializer there to determine easily if the session property is set.

drinkynet commented 2 years ago

It would make sense to do it during serialisation as that is the exact point it should all be valid. Otherwise you'd be wrongly throwing exceptions while building up the model.

I suppose you'd need some pre-serialisation validation method/rule on the model that the serialiser could be aware of to call. But I guess we're into quite a bit of complexity for a little bit of convenience here, and maybe catching it in the validator is fine :)