-
Notifications
You must be signed in to change notification settings - Fork 7
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
Generic Array Datatype #127
Comments
I always felt like this was bound to come up at some point. I think you're right, we probably need an Array datatype. I think that if a Property has the |
This brings up an interesting modeling problem. How do you express "array of integers" in the schema? This is actually the more general problem of "how to refine types". I see several solutions, all of them with downsides. Additional Properties on Property ResourcesA property of type The big downside here is that it would not be apparent from the schema that this property is expected or required as a refinement of the array datatype, so that makes the schema more cryptic and implementations more complicated. It's also more complex to "unify" and compare schema types, since libraries now need to understand that the Custom DatatypesHave something like a Properties can then specify their type (usually with a nested resource, probably) as an The downside here is that libraries now have to understand what an Express Types With a Core Type SystemIn my I don't allow defining arbitrary datatypes. A simplified definition of the core types in Rust looks a bit like this: pub enum ValueType {
Const(Value),
Any,
Unit,
Bool,
Int {
min: Option<i64>,
max: Option<i64>,
},
UInt {
min: Option<u64>,
max: Option<u64>,
},
Float {
min: Option<f64>,
max: Option<f64>,
},
String {
min_length: Option<u64>,
max_length: Option<u64>,
regex_validators: Option<Vec<String>>,
},
Bytes {
min_length: Option<u64>,
max_length: Option<u64>,
},
// Containers.
List {
item_type: Box<Self>,
min_length: Option<u64>,
max_length: Option<u64>,
},
/// A mapping from keys to values
Map {
key_type: Box<Self>,
value_type: Box<Self>,
},
///
Object(ObjectType),
/// An anonymous union of different types.
Union(Vec<Self>),
/// Tagged union (aka sum type / ADT)
Variant(VariantType),
/// Reference (aka foreign key) pointing to another entity
Reference {
/// Restrict the allowed entity types.
allowed_types: Option<HashSet<Ident>>,
},
/// A custom data type.
Named(Ident),
} Properties can either specify a concrete The main advantage here is that clients will always be able to understand and work with all data. More complex types can always be expressed in terms of this core schema, and worst case they can just use a (including things like |
There currently only is a
resource-array
datatype, which requires using nested resources if there are multiple values.Often I would want to have a property with multiple plain values though.
Reasons:
Image you want an array of ints or strings.
So there should be a datatype for "array of type T".
Defining the nested type would run into similar issues as #126 though.
The text was updated successfully, but these errors were encountered: