@@ -25,7 +25,7 @@ private ModelBundles() {}
2525 private static final PluginProviders PLUGIN_PROVIDERS = PluginProviders .builder ().build ();
2626
2727 public static Service getService (SmithyBundle smithyBundle ) {
28- var model = getModel (smithyBundle );
28+ var model = prepareModelForBundling (smithyBundle );
2929 var plugin = PLUGIN_PROVIDERS .getPlugin (smithyBundle .getConfigType (), smithyBundle .getConfig ());
3030 return ProxyService .builder ()
3131 .model (model )
@@ -35,7 +35,8 @@ public static Service getService(SmithyBundle smithyBundle) {
3535 .build ();
3636 }
3737
38- private static Model getModel (SmithyBundle bundle ) {
38+ // visible for testing
39+ static Model prepareModelForBundling (SmithyBundle bundle ) {
3940 // TODO: model the type in the returned bundle
4041 var suffix = bundle .getModel ().startsWith ("$version" ) ? "smithy" : "json" ;
4142 var modelAssemble = new ModelAssembler ().putProperty (ModelAssembler .ALLOW_UNKNOWN_TRAITS , true )
@@ -49,7 +50,6 @@ private static Model getModel(SmithyBundle bundle) {
4950 model = modelAssemble .assemble ().unwrap ();
5051 additionalInputShape =
5152 model .expectShape (ShapeId .from (additionalInput .getIdentifier ())).asStructureShape ().get ();
52-
5353 } else {
5454 model = modelAssemble .assemble ().unwrap ();
5555 }
@@ -116,16 +116,24 @@ private static void addProxyOperationWithAdditionalInput(
116116 var input = op .getInput ();
117117 StructureShape finalInput ;
118118 if (op .getInput ().isEmpty ()) {
119- finalInput = additionalInput ;
119+ var containerId = syntheticContainerForInput (additionalInput );
120+ var container = builder .getCurrentShapes ().get (containerId );
121+ if (container == null ) {
122+ finalInput = createSyntheticInput (containerId , additionalInput );
123+ builder .addShape (finalInput );
124+ } else {
125+ finalInput = (StructureShape ) container ;
126+ }
120127 } else {
121128 var inputBuilder = model .expectShape (input .get (), StructureShape .class ).toBuilder ();
122129 inputBuilder .addMember (MemberShape .builder ()
123130 .id (ShapeId .from (inputBuilder .getId ().toString () + "$additionalInput" ))
124131 .target (additionalInput .getId ())
125132 .build ());
126133 finalInput = inputBuilder .id (ShapeId .from (inputBuilder .getId ().toString ()) + "Proxy" ).build ();
134+ builder .addShape (finalInput );
127135 }
128- builder . addShape ( finalInput );
136+
129137 var newOperation = op .toBuilder ()
130138 .id (ShapeId .from (op .getId ().toString () + "Proxy" ))
131139 .input (finalInput )
@@ -135,4 +143,18 @@ private static void addProxyOperationWithAdditionalInput(
135143 builder .addShape (newOperation );
136144 serviceBuilder .addOperation (newOperation ).build ();
137145 }
146+
147+ private static ShapeId syntheticContainerForInput (StructureShape additionalInput ) {
148+ return ShapeId .from ("smithy.mcp#AdditionalInputFor" + additionalInput .getId ().getName ());
149+ }
150+
151+ private static StructureShape createSyntheticInput (ShapeId containerId , StructureShape additionalInput ) {
152+ return StructureShape .builder ()
153+ .id (containerId )
154+ .addMember (MemberShape .builder ()
155+ .id (containerId .toString () + "$additionalInput" )
156+ .target (additionalInput .getId ())
157+ .build ())
158+ .build ();
159+ }
138160}
0 commit comments