Skip to content

Commit 0905982

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

File tree

2 files changed

+34
-26
lines changed

2 files changed

+34
-26
lines changed

smithy-typescript-codegen-test/model/weather/main.smithy

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -167,17 +167,17 @@ apply GetCity @httpResponseTests([
167167
code: 200
168168
body: """
169169
{
170-
"name": "Seattle",
171-
"coordinates": {
172-
"latitude": 12.34,
173-
"longitude": -56.78
174-
},
175-
"city": {
176-
"cityId": "123",
177-
"name": "Seattle",
178-
"number": "One",
179-
"case": "Upper"
180-
}
170+
"name": "Seattle",
171+
"coordinates": {
172+
"latitude": 12.34,
173+
"longitude": -56.78
174+
},
175+
"city": {
176+
"cityId": "123",
177+
"name": "Seattle",
178+
"number": "One",
179+
"case": "Upper"
180+
}
181181
}"""
182182
bodyMediaType: "application/json"
183183
params: {
@@ -259,8 +259,8 @@ apply NoSuchResource @httpResponseTests([
259259
code: 404
260260
body: """
261261
{
262-
"resourceType": "City",
263-
"message": "Your custom message"
262+
"resourceType": "City",
263+
"message": "Your custom message"
264264
}"""
265265
bodyMediaType: "application/json"
266266
params: { resourceType: "City", message: "Your custom message" }

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

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,27 @@ public void run() {
9494
writer.writeDocs(
9595
"@see {@link " + operationSymbol.getName() + "}"
9696
);
97-
writer.write("$L(\n"
98-
+ " args: $T,\n"
99-
+ " options?: $T,\n"
100-
+ "): Promise<$T>;", methodName, input, applicationProtocol.getOptionsType(), output);
101-
writer.write("$L(\n"
102-
+ " args: $T,\n"
103-
+ " cb: (err: any, data?: $T) => void\n"
104-
+ "): void;", methodName, input, output);
105-
writer.write("$L(\n"
106-
+ " args: $T,\n"
107-
+ " options: $T,\n"
108-
+ " cb: (err: any, data?: $T) => void\n"
109-
+ "): void;", methodName, input, applicationProtocol.getOptionsType(), output);
97+
writer.addImport("OptionalParameter", null, TypeScriptDependency.SMITHY_TYPES);
98+
writer.write("""
99+
$L(
100+
...[args]: OptionalParameter<$T>,
101+
): Promise<$T>;""", methodName, input, output);
102+
writer.write("""
103+
$L(
104+
args: $T,
105+
options?: $T,
106+
): Promise<$T>;""", methodName, input, applicationProtocol.getOptionsType(), output);
107+
writer.write("""
108+
$L(
109+
args: $T,
110+
cb: (err: any, data?: $T) => void
111+
): void;""", methodName, input, output);
112+
writer.write("""
113+
$L(
114+
args: $T,
115+
options: $T,
116+
cb: (err: any, data?: $T) => void
117+
): void;""", methodName, input, applicationProtocol.getOptionsType(), output);
110118
writer.write("");
111119
}
112120
});

0 commit comments

Comments
 (0)