summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRicardo Wurmus <rekado@elephly.net>2021-03-07 08:38:52 +0100
committerRicardo Wurmus <rekado@elephly.net>2021-03-07 08:38:52 +0100
commitb2eea94a72cf934764d8e17f9ee439b0a0d11cdf (patch)
tree7018d9ec59757c3cdbef72b922fea19b9340c66f
parente0a53f9bf3b19db202608e4ec7eedefcf749b692 (diff)
request: aws-value->scm: Support parent name stripping.
This is necessary to remove unnecessary nesting when serializing wrappers around primitive types.
-rw-r--r--aws/request.scm37
1 files changed, 23 insertions, 14 deletions
diff --git a/aws/request.scm b/aws/request.scm
index 0f4956b..69d71bb 100644
--- a/aws/request.scm
+++ b/aws/request.scm
@@ -134,28 +134,37 @@
'()))
"&"))
-(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