|
20 | 20 | import java.util.Map;
|
21 | 21 | import java.util.function.Consumer;
|
22 | 22 |
|
| 23 | +import software.amazon.smithy.aws.traits.clientendpointdiscovery.ClientDiscoveredEndpointTrait; |
23 | 24 | import software.amazon.smithy.aws.traits.clientendpointdiscovery.ClientEndpointDiscoveryTrait;
|
24 | 25 | import software.amazon.smithy.codegen.core.CodegenException;
|
25 | 26 | import software.amazon.smithy.codegen.core.SymbolProvider;
|
|
33 | 34 | import software.amazon.smithy.typescript.codegen.TypeScriptWriter;
|
34 | 35 | import software.amazon.smithy.typescript.codegen.integration.RuntimeClientPlugin;
|
35 | 36 | import software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration;
|
| 37 | +import software.amazon.smithy.typescript.codegen.integration.RuntimeClientPlugin.Convention; |
36 | 38 | import software.amazon.smithy.utils.ListUtils;
|
37 | 39 | import software.amazon.smithy.utils.MapUtils;
|
38 | 40 | import software.amazon.smithy.utils.SmithyInternalApi;
|
@@ -70,7 +72,22 @@ public List<RuntimeClientPlugin> getClientPlugins() {
|
70 | 72 | // ToDo: The Endpoint Discovery Command Name needs to be read from ClientEndpointDiscoveryTrait.
|
71 | 73 | .additionalResolveFunctionParameters("DescribeEndpointsCommand")
|
72 | 74 | .servicePredicate((m, s) -> hasClientEndpointDiscovery(s))
|
| 75 | + .build(), |
| 76 | + // ToDo: The value ClientDiscoveredEndpointTrait.isRequired() needs to be passed to Plugin instead |
| 77 | + // of creating two functions Required and Optional. The map of identifiers also needs to be passed. |
| 78 | + RuntimeClientPlugin.builder() |
| 79 | + .withConventions(AwsDependency.MIDDLEWARE_ENDPOINT_DISCOVERY.dependency, |
| 80 | + "EndpointDiscoveryRequired", RuntimeClientPlugin.Convention.HAS_MIDDLEWARE) |
| 81 | + .additionalResolveFunctionParameters(new String[]{"clientStack", "options"}) |
| 82 | + .operationPredicate((m, s, o) -> isClientDiscoveredEndpointRequired(s, o)) |
| 83 | + .build(), |
| 84 | + RuntimeClientPlugin.builder() |
| 85 | + .withConventions(AwsDependency.MIDDLEWARE_ENDPOINT_DISCOVERY.dependency, |
| 86 | + "EndpointDiscoveryOptional", RuntimeClientPlugin.Convention.HAS_MIDDLEWARE) |
| 87 | + .additionalResolveFunctionParameters(new String[]{"clientStack", "options"}) |
| 88 | + .operationPredicate((m, s, o) -> isClientDiscoveredEndpointOptional(s, o)) |
73 | 89 | .build()
|
| 90 | + |
74 | 91 | );
|
75 | 92 | }
|
76 | 93 |
|
@@ -125,9 +142,23 @@ private void addEndpointDiscoveryCommandImport(
|
125 | 142 | }
|
126 | 143 |
|
127 | 144 | private static boolean hasClientEndpointDiscovery(ServiceShape service) {
|
128 |
| - if(service.getTrait(ClientEndpointDiscoveryTrait.class).isPresent()) { |
| 145 | + if(service.hasTrait(ClientEndpointDiscoveryTrait.class)) { |
129 | 146 | return true;
|
130 | 147 | }
|
131 | 148 | return false;
|
132 | 149 | }
|
| 150 | + |
| 151 | + private static boolean isClientDiscoveredEndpointRequired(ServiceShape service, OperationShape operation) { |
| 152 | + if (hasClientEndpointDiscovery(service) && operation.hasTrait(ClientDiscoveredEndpointTrait.class)) { |
| 153 | + return operation.getTrait(ClientDiscoveredEndpointTrait.class).orElse(null).isRequired(); |
| 154 | + } |
| 155 | + return false; |
| 156 | + } |
| 157 | + |
| 158 | + private static boolean isClientDiscoveredEndpointOptional(ServiceShape service, OperationShape operation) { |
| 159 | + if (!hasClientEndpointDiscovery(service) && operation.hasTrait(ClientDiscoveredEndpointTrait.class)) { |
| 160 | + return !operation.getTrait(ClientDiscoveredEndpointTrait.class).orElse(null).isRequired(); |
| 161 | + } |
| 162 | + return false; |
| 163 | + } |
133 | 164 | }
|
0 commit comments