22
22
import software .amazon .smithy .model .node .NodeVisitor ;
23
23
import software .amazon .smithy .model .node .ObjectNode ;
24
24
import software .amazon .smithy .model .node .StringNode ;
25
- import software .amazon .smithy .model .shapes .OperationShape ;
25
+ import software .amazon .smithy .model .shapes .MemberShape ;
26
26
import software .amazon .smithy .model .shapes .ServiceShape ;
27
+ import software .amazon .smithy .model .shapes .Shape ;
27
28
import software .amazon .smithy .rulesengine .traits .ClientContextParamsTrait ;
28
29
import software .amazon .smithy .rulesengine .traits .ContextParamTrait ;
29
30
import software .amazon .smithy .rulesengine .traits .EndpointRuleSetTrait ;
@@ -65,7 +66,7 @@ public Map<String, String> getClientContextParams() {
65
66
clientContextParamsTrait .getParameters ().forEach ((name , definition ) -> {
66
67
map .put (
67
68
name ,
68
- definition .getType ().toString () // "boolean" and "string" are directly usable in TS.
69
+ definition .getType ().toString (). toLowerCase () // "boolean" and "string" are directly usable in TS.
69
70
);
70
71
});
71
72
}
@@ -76,46 +77,58 @@ public Map<String, String> getClientContextParams() {
76
77
* "The staticContextParams trait defines one or more context parameters that MUST
77
78
* be bound to the specified values. This trait MUST target an operation shape."
78
79
*/
79
- public Map <String , String > getStaticContextParams (OperationShape operation ) {
80
+ public Map <String , String > getStaticContextParams (Shape operationInput ) {
80
81
Map <String , String > map = new HashMap <>();
81
- Optional <StaticContextParamsTrait > trait = operation .getTrait (StaticContextParamsTrait .class );
82
- if (trait .isPresent ()) {
83
- StaticContextParamsTrait staticContextParamsTrait = trait .get ();
84
- staticContextParamsTrait .getParameters ().forEach ((name , definition ) -> {
85
- map .put (
86
- name ,
87
- definition .getValue ().getType ().toString ()
88
- );
82
+
83
+ if (operationInput .isStructureShape ()) {
84
+ operationInput .getAllMembers ().forEach ((String memberName , MemberShape member ) -> {
85
+ Optional <StaticContextParamsTrait > trait = member .getTrait (StaticContextParamsTrait .class );
86
+ if (trait .isPresent ()) {
87
+ StaticContextParamsTrait staticContextParamsTrait = trait .get ();
88
+ staticContextParamsTrait .getParameters ().forEach ((name , definition ) -> {
89
+ map .put (
90
+ name ,
91
+ definition .getValue ().getType ().toString ()
92
+ );
93
+ });
94
+ }
89
95
});
90
96
}
97
+
91
98
return map ;
92
99
}
93
100
94
101
/**
95
102
* Get map of params to actual values instead of the value type.
96
103
*/
97
- public Map <String , String > getStaticContextParamValues (OperationShape operation ) {
104
+ public Map <String , String > getStaticContextParamValues (Shape operationInput ) {
98
105
Map <String , String > map = new HashMap <>();
99
- Optional <StaticContextParamsTrait > trait = operation .getTrait (StaticContextParamsTrait .class );
100
- if (trait .isPresent ()) {
101
- StaticContextParamsTrait staticContextParamsTrait = trait .get ();
102
- staticContextParamsTrait .getParameters ().forEach ((name , definition ) -> {
103
- String value ;
104
- if (definition .getValue ().isStringNode ()) {
105
- value = "`" + definition .getValue ().expectStringNode ().toString () + "`" ;
106
- } else if (definition .getValue ().isBooleanNode ()) {
107
- value = definition .getValue ().expectBooleanNode ().toString ();
108
- } else {
109
- throw new RuntimeException ("unexpected type "
110
- + definition .getValue ().getType ().toString ()
111
- + " received as staticContextParam." );
106
+
107
+ if (operationInput .isStructureShape ()) {
108
+ operationInput .getAllMembers ().forEach ((String memberName , MemberShape member ) -> {
109
+ Optional <StaticContextParamsTrait > trait = member .getTrait (StaticContextParamsTrait .class );
110
+ if (trait .isPresent ()) {
111
+ StaticContextParamsTrait staticContextParamsTrait = trait .get ();
112
+ staticContextParamsTrait .getParameters ().forEach ((name , definition ) -> {
113
+ String value ;
114
+ if (definition .getValue ().isStringNode ()) {
115
+ value = "`" + definition .getValue ().expectStringNode ().toString () + "`" ;
116
+ } else if (definition .getValue ().isBooleanNode ()) {
117
+ value = definition .getValue ().expectBooleanNode ().toString ();
118
+ } else {
119
+ throw new RuntimeException ("unexpected type "
120
+ + definition .getValue ().getType ().toString ()
121
+ + " received as staticContextParam." );
122
+ }
123
+ map .put (
124
+ name ,
125
+ value
126
+ );
127
+ });
112
128
}
113
- map .put (
114
- name ,
115
- value
116
- );
117
129
});
118
130
}
131
+
119
132
return map ;
120
133
}
121
134
@@ -125,17 +138,23 @@ public Map<String, String> getStaticContextParamValues(OperationShape operation)
125
138
* The targeted endpoint parameter MUST be a type that is compatible with member’s
126
139
* shape targeted by the trait.
127
140
*/
128
- public Map <String , String > getContextParams (OperationShape operation ) {
141
+ public Map <String , String > getContextParams (Shape operationInput ) {
129
142
Map <String , String > map = new HashMap <>();
130
- Optional <ContextParamTrait > trait = operation .getTrait (ContextParamTrait .class );
131
- if (trait .isPresent ()) {
132
- ContextParamTrait staticContextParamsTrait = trait .get ();
133
- String name = staticContextParamsTrait .getName ();
134
- map .put (
135
- name ,
136
- "unknown"
137
- );
143
+
144
+ if (operationInput .isStructureShape ()) {
145
+ operationInput .getAllMembers ().forEach ((String memberName , MemberShape member ) -> {
146
+ Optional <ContextParamTrait > trait = member .getTrait (ContextParamTrait .class );
147
+ if (trait .isPresent ()) {
148
+ ContextParamTrait contextParamTrait = trait .get ();
149
+ String name = contextParamTrait .getName ();
150
+ map .put (
151
+ name ,
152
+ "unknown"
153
+ );
154
+ }
155
+ });
138
156
}
157
+
139
158
return map ;
140
159
}
141
160
0 commit comments