Skip to content

Commit ba79f06

Browse files
committed
feat: java codegen for optional command arg
1 parent 0905982 commit ba79f06

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

packages/smithy-client/src/command.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ class ClassBuilder<
218218
* @returns a Command class with the classBuilder properties.
219219
*/
220220
public build(): {
221+
new (input: I): CommandImpl<I, O, C, SI, SO>;
221222
new (...[input]: OptionalParameter<I>): CommandImpl<I, O, C, SI, SO>;
222223
getEndpointParameterInstructions(): EndpointParameterInstructions;
223224
} {

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/ServiceAggregatedClientGenerator.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import software.amazon.smithy.codegen.core.SymbolProvider;
2323
import software.amazon.smithy.model.Model;
2424
import software.amazon.smithy.model.knowledge.TopDownIndex;
25+
import software.amazon.smithy.model.shapes.MemberShape;
2526
import software.amazon.smithy.model.shapes.OperationShape;
2627
import software.amazon.smithy.model.shapes.ServiceShape;
2728
import software.amazon.smithy.utils.SmithyInternalApi;
@@ -94,11 +95,14 @@ public void run() {
9495
writer.writeDocs(
9596
"@see {@link " + operationSymbol.getName() + "}"
9697
);
97-
writer.addImport("OptionalParameter", null, TypeScriptDependency.SMITHY_TYPES);
98-
writer.write("""
99-
$L(
100-
...[args]: OptionalParameter<$T>,
101-
): Promise<$T>;""", methodName, input, output);
98+
boolean inputOptional = model.getShape(operation.getInputShape()).map(
99+
shape -> shape.getAllMembers().values().stream().noneMatch(MemberShape::isRequired)
100+
).orElse(true);
101+
if (inputOptional) {
102+
writer.addImport("OptionalParameter", null, TypeScriptDependency.SMITHY_TYPES);
103+
writer.write("""
104+
$L(): Promise<$T>;""", methodName, output);
105+
}
102106
writer.write("""
103107
$L(
104108
args: $T,

0 commit comments

Comments
 (0)