26
26
import software .amazon .smithy .codegen .core .SymbolProvider ;
27
27
import software .amazon .smithy .codegen .core .SymbolReference ;
28
28
import software .amazon .smithy .model .Model ;
29
- import software .amazon .smithy .model .knowledge .OperationIndex ;
30
29
import software .amazon .smithy .model .knowledge .TopDownIndex ;
31
30
import software .amazon .smithy .model .shapes .OperationShape ;
32
31
import software .amazon .smithy .model .shapes .ServiceShape ;
33
- import software .amazon .smithy .model .shapes .StructureShape ;
34
32
import software .amazon .smithy .typescript .codegen .integration .RuntimeClientPlugin ;
35
33
import software .amazon .smithy .typescript .codegen .integration .TypeScriptIntegration ;
36
34
import software .amazon .smithy .utils .OptionalUtils ;
@@ -90,33 +88,23 @@ static String getResolvedConfigTypeName(Symbol symbol) {
90
88
91
89
@ Override
92
90
public void run () {
93
- OperationIndex operationIndex = model .getKnowledge (OperationIndex .class );
94
91
writer .addImport ("Client" , "__Client" , "@aws-sdk/smithy-client" );
95
92
writer .addImport ("ClientDefaultValues" , "__ClientDefaultValues" , "./runtimeConfig" );
96
93
97
94
// Normalize the input and output types of the command to account for
98
95
// things like an operation adding input where there once wasn't any
99
96
// input, adding output, naming differences between services, etc.
100
- writeInputOutputTypeUnion ("ServiceInputTypes" , writer , operationIndex ::getInput ,
101
- writer -> {
102
- // Use an empty object if an operation doesn't define input.
103
- writer .write ("| {}" );
104
- },
105
- // Input types don't need modification.
106
- Function .identity ());
107
- writeInputOutputTypeUnion ("ServiceOutputTypes" , writer , operationIndex ::getOutput ,
108
- writer -> {
109
- // Use a MetadataBearer if an operation doesn't define output.
110
- writer .addImport ("MetadataBearer" , "__MetadataBearer" ,
111
- TypeScriptDependency .AWS_SDK_TYPES .packageName );
112
- writer .write ("| __MetadataBearer" );
113
- },
114
- // Command output shape types should be MetadataBearers in the output union.
115
- type -> {
116
- writer .addImport ("MetadataBearer" , "__MetadataBearer" ,
117
- TypeScriptDependency .AWS_SDK_TYPES .packageName );
118
- return type + " & __MetadataBearer" ;
119
- });
97
+ writeInputOutputTypeUnion ("ServiceInputTypes" , writer ,
98
+ operationSymbol -> operationSymbol .getProperty ("inputType" , Symbol .class ), writer -> {
99
+ // Use an empty object if an operation doesn't define input.
100
+ writer .write ("| {}" );
101
+ });
102
+ writeInputOutputTypeUnion ("ServiceOutputTypes" , writer ,
103
+ operationSymbol -> operationSymbol .getProperty ("outputType" , Symbol .class ), writer -> {
104
+ // Use a MetadataBearer if an operation doesn't define output.
105
+ writer .addImport ("MetadataBearer" , "__MetadataBearer" , TypeScriptDependency .AWS_SDK_TYPES .packageName );
106
+ writer .write ("| __MetadataBearer" );
107
+ });
120
108
121
109
generateConfig ();
122
110
writer .write ("" );
@@ -126,15 +114,15 @@ public void run() {
126
114
private void writeInputOutputTypeUnion (
127
115
String typeName ,
128
116
TypeScriptWriter writer ,
129
- Function <OperationShape , Optional <StructureShape >> mapper ,
130
- Consumer <TypeScriptWriter > defaultTypeGenerator ,
131
- Function <String , String > typeModifier
117
+ Function <Symbol , Optional <Symbol >> mapper ,
118
+ Consumer <TypeScriptWriter > defaultTypeGenerator
132
119
) {
133
120
TopDownIndex topDownIndex = model .getKnowledge (TopDownIndex .class );
134
121
Set <OperationShape > containedOperations = topDownIndex .getContainedOperations (service );
122
+
135
123
List <Symbol > symbols = containedOperations .stream ()
136
- .flatMap (operation -> OptionalUtils .stream (mapper .apply (operation )))
137
124
.map (symbolProvider ::toSymbol )
125
+ .flatMap (operation -> OptionalUtils .stream (mapper .apply (operation )))
138
126
.sorted (Comparator .comparing (Symbol ::getName ))
139
127
.collect (Collectors .toList ());
140
128
@@ -145,8 +133,7 @@ private void writeInputOutputTypeUnion(
145
133
defaultTypeGenerator .accept (writer );
146
134
}
147
135
for (int i = 0 ; i < symbols .size (); i ++) {
148
- String lineEnding = (i == symbols .size () - 1 ) ? ";" : "" ;
149
- writer .write ("| " + typeModifier .apply ("$T" ) + "$L" , symbols .get (i ), lineEnding );
136
+ writer .write ("| $T$L" , symbols .get (i ), i == symbols .size () - 1 ? ";" : "" );
150
137
}
151
138
writer .dedent ();
152
139
writer .write ("" );
0 commit comments