1818import java .util .HashMap ;
1919import java .util .Map ;
2020import java .util .Optional ;
21+ import java .util .stream .Collectors ;
22+ import software .amazon .smithy .model .node .ArrayNode ;
2123import software .amazon .smithy .model .node .Node ;
2224import software .amazon .smithy .model .node .NodeVisitor ;
2325import software .amazon .smithy .model .node .ObjectNode ;
2628import software .amazon .smithy .model .shapes .OperationShape ;
2729import software .amazon .smithy .model .shapes .ServiceShape ;
2830import software .amazon .smithy .model .shapes .Shape ;
31+ import software .amazon .smithy .model .shapes .ShapeType ;
2932import software .amazon .smithy .rulesengine .traits .ClientContextParamsTrait ;
3033import software .amazon .smithy .rulesengine .traits .ContextParamTrait ;
3134import software .amazon .smithy .rulesengine .traits .EndpointRuleSetTrait ;
@@ -66,10 +69,23 @@ public Map<String, String> getClientContextParams() {
6669 if (trait .isPresent ()) {
6770 ClientContextParamsTrait clientContextParamsTrait = trait .get ();
6871 clientContextParamsTrait .getParameters ().forEach ((name , definition ) -> {
69- map .put (
70- name ,
71- definition .getType ().toString ().toLowerCase () // "boolean" and "string" are directly usable in TS.
72- );
72+ ShapeType shapeType = definition .getType ();
73+ if (shapeType .isShapeType (ShapeType .STRING ) || shapeType .isShapeType (ShapeType .BOOLEAN )) {
74+ map .put (
75+ name ,
76+ // "boolean" and "string" are directly usable in TS.
77+ definition .getType ().toString ().toLowerCase ()
78+ );
79+ } else if (shapeType .isShapeType (ShapeType .LIST )) {
80+ map .put (
81+ name ,
82+ "string[]" // Only string lists are supported.
83+ );
84+ } else {
85+ throw new RuntimeException ("unexpected type "
86+ + definition .getType ().toString ()
87+ + " received as clientContextParam." );
88+ }
7389 });
7490 }
7591 return map ;
@@ -90,6 +106,11 @@ public Map<String, String> getStaticContextParamValues(OperationShape operation)
90106 value = "`" + definition .getValue ().expectStringNode ().toString () + "`" ;
91107 } else if (definition .getValue ().isBooleanNode ()) {
92108 value = definition .getValue ().expectBooleanNode ().toString ();
109+ } else if (definition .getValue ().isArrayNode ()) {
110+ ArrayNode arrayNode = definition .getValue ().expectArrayNode ();
111+ value = arrayNode .getElements ().stream ()
112+ .map (element -> element .expectStringNode ().getValue ())
113+ .collect (Collectors .joining ("`, `" , "[`" , "`]" ));
93114 } else {
94115 throw new RuntimeException ("unexpected type "
95116 + definition .getValue ().getType ().toString ()
0 commit comments