spec: primitive-type-checker: Support string limit checking.
authorRicardo Wurmus <rekado@elephly.net>
Sun, 7 Mar 2021 07:40:24 +0000 (08:40 +0100)
committerRicardo Wurmus <rekado@elephly.net>
Sun, 7 Mar 2021 07:40:24 +0000 (08:40 +0100)
language/aws/spec.scm

index 836e4c65cae78f8c008c02e11291a54c43917453..2b63606eb6363090606d4c5a9b3ce53dec827a49 100644 (file)
@@ -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?)