request: aws-value->scm: Support parent name stripping.
authorRicardo Wurmus <rekado@elephly.net>
Sun, 7 Mar 2021 07:38:52 +0000 (08:38 +0100)
committerRicardo Wurmus <rekado@elephly.net>
Sun, 7 Mar 2021 07:38:52 +0000 (08:38 +0100)
This is necessary to remove unnecessary nesting when serializing
wrappers around primitive types.

aws/request.scm

index 0f4956bfed7569760f725fa7dd2a4172309cc401..69d71bbd1559e6cd8f9e808873f2d37e4d02086f 100644 (file)
                           '()))
                "&"))
 
-(define (aws-value->scm thing)
+(define* (aws-value->scm thing #:optional strip-name?)
   "Transform the potentially nested AWS value THING into an alist,
 which can easily be converted to JSON."
   (cond
    ((aws-structure? thing)
-    `((,(format #false "~a" (aws-structure-aws-name thing))
-       .
-       ,(filter-map (lambda (member)
-                      (match (aws-member-value member)
-                        ('__unspecified__ #false)
-                        (value
-                         `(,(format #false "~a"
-                                     (or (aws-member-location-name member)
-                                         (aws-member-name member)))
-                           .
-                           ,(aws-value->scm value)))))
-                    (aws-structure-members thing)))))
+    (let ((members
+           (filter-map (lambda (member)
+                         (match (aws-member-value member)
+                           ('__unspecified__ #false)
+                           (value
+                            `(,(format #false "~a"
+                                       (or (aws-member-location-name member)
+                                           (aws-member-name member)))
+                              .
+                              ,(aws-value->scm value)))))
+                       (aws-structure-members thing))))
+      (if strip-name?
+          members
+          `((,(format #false "~a" (aws-structure-aws-name thing))
+             . ,members)))))
    ((aws-shape? thing)
     (match (aws-shape-value thing)
       ((? list? l)
        (list->vector (map aws-value->scm l)))
-      (x x)))))
+      (x x)))
+   ;; TODO: what about the primitive "map" type?  That would also
+   ;; appear as a pair, wouldn't it?
+   ((pair? thing)
+    (list->vector (map (cut aws-value->scm <> 'strip-name) thing)))
+   ;; Other primitive value, e.g. string or boolean
+   (else thing)))
 
 (define (input-arguments->scm input)
   "Return the arguments of the INPUT value as an alist.  Drop the