Skip to content

Commit 31284f9

Browse files
adwsinghmtdowling
authored andcommitted
Use StructDocument in ProxyService
1 parent 2353629 commit 31284f9

1 file changed

Lines changed: 20 additions & 19 deletions

File tree

  • server/server-proxy/src/main/java/software/amazon/smithy/java/server

server/server-proxy/src/main/java/software/amazon/smithy/java/server/ProxyService.java

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import software.amazon.smithy.java.dynamicclient.DynamicClient;
2626
import software.amazon.smithy.java.dynamicclient.DynamicOperation;
2727
import software.amazon.smithy.java.dynamicschemas.SchemaConverter;
28-
import software.amazon.smithy.java.dynamicschemas.WrappedDocument;
28+
import software.amazon.smithy.java.dynamicschemas.StructDocument;
2929
import software.amazon.smithy.model.Model;
3030
import software.amazon.smithy.model.knowledge.TopDownIndex;
3131
import software.amazon.smithy.model.shapes.OperationShape;
@@ -40,7 +40,7 @@ public final class ProxyService implements Service {
4040

4141
private final DynamicClient dynamicClient;
4242
private final SchemaConverter schemaConverter;
43-
private final Map<String, Operation<WrappedDocument, WrappedDocument>> operations;
43+
private final Map<String, Operation<StructDocument, StructDocument>> operations;
4444
private final TypeRegistry serviceErrorRegistry;
4545
private final Model model;
4646
private final ServiceShape service;
@@ -76,8 +76,8 @@ private ProxyService(Builder builder, ServiceShape service, Model model) {
7676
String operationName = operation.getId().getName();
7777
var function =
7878
new DynamicFunction(dynamicClient, operationName, schemaConverter, model, operation, service);
79-
Operation<WrappedDocument,
80-
WrappedDocument> serverOperation = Operation.of(operationName,
79+
Operation<StructDocument,
80+
StructDocument> serverOperation = Operation.of(operationName,
8181
function,
8282
DynamicOperation.create(operation,
8383
schemaConverter,
@@ -196,25 +196,26 @@ public Builder region(String region) {
196196
}
197197
}
198198

199-
private record DynamicFunction(DynamicClient dynamicClient,
200-
String operation,
201-
SchemaConverter schemaConverter,
202-
Model model,
203-
OperationShape operationShape,
204-
ServiceShape serviceShape) implements BiFunction<WrappedDocument, RequestContext, WrappedDocument> {
199+
private record DynamicFunction(
200+
DynamicClient dynamicClient,
201+
String operation,
202+
SchemaConverter schemaConverter,
203+
Model model,
204+
OperationShape operationShape,
205+
ServiceShape serviceShape) implements BiFunction<StructDocument, RequestContext, StructDocument> {
205206

206207
@Override
207-
public WrappedDocument apply(WrappedDocument input, RequestContext requestContext) {
208-
return createWrappedDocument(operationShape.getOutput().get(), dynamicClient.call(operation, input));
209-
}
208+
public StructDocument apply(StructDocument input, RequestContext requestContext) {
209+
return createStructDocument(operationShape.getOutput().get(), dynamicClient.call(operation, input));
210+
}
210211

211-
private WrappedDocument createWrappedDocument(ToShapeId shape, Document value) {
212-
var schema = schemaConverter.getSchema(model.expectShape(shape.toShapeId()));
213-
if (value.type() != ShapeType.MAP && value.type() != ShapeType.STRUCTURE) {
214-
throw new IllegalArgumentException("Document value must be a map or structure, found " + value.type());
215-
}
216-
return new WrappedDocument(schema, value, serviceShape.getId());
212+
private StructDocument createStructDocument(ToShapeId shape, Document value) {
213+
var schema = schemaConverter.getSchema(model.expectShape(shape.toShapeId()));
214+
if (value.type() != ShapeType.MAP && value.type() != ShapeType.STRUCTURE) {
215+
throw new IllegalArgumentException("Document value must be a map or structure, found " + value.type());
217216
}
217+
return StructDocument.of(schema, value, serviceShape.getId());
218218
}
219+
}
219220

220221
}

0 commit comments

Comments
 (0)