-
-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Concerto should allow $class to be omitted or abbreviated when it's obvious from context #542
Comments
I've implemented an initial solution in #577. The changes to the spec above are:
|
Summary of discussion on Working Group call, 12 December 2022. The solution as implemented in #577 causes the model manager context to affect the validity of an instance. For example: Suppose a model M.cto: namespace M
concept C {
o String x
} The instance would validate against this model (given a root type of { "x": "X" } Now suppose that an additional model is added to the model manager: namespace N
import M.C
concept D extends C {} When attempting to validate the original instance with both models loaded, there is no single concrete subtype to choose. This proves that adding a Concept (even in a separate namespace) can be a breaking change with respect to validation and deserialization. This is not something that we should support. We propose to defer this feature until we also support |
Why not just treat objects as instances of the declared field type if $class is omitted? It's much simpler than a Your example doesn't match my understanding, since I believe a $class is still required on a top-level instance, but I understand what you mean at least. But given two namespaces similar to yours...
... then this instance is unambiguous:
In this case,
|
This is related to #482 and should be tackled in the context of |
I'm not sure what you mean about |
In short, "strict-mode" means that versioning is mandatory. This removes ambiguity which makes this kind of type inference easier. Strict-mode will become the default in a future release. |
This looks like a good candidate for #706. One other observation is that when we omit We should also specify whether $class is permitted but optional everywhere except root (e.g. for backwards compatibility). |
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 10 days. |
The need to provide a full $class declaration on every subobject in an object tree adds a lot of redundant information to a serialized Concerto object. In nearly all cases it could be removed or abbreviated without loss of information. This has a few benefits:
Feature Request
The $class property should not be required where it can be inferred from context, and an abbreviated form of the $class property should be allowed when it can be mostly inferred from context. The only times a full $class property is really needed are 1) on the top-level object, and 2) when referencing a type from another namespace or version. Otherwise, the $class property could usually be omitted entirely, even in some polymorphic cases. In the polymorphic cases where a $class property is needed, it's rare to need a full $class; usually the type name only would suffice, without the namespace and version, which can be inferred from the containing object.
If there is only one $class attribute, at the top level, it can easily be altered to change the version. If there's a $class attribute on every subobject, the user would need to recursively update all of them. Done programmatically, this requires significantly more complicated logic, and if they aren't so careful to update all the $class attributes, then they can easily get objects where some field values have version X and other field values have version Y. The object could no longer be said to come from a single model version, but would be a mix of multiple model versions. Perhaps in rare cases that might be desirable, but it should be something that's hard to do by accident.
I'll note that this request is about deserializing and validating objects. It would also be nice if Concerto would produce a more compact serialized format as well, but that is outside the scope of this request. (#482 is somewhat related, describing a "final" feature to allow Concerto to omit $class in one specific case. I notice that the title of that issue was changed earlier today to something broader, but the body is still about the "final" feature.)
Possible Solution
I'll note that this is backwards-compatible with the existing, more verbose specification that requires a full $class property on every sub-object.
The text was updated successfully, but these errors were encountered: