Skip to content

Commit d468edf

Browse files
authored
fix: allow endpoint params to be explicitly undefined if not required (#1618)
1 parent f4ab06a commit d468edf

File tree

5 files changed

+33
-23
lines changed

5 files changed

+33
-23
lines changed

private/smithy-rpcv2-cbor-schema/src/endpoint/EndpointParameters.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ export const commonParams = {
2525
} as const;
2626

2727
export interface EndpointParameters extends __EndpointParameters {
28-
endpoint?: string;
28+
endpoint?: string | undefined;
2929
}

private/smithy-rpcv2-cbor-schema/src/schemas/schemas.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const _B = "Blob";
2-
const _BL = "BlobList";
3-
const _BLo = "BooleanList";
4-
const _Bo = "Boolean";
1+
const _B = "Boolean";
2+
const _BL = "BooleanList";
3+
const _BLl = "BlobList";
4+
const _Bl = "Blob";
55
const _By = "Byte";
66
const _CE = "ComplexError";
77
const _CNED = "ComplexNestedErrorData";

private/smithy-rpcv2-cbor/src/endpoint/EndpointParameters.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ export const commonParams = {
2525
} as const;
2626

2727
export interface EndpointParameters extends __EndpointParameters {
28-
endpoint?: string;
28+
endpoint?: string | undefined;
2929
}

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/endpointsV2/ParameterGenerator.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,21 @@ public Map.Entry<String, String> getNameAndType() {
132132
public String toCodeString(boolean isClientContextParam) {
133133
String buffer = "";
134134
buffer += parameterName;
135-
if (!required || hasDefault() || isClientContextParam) {
135+
boolean optional = !required || hasDefault() || isClientContextParam;
136+
if (optional) {
136137
buffer += "?";
137138
}
138139
buffer += ": ";
139140

140141
if (parameterName.equals("endpoint") && isInputKey) {
141142
buffer += "string | Provider<string> | Endpoint | Provider<Endpoint> | EndpointV2 | Provider<EndpointV2>;";
142143
} else {
143-
if (isClientContextParam) {
144-
buffer += (tsParamType + "|" + "Provider<" + tsParamType + ">") + ";";
144+
if (optional) {
145+
if (isClientContextParam) {
146+
buffer += (tsParamType + " | undefined | Provider<" + tsParamType + " | undefined>") + ";";
147+
} else {
148+
buffer += tsParamType + " | undefined;";
149+
}
145150
} else {
146151
buffer += tsParamType + ";";
147152
}

smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/endpointsV2/EndpointsV2GeneratorTest.java

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,30 @@ public void containsExtraContextParameter() {
4040
String ruleset = manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/endpoint/ruleset.ts").get();
4141

4242
assertThat(ruleset, containsString(
43-
" },\n" +
44-
" \"Stage\": {\n" +
45-
" \"type\": \"String\",\n" +
46-
" \"required\": true,\n" +
47-
" \"default\": \"production\",\n" +
48-
" },\n"));
43+
"""
44+
},
45+
"Stage": {
46+
"type": "String",
47+
"required": true,
48+
"default": "production",
49+
},
50+
"""));
4951

5052
String endpointParameters = manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/endpoint/EndpointParameters.ts").get();
5153

5254
assertThat(endpointParameters, containsString(
53-
" return Object.assign(options, {\n" +
54-
" stage: options.stage ?? \"production\",\n" +
55-
" defaultSigningName: \"\",\n" +
56-
" });\n"));
55+
"""
56+
return Object.assign(options, {
57+
stage: options.stage ?? "production",
58+
defaultSigningName: "",
59+
});
60+
"""));
5761
assertThat(endpointParameters, containsString(
58-
"export interface ClientInputEndpointParameters {\n" +
59-
" region?: string|Provider<string>;\n" +
60-
" stage?: string|Provider<string>;\n" +
61-
" endpoint?:"));
62+
"""
63+
export interface ClientInputEndpointParameters {
64+
region?: string | undefined | Provider<string | undefined>;
65+
stage?: string | undefined | Provider<string | undefined>;
66+
endpoint?:"""));
6267
}
6368

6469
private MockManifest testEndpoints(String filename) {

0 commit comments

Comments
 (0)