Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions core/src/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,14 @@ pub enum Type {
name: String,
target: Option<UnitRef>,
},
/// `T[]` (`length: None`) or `T[N]`.
/// `T[]`, `T[N]` (`length`) or `T[max N]` (`max`), at most one of the
/// two. An array of `char` is a string: `char[max 64]` holds at most 64
/// characters. `max` is absent when there is none.
Array {
element: Box<Type>,
length: Option<u64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
max: Option<u64>,
},
/// `union(A B ...)`.
Union { members: Vec<Type> },
Expand Down Expand Up @@ -909,10 +913,10 @@ impl Scope<'_> {
name: name.clone(),
target: self.resolve(name),
},
// The doc model carries bounds in rollout step 6 (core#98).
TypeRef::Array { element, length, .. } => Type::Array {
TypeRef::Array { element, length, max } => Type::Array {
element: Box::new(self.ty(element)),
length: *length,
max: *max,
},
TypeRef::Union(members) => Type::Union {
members: members.iter().map(|m| self.ty(m)).collect(),
Expand Down Expand Up @@ -1325,7 +1329,8 @@ mod tests {
fields[1].ty,
Type::Array {
element: Box::new(named("Payment", "types")),
length: None
length: None,
max: Some(1024)
}
);
assert!(matches!(&fields[2].ty, Type::Union { members } if members.len() == 2));
Expand Down
10 changes: 9 additions & 1 deletion schemas/doc-model.json
Original file line number Diff line number Diff line change
Expand Up @@ -1728,7 +1728,7 @@
"type": "object"
},
{
"description": "`T[]` (`length: None`) or `T[N]`.",
"description": "`T[]`, `T[N]` (`length`) or `T[max N]` (`max`), at most one of the\ntwo. An array of `char` is a string: `char[max 64]` holds at most 64\ncharacters. `max` is absent when there is none.",
"properties": {
"element": {
"$ref": "#/definitions/Type"
Expand All @@ -1744,6 +1744,14 @@
"integer",
"null"
]
},
"max": {
"format": "uint64",
"minimum": 0,
"type": [
"integer",
"null"
]
}
},
"required": [
Expand Down
Loading