summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRicardo Wurmus <rekado@elephly.net>2021-03-07 08:40:24 +0100
committerRicardo Wurmus <rekado@elephly.net>2021-03-07 08:40:24 +0100
commit04332e70eb9a497014002b4c668768638c8c2865 (patch)
treec3dd402ca5a5149ec60824373189393d1880423a
parentb2eea94a72cf934764d8e17f9ee439b0a0d11cdf (diff)
spec: primitive-type-checker: Support string limit checking.
-rw-r--r--language/aws/spec.scm18
1 files changed, 13 insertions, 5 deletions
diff --git a/language/aws/spec.scm b/language/aws/spec.scm
index 836e4c6..2b63606 100644
--- a/language/aws/spec.scm
+++ b/language/aws/spec.scm
@@ -41,11 +41,19 @@ if this is not a primitive data type."
(match (assoc-ref exp "type")
("string"
(let ((enum (and=> (assoc-ref exp "enum")
- vector->list)))
- (if enum
- `(lambda (value)
- (member value ',enum))
- 'string?)))
+ vector->list))
+ (min (assoc-ref exp "min"))
+ (max (assoc-ref exp "max")))
+ `(lambda (value)
+ (and (string? value)
+ ,(if enum
+ `(member value ',enum)
+ #true)
+ ,(if (or min max)
+ `(let ((len (string-length value)))
+ (and ,(if min `(>= len ,min) #true)
+ ,(if max `(<= len ,max) #true)))
+ #true)))))
("blob" 'bytevector?)
("boolean" 'boolean?)
("timestamp" 'date?)