From 04332e70eb9a497014002b4c668768638c8c2865 Mon Sep 17 00:00:00 2001 From: Ricardo Wurmus Date: Sun, 7 Mar 2021 08:40:24 +0100 Subject: spec: primitive-type-checker: Support string limit checking. --- language/aws/spec.scm | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'language/aws/spec.scm') 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?) -- cgit v1.2.3