diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/SmithyIdlModelSerializer.java b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/SmithyIdlModelSerializer.java index 53000a44ced..ba7ac270408 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/shapes/SmithyIdlModelSerializer.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/shapes/SmithyIdlModelSerializer.java @@ -243,8 +243,8 @@ private Pair determineInlineSuffixes(Model fullModel, Collection return Pair.of(inlineInputSuffix, inlineOutputSuffix); } - Set inputSuffixes = new HashSet<>(); - Set outputSuffixes = new HashSet<>(); + Map inputSuffixes = new LinkedHashMap<>(); + Map outputSuffixes = new LinkedHashMap<>(); for (Shape shape : shapes) { if (!shape.isOperationShape()) { continue; @@ -255,15 +255,28 @@ private Pair determineInlineSuffixes(Model fullModel, Collection StructureShape output = fullModel.expectShape(operation.getOutputShape(), StructureShape.class); if (shapes.contains(input) && input.getId().getName().startsWith(operation.getId().getName())) { - inputSuffixes.add(input.getId().getName().substring(operation.getId().getName().length())); + String inputSuffix = input.getId().getName().substring(operation.getId().getName().length()); + int inputCount = inputSuffixes.getOrDefault(inputSuffix, 0); + inputSuffixes.put(inputSuffix, ++inputCount); } if (shapes.contains(output) && output.getId().getName().startsWith(operation.getId().getName())) { - outputSuffixes.add(output.getId().getName().substring(operation.getId().getName().length())); + String outputSuffix = output.getId().getName().substring(operation.getId().getName().length()); + int outputCount = outputSuffixes.getOrDefault(outputSuffix, 0); + outputSuffixes.put(outputSuffix, ++outputCount); } } - String inputSuffix = inputSuffixes.size() == 1 ? inputSuffixes.iterator().next() : inlineInputSuffix; - String outputSuffix = outputSuffixes.size() == 1 ? outputSuffixes.iterator().next() : inlineOutputSuffix; + + String inputSuffix = inputSuffixes.entrySet() + .stream() + .max(Map.Entry.comparingByValue()) + .map(Map.Entry::getKey) + .orElse(inlineInputSuffix); + String outputSuffix = outputSuffixes.entrySet() + .stream() + .max(Map.Entry.comparingByValue()) + .map(Map.Entry::getKey) + .orElse(inlineInputSuffix); return Pair.of(inputSuffix, outputSuffix); } diff --git a/smithy-model/src/test/resources/software/amazon/smithy/model/shapes/idl-serialization/inferred-io/shared.smithy b/smithy-model/src/test/resources/software/amazon/smithy/model/shapes/idl-serialization/inferred-io/shared.smithy index 8dc75dc7764..b8d45df4d95 100644 --- a/smithy-model/src/test/resources/software/amazon/smithy/model/shapes/idl-serialization/inferred-io/shared.smithy +++ b/smithy-model/src/test/resources/software/amazon/smithy/model/shapes/idl-serialization/inferred-io/shared.smithy @@ -4,6 +4,11 @@ $operationOutputSuffix: "Response" namespace com.example +operation NotShared { + input: NotSharedInput + output: NotSharedOutput +} + operation SharedCustomA { input := {} output := {} @@ -13,3 +18,9 @@ operation SharedCustomB { input := {} output := {} } + +@input +structure NotSharedInput {} + +@output +structure NotSharedOutput {}