@@ -25,7 +25,7 @@ private ModelBundles() {}
25
25
private static final PluginProviders PLUGIN_PROVIDERS = PluginProviders .builder ().build ();
26
26
27
27
public static Service getService (SmithyBundle smithyBundle ) {
28
- var model = getModel (smithyBundle );
28
+ var model = prepareModelForBundling (smithyBundle );
29
29
var plugin = PLUGIN_PROVIDERS .getPlugin (smithyBundle .getConfigType (), smithyBundle .getConfig ());
30
30
return ProxyService .builder ()
31
31
.model (model )
@@ -35,7 +35,8 @@ public static Service getService(SmithyBundle smithyBundle) {
35
35
.build ();
36
36
}
37
37
38
- private static Model getModel (SmithyBundle bundle ) {
38
+ // visible for testing
39
+ static Model prepareModelForBundling (SmithyBundle bundle ) {
39
40
// TODO: model the type in the returned bundle
40
41
var suffix = bundle .getModel ().startsWith ("$version" ) ? "smithy" : "json" ;
41
42
var modelAssemble = new ModelAssembler ().putProperty (ModelAssembler .ALLOW_UNKNOWN_TRAITS , true )
@@ -49,7 +50,6 @@ private static Model getModel(SmithyBundle bundle) {
49
50
model = modelAssemble .assemble ().unwrap ();
50
51
additionalInputShape =
51
52
model .expectShape (ShapeId .from (additionalInput .getIdentifier ())).asStructureShape ().get ();
52
-
53
53
} else {
54
54
model = modelAssemble .assemble ().unwrap ();
55
55
}
@@ -116,16 +116,24 @@ private static void addProxyOperationWithAdditionalInput(
116
116
var input = op .getInput ();
117
117
StructureShape finalInput ;
118
118
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
+ }
120
127
} else {
121
128
var inputBuilder = model .expectShape (input .get (), StructureShape .class ).toBuilder ();
122
129
inputBuilder .addMember (MemberShape .builder ()
123
130
.id (ShapeId .from (inputBuilder .getId ().toString () + "$additionalInput" ))
124
131
.target (additionalInput .getId ())
125
132
.build ());
126
133
finalInput = inputBuilder .id (ShapeId .from (inputBuilder .getId ().toString ()) + "Proxy" ).build ();
134
+ builder .addShape (finalInput );
127
135
}
128
- builder . addShape ( finalInput );
136
+
129
137
var newOperation = op .toBuilder ()
130
138
.id (ShapeId .from (op .getId ().toString () + "Proxy" ))
131
139
.input (finalInput )
@@ -135,4 +143,18 @@ private static void addProxyOperationWithAdditionalInput(
135
143
builder .addShape (newOperation );
136
144
serviceBuilder .addOperation (newOperation ).build ();
137
145
}
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
+ }
138
160
}
0 commit comments