cityjson / specs

Specifications for CityJSON, a JSON-based encoding for 3D city models
https://cityjson.org
Creative Commons Zero v1.0 Universal
108 stars 25 forks source link

Define abstract classes for the city object types #33

Closed liberostelios closed 6 years ago

liberostelios commented 6 years ago

I propose this way for the definition of city object types. The idea is that we can introduce abstract types (denoted as _AbstractType) which define the basic properties of the objects and, then, there is a simple concrete type that include those properties and only adds the type property (e.g., see _AbstractBuilding and Building in 7b94613ba7cde9a99f9b546835ca2d13ca57158b).

There are certain benefits:

As a caveat, though, we can't use the additionalProperties: false option with this mechanism (see why here), therefore we cannot force objects to only have the properties of the schema. There is a workaround, by listing again all "inherited" properties in the last class (explained at the end of this answer). Nevertheless, I believe it's better to just warn users about this through cjio validation, than really forcing them to follow the schema. After all, the whole point of JSON is to be more flexible.