Skip to content

Commit

Permalink
fix: use optional chaining while processing runtime config (#401)
Browse files Browse the repository at this point in the history
  • Loading branch information
gosar authored Aug 23, 2021
1 parent c800765 commit caaac34
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ void generate(LanguageTarget target) {
}
int indentation = target.equals(LanguageTarget.SHARED) ? 1 : 2;
configs.forEach((key, value) -> {
writer.indent(indentation).disableNewlines().openBlock("$1L: config.$1L ?? ", ",\n", key,
writer.indent(indentation).disableNewlines().openBlock("$1L: config?.$1L ?? ", ",\n", key,
() -> {
value.accept(writer);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getRuntimeConfig as getSharedRuntimeConfig } from "./runtimeConfig.shar
/**
* @internal
*/
export const getRuntimeConfig = (config: ${clientConfigName} = {}) => {
export const getRuntimeConfig = (config: ${clientConfigName}) => {
const clientSharedValues = getSharedRuntimeConfig(config);
return {
...clientSharedValues,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getRuntimeConfig as getBrowserRuntimeConfig } from "./runtimeConfig.bro
/**
* @internal
*/
export const getRuntimeConfig = (config: ${clientConfigName} = {}) => {
export const getRuntimeConfig = (config: ${clientConfigName}) => {
const browserDefaults = getBrowserRuntimeConfig(config);
return {
...browserDefaults,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ${clientConfigName} } from "${clientModuleName}";
/**
* @internal
*/
export const getRuntimeConfig = (config: ${clientConfigName} = {}) => ({
export const getRuntimeConfig = (config: ${clientConfigName}) => ({
apiVersion: "${apiVersion}",
${customizations}
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { emitWarningIfUnsupportedVersion } from "@aws-sdk/smithy-client";
/**
* @internal
*/
export const getRuntimeConfig = (config: ${clientConfigName} = {}) => {
export const getRuntimeConfig = (config: ${clientConfigName}) => {
emitWarningIfUnsupportedVersion(process.version);
const clientSharedValues = getSharedRuntimeConfig(config);
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,29 @@ public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(

// Does the runtimeConfig.shared.ts file expand the template properties properly?
String runtimeConfigSharedContents = manifest.getFileString("runtimeConfig.shared.ts").get();
assertThat(runtimeConfigSharedContents,
containsString("export const getRuntimeConfig = (config: ExampleClientConfig) =>"));
assertThat(runtimeConfigSharedContents, containsString("apiVersion: \"1.0.0\","));
assertThat(runtimeConfigSharedContents, containsString("syn: 'ack2',"));
assertThat(runtimeConfigSharedContents, containsString("foo: 'bar',"));
assertThat(runtimeConfigSharedContents, containsString("config?.syn ?? syn: 'ack2',"));
assertThat(runtimeConfigSharedContents, containsString("config?.foo ?? foo: 'bar',"));

// Does the runtimeConfig.ts file expand the template properties properly?
String runtimeConfigContents = manifest.getFileString("runtimeConfig.ts").get();
assertThat(runtimeConfigContents,
containsString("import { ExampleClientConfig } from \"./ExampleClient\";"));
assertThat(runtimeConfigContents, containsString("syn: 'ack2',"));
assertThat(runtimeConfigSharedContents, containsString("foo: 'bar',"));
assertThat(runtimeConfigSharedContents,
containsString("export const getRuntimeConfig = (config: ExampleClientConfig) =>"));
assertThat(runtimeConfigContents, containsString("config?.syn ?? syn: 'ack2',"));
assertThat(runtimeConfigSharedContents, containsString("config?.foo ?? foo: 'bar',"));

// Does the runtimeConfig.browser.ts file expand the template properties properly?
String runtimeConfigBrowserContents = manifest.getFileString("runtimeConfig.browser.ts").get();
assertThat(runtimeConfigBrowserContents,
containsString("import { ExampleClientConfig } from \"./ExampleClient\";"));
assertThat(runtimeConfigContents, containsString("syn: 'ack2',"));
assertThat(runtimeConfigSharedContents, containsString("foo: 'bar',"));
assertThat(runtimeConfigSharedContents,
containsString("export const getRuntimeConfig = (config: ExampleClientConfig) =>"));
assertThat(runtimeConfigContents, containsString("config?.syn ?? syn: 'ack2',"));
assertThat(runtimeConfigSharedContents, containsString("config?.foo ?? foo: 'bar',"));

// Does the runtimeConfig.native.ts file expand the browser template properties properly?
String runtimeConfigNativeContents = manifest.getFileString("runtimeConfig.native.ts").get();
Expand All @@ -111,7 +117,9 @@ public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
assertThat(runtimeConfigNativeContents,
containsString(
"import { getRuntimeConfig as getBrowserRuntimeConfig } from \"./runtimeConfig.browser\";"));
assertThat(runtimeConfigContents, containsString("syn: 'ack2',"));
assertThat(runtimeConfigSharedContents, containsString("foo: 'bar',"));
assertThat(runtimeConfigSharedContents,
containsString("export const getRuntimeConfig = (config: ExampleClientConfig) =>"));
assertThat(runtimeConfigContents, containsString("config?.syn ?? syn: 'ack2',"));
assertThat(runtimeConfigSharedContents, containsString("config?.foo ?? foo: 'bar',"));
}
}

0 comments on commit caaac34

Please sign in to comment.