Skip to content

Commit 0480559

Browse files
trivikrkuhe
andauthored
Process Map in function parameter list (#1472)
Co-authored-by: George Fu <[email protected]>
1 parent 941cc0e commit 0480559

File tree

1 file changed

+19
-6
lines changed
  • smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen

1 file changed

+19
-6
lines changed

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

+19-6
Original file line numberDiff line numberDiff line change
@@ -296,13 +296,26 @@ static List<String> getFunctionParametersList(Map<String, Object> paramsMap) {
296296
} else if (value instanceof Boolean) {
297297
functionParametersList.add(String.format("%s: %s", key, value));
298298
} else if (value instanceof List) {
299-
if (!((List) value).isEmpty() && !(((List) value).get(0) instanceof String)) {
300-
throw new CodegenException("Plugin function parameters not supported for type List<"
301-
+ ((List) value).get(0).getClass() + ">");
299+
List<?> valueList = (List<?>) value;
300+
if (!valueList.isEmpty() && !(valueList.get(0) instanceof String)) {
301+
throw new CodegenException("Plugin function parameters list must be List<String>");
302302
}
303-
functionParametersList.add(String.format("%s: [%s]",
304-
key, ((List<String>) value).stream()
305-
.collect(Collectors.joining("\", \"", "\"", "\""))));
303+
List<String> valueStringList = valueList.stream()
304+
.map(item -> String.format("'%s'", item))
305+
.collect(Collectors.toList());
306+
functionParametersList.add(String.format("'%s': [%s]",
307+
key, valueStringList.stream().collect(Collectors.joining(", "))));
308+
} else if (value instanceof Map) {
309+
Map<?, ?> valueMap = (Map<?, ?>) value;
310+
if (!valueMap.isEmpty() && valueMap.keySet().stream().anyMatch(k -> !(k instanceof String))
311+
&& valueMap.values().stream().anyMatch(v -> !(v instanceof String))) {
312+
throw new CodegenException("Plugin function parameters map must be Map<String, String>");
313+
}
314+
List<String> valueStringList = valueMap.entrySet().stream()
315+
.map(entry -> String.format("'%s': '%s'", entry.getKey(), entry.getValue()))
316+
.collect(Collectors.toList());
317+
functionParametersList.add(String.format("%s: {%s}",
318+
key, valueStringList.stream().collect(Collectors.joining(", "))));
306319
} else {
307320
// Future support for param type should be added in else if.
308321
throw new CodegenException("Plugin function parameters not supported for type "

0 commit comments

Comments
 (0)