Closed arnauddrain closed 1 month ago
Thank you for your answer @bcherny !
extends
will indeed generate the correct typescript classes, but then the validation will be incorrect, because the properties of the "parent" objets won't be required anymore and {"numDoors": 2}
will become a valid input: https://jsonschema.dev/s/TdKME
@arnauddrain extends
is an old keyword that has been removed in modern JSON Schema versions. The website you linked doesn't seem to implement it correctly. If your validator supports it, extends
will work fine the way I suggested.
See the spec: https://github.com/json-schema/json-schema/wiki/Extends/014e3cd8692250baad70c361dd81f6119ad0f696
Fix included in v15.0.0.
I'm trying to reproduce an inheritance schema like this:
Using the "allOf" keyword with a schema like this:
The output looks like this:
Here,
Truck
is directly inheritingThing
instead ofVehicle
, so its TypeScript definition does not includes theyear
property. If I exchange the properties of the rootoneOf
, then the the issue appears in the type definition ofCar
.