Skip to content

Commit 552a648

Browse files
committed
Add map input for dynamic client
1 parent 2263e22 commit 552a648

2 files changed

Lines changed: 29 additions & 5 deletions

File tree

client/dynamic-client/src/main/java/software/amazon/smithy/java/dynamicclient/DynamicClient.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,18 @@ public Document call(String operation) {
115115
}
116116

117117
/**
118-
* Call an operation with input.
118+
* Call an operation with a map input, using {@link Document#ofObject(Object)} to create a document.
119+
*
120+
* @param operation Operation name to call.
121+
* @param input Operation input as a document.
122+
* @return the output of the operation.
123+
*/
124+
public Document call(String operation, Map<String, Object> input) {
125+
return call(operation, Document.ofObject(input));
126+
}
127+
128+
/**
129+
* Call an operation with a document input.
119130
*
120131
* @param operation Operation name to call.
121132
* @param input Operation input as a document.

client/dynamic-client/src/test/java/software/amazon/smithy/java/dynamicclient/DynamicClientTest.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,22 @@ public void sendsRequestWithNoInput() throws Exception {
156156
assertThat(result.getMember("id").asString(), equalTo("1"));
157157
}
158158

159+
@Test
160+
public void sendOperationsWithMap() {
161+
var client = DynamicClient.builder()
162+
.serviceId(SERVICE)
163+
.model(model)
164+
.protocol(new AwsJson1Protocol(SERVICE))
165+
.authSchemeResolver(AuthSchemeResolver.NO_AUTH)
166+
.transport(mockTransport())
167+
.endpointResolver(EndpointResolver.staticEndpoint("https://foo.com"))
168+
.build();
169+
170+
var result = client.call("GetSprocket", Map.of("id", "1"));
171+
assertThat(result.type(), is(ShapeType.STRUCTURE));
172+
assertThat(result.getMember("id").asString(), equalTo("1"));
173+
}
174+
159175
private ClientTransport<HttpRequest, HttpResponse> mockTransport() {
160176
return new ClientTransport<>() {
161177
@Override
@@ -304,10 +320,7 @@ public void detectsService() {
304320

305321
@Test
306322
public void detectsEndpointResolver() {
307-
var client = DynamicClient.builder()
308-
.model(model)
309-
// .authSchemeResolver(AuthSchemeResolver.NO_AUTH)
310-
.build();
323+
var client = DynamicClient.builder().model(model).build();
311324

312325
assertThat(client.config().service().schema().id(), equalTo(SERVICE));
313326
assertThat(client.config().protocol(), instanceOf(AwsJson1Protocol.class));

0 commit comments

Comments
 (0)