Comments (7)
I've implemented an initial solution in #577.
The changes to the spec above are:
- Extension: I allow for basic polymorphism where there is a single concrete subtype. This allows us to handle some uses of abstract concepts.
- Omission: I haven't implemented an abbreviated form of the $class discriminator. I'd like to consider this separately in the context of #480.
from concerto.
Summary of discussion on Working Group call, 12 December 2022.
https://vimeo.com/783301280
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 M.C
).
{ "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 final
annotations. This would allow us to unambiguously infer the types for only those with a final
annotation. #482.
from concerto.
Why not just treat objects as instances of the declared field type if $class is omitted? It's much simpler than a final
annotation and more general.
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...
namespace M
concept Top {
o B o
}
concept B {
o String s
}
namespace N
import M.*
concept D extends B { }
... then this instance is unambiguous:
{ "$class": "M.Top", "o": { "s": "string" } }
In this case, o
must be an instance of M.B
, because the field is declared as being of type M.B
. It is not and cannot be N.D
. That would require a $class:
{ "$class": "M.Top", "o": { "$class": "N.D", "s": "string" } }
from concerto.
This is related to #482 and should be tackled in the context of strict: true
from concerto.
This is related to #482 and should be tackled in the context of
strict: true
I'm not sure what you mean about strict: true
, but if you're implying that $class should be allowed to be omitted only when strict
is false, I'd disagree. Strictness presumably means forcing adherence to the rules; I'm arguing for a changing of the rules (for everyone) to relax them in cases where it doesn't introduce any ambiguity. I don't know which rules get ignored when strict
is false, but I doubt I'd want to have to opt into that general leniency to get this feature.
from concerto.
I'm not sure what you mean about
strict: true
.
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.
from concerto.
This looks like a good candidate for #706.
One other observation is that when we omit $class
from non-root types we make it harder to copy/paste (or programatically move) JSON nodes around, because the root node is "special" and has different rules from the non-root nodes (which are contextualised by their root). This is not a problem per-se, but is something we should bear in mind. We may want to consider adding helper functions to contextualise / decontextualise nodes.
We should also specify whether $class is permitted but optional everywhere except root (e.g. for backwards compatibility).
from concerto.
Related Issues (20)
- Factory doesn't generate empty entities HOT 1
- Make serializer option `strictQualifiedDateTimes` default behaviour
- Extends support for enum declarations HOT 3
- LocalDateTime
- Update CTO grammar for Import Aliasing HOT 2
- Update CTO printer for Import Aliasing
- Optimizations for applying decorators on a model HOT 1
- Vocabularies don't support namespace-scoped decorators HOT 1
- Update runtime classes to understand import aliasing
- Serialization exception when declaring a default false boolean field
- Update concerto-core/serializer to understand aliased imports HOT 2
- Update concerto-core/introspector to understand aliased imports
- Update concerto-analysis rules to analyse aliased imports HOT 2
- Multiple occurence of imported type in importTypes statement
- Redefining an imported type is allowed HOT 1
- Update v4 concerto
- DCS with namespace target, don't apply decorators on top of the namespace. HOT 5
- Update docs about import aliasing usage
- Update concerto-analyser to generate import aliasing
- Document / Clarify naming rules for identifiers HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from concerto.