From 697119ef3214eac4ddac62a83d6265ca155231b5 Mon Sep 17 00:00:00 2001 From: Kinflou Date: Mon, 2 Nov 2026 20:12:59 +0000 Subject: [PATCH] doc model: an array carries its maximum (core#98 step 6) `Type::Array` gains `max`, absent when there is none, so the model stays at version 1: a reader that ignores it sees the array without its limit. An array of `char` is a string. A depth limit already reaches the model as the `max_depth` annotation. --- core/src/doc.rs | 13 +++++++++---- schemas/doc-model.json | 10 +++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/core/src/doc.rs b/core/src/doc.rs index 736158b..5e7ec26 100644 --- a/core/src/doc.rs +++ b/core/src/doc.rs @@ -280,10 +280,14 @@ pub enum Type { name: String, target: Option, }, - /// `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, length: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + max: Option, }, /// `union(A B ...)`. Union { members: Vec }, @@ -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(), @@ -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)); diff --git a/schemas/doc-model.json b/schemas/doc-model.json index 1975eb7..78c2c37 100644 --- a/schemas/doc-model.json +++ b/schemas/doc-model.json @@ -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" @@ -1744,6 +1744,14 @@ "integer", "null" ] + }, + "max": { + "format": "uint64", + "minimum": 0, + "type": [ + "integer", + "null" + ] } }, "required": [