Currently extends is used for models inheritance in Plank schema.
Pros:
- Support of inheritance in schema just makes it easier.
Cons:
-
It is really "allOf" other than having a base class.
-
In the generated models, for common methods, it may confuses the complier. I.e,
`Class A :
- aStandardMethodWith:(ClassA)obj
Class B : ClassA
- aStandardMethodWith:(ClassB)obj
`
This pattern is either explicitly not allowed or behaving unexpectedly in most programing languages.
-
Its not a standard keyword thus most existing JSON schema validators don't support that, or we have to make/use Plank's own validator tools on both provider-consumer sides.
-
It may encourages 'polymorphicTypeIdentifier' or similar kind of field in the schema to tell real type of model.
AFAIK, Inheritance isn't supported in most popular model-gen(GraphQL, protoBuf, and etc) tools. I guess the main reasons is that IDL is more for defining constraints on model, not primarily on OOP.
Possible solutions:
-
support allOf then deprecate extends
This shouldn't lose any property or method from the base class but base class itself.
-
A new build option to treat extends as allOf
For existing extends users, they may assume base class of the models, this is a breaking change in that case. A possible workaround is to specify a base class in the build option mentioned above? And users of "extend" would take care of the base class and its compliance in their code base.
I created this issue to capture what @jparise and me discussed a while go.
Your thoughts are appreciated.
Currently extends is used for models inheritance in Plank schema.
Pros:
Cons:
It is really "allOf" other than having a base class.
In the generated models, for common methods, it may confuses the complier. I.e,
`Class A :
Class B : ClassA
`
This pattern is either explicitly not allowed or behaving unexpectedly in most programing languages.
Its not a standard keyword thus most existing JSON schema validators don't support that, or we have to make/use Plank's own validator tools on both provider-consumer sides.
It may encourages 'polymorphicTypeIdentifier' or similar kind of field in the schema to tell real type of model.
AFAIK, Inheritance isn't supported in most popular model-gen(GraphQL, protoBuf, and etc) tools. I guess the main reasons is that IDL is more for defining constraints on model, not primarily on OOP.
Possible solutions:
support allOf then deprecate extends
This shouldn't lose any property or method from the base class but base class itself.
A new build option to treat extends as allOf
For existing extends users, they may assume base class of the models, this is a breaking change in that case. A possible workaround is to specify a base class in the build option mentioned above? And users of "extend" would take care of the base class and its compliance in their code base.
I created this issue to capture what @jparise and me discussed a while go.
Your thoughts are appreciated.