diff --git a/smithy-typescript-codegen-test/example-weather-customizations/src/main/java/example/weather/GenericTestAddCustomEndpointsRuntimeConfig.java b/smithy-typescript-codegen-test/example-weather-customizations/src/main/java/example/weather/ExampleWeatherCustomEndpointsRuntimeConfig.java similarity index 83% rename from smithy-typescript-codegen-test/example-weather-customizations/src/main/java/example/weather/GenericTestAddCustomEndpointsRuntimeConfig.java rename to smithy-typescript-codegen-test/example-weather-customizations/src/main/java/example/weather/ExampleWeatherCustomEndpointsRuntimeConfig.java index 9eae6bcc46f..5a5c3946812 100644 --- a/smithy-typescript-codegen-test/example-weather-customizations/src/main/java/example/weather/GenericTestAddCustomEndpointsRuntimeConfig.java +++ b/smithy-typescript-codegen-test/example-weather-customizations/src/main/java/example/weather/ExampleWeatherCustomEndpointsRuntimeConfig.java @@ -15,6 +15,8 @@ import software.amazon.smithy.codegen.core.SymbolProvider; import software.amazon.smithy.model.Model; import software.amazon.smithy.model.shapes.ShapeId; +import software.amazon.smithy.model.shapes.ToShapeId; +import software.amazon.smithy.rulesengine.traits.EndpointRuleSetTrait; import software.amazon.smithy.typescript.codegen.CodegenUtils; import software.amazon.smithy.typescript.codegen.Dependency; import software.amazon.smithy.typescript.codegen.LanguageTarget; @@ -29,7 +31,7 @@ import software.amazon.smithy.utils.SmithyInternalApi; @SmithyInternalApi -public final class GenericTestAddCustomEndpointsRuntimeConfig implements TypeScriptIntegration { +public final class ExampleWeatherCustomEndpointsRuntimeConfig implements TypeScriptIntegration { public static final String GENERIC_TEST_DIR = Paths.get(".", CodegenUtils.SOURCE_FOLDER, "generic").toString(); public static final String INDEX_MODULE = GENERIC_TEST_DIR + "/index"; public static final String INDEX_FILE = INDEX_MODULE + ".ts"; @@ -37,7 +39,8 @@ public final class GenericTestAddCustomEndpointsRuntimeConfig implements TypeScr public static final String getClientFile(ShapeId service) { return Paths.get(".", CodegenUtils.SOURCE_FOLDER, service.getName() + "Client.ts").toString(); } - + public static final ShapeId EXAMPLE_WEATHER_SERVICE_ID = ShapeId.from("example.weather#Weather"); + @Override public List getClientPlugins() { return List.of( @@ -54,10 +57,12 @@ public List getClientPlugins() { .namespace(INDEX_MODULE, "/") .name("resolveGenericCustomEndpointsConfig") .build()) + .servicePredicate((m, s) -> isExampleWeatherService(s)) .build(), RuntimeClientPlugin.builder() .withConventions( TypeScriptDependency.MIDDLEWARE_ENDPOINTS_V2.dependency, "Endpoint", Convention.HAS_CONFIG) + .servicePredicate((m, s) -> isExampleWeatherService(s)) .build()); } @@ -67,12 +72,18 @@ public void customize(TypeScriptCodegenContext codegenContext) { return; } + if (!isExampleWeatherService(codegenContext.settings().getService())) { + return; + } + codegenContext.writerDelegator().useFileWriter(INDEX_FILE, w -> { w.write("export * from \"./customEndpoints\";"); }); codegenContext.writerDelegator().useFileWriter(getClientFile(codegenContext.settings().getService()), w -> { - w.addImport("EndpointParameters", null, EndpointsV2Generator.ENDPOINT_PARAMETERS_DEPENDENCY); + if (codegenContext.settings().getService(codegenContext.model()).hasTrait(EndpointRuleSetTrait.ID)) { + w.addImport("EndpointParameters", null, EndpointsV2Generator.ENDPOINT_PARAMETERS_DEPENDENCY); + } }); codegenContext.writerDelegator().useFileWriter(ADD_CUSTOM_ENDPOINTS_FILE, w -> { @@ -102,4 +113,8 @@ export interface GenericCustomEndpointsResolvedConfig { """); }); } + + private static boolean isExampleWeatherService(ToShapeId toShapeId) { + return toShapeId.toShapeId().equals(EXAMPLE_WEATHER_SERVICE_ID); + } } diff --git a/smithy-typescript-codegen-test/example-weather-customizations/src/main/resources/META-INF/services/software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration b/smithy-typescript-codegen-test/example-weather-customizations/src/main/resources/META-INF/services/software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration index c940b731ff6..93c3c677e46 100644 --- a/smithy-typescript-codegen-test/example-weather-customizations/src/main/resources/META-INF/services/software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration +++ b/smithy-typescript-codegen-test/example-weather-customizations/src/main/resources/META-INF/services/software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration @@ -1 +1 @@ -example.weather.GenericTestAddCustomEndpointsRuntimeConfig +example.weather.ExampleWeatherCustomEndpointsRuntimeConfig diff --git a/smithy-typescript-codegen-test/model/common/fakeAuth.smithy b/smithy-typescript-codegen-test/model/common/fakeAuth.smithy new file mode 100644 index 00000000000..5c0be97c0a7 --- /dev/null +++ b/smithy-typescript-codegen-test/model/common/fakeAuth.smithy @@ -0,0 +1,7 @@ +$version: "2.0" + +namespace common + +@trait +@authDefinition +structure fakeAuth {} diff --git a/smithy-typescript-codegen-test/model/common/fakeProtocol.smithy b/smithy-typescript-codegen-test/model/common/fakeProtocol.smithy new file mode 100644 index 00000000000..eb39ed58b3b --- /dev/null +++ b/smithy-typescript-codegen-test/model/common/fakeProtocol.smithy @@ -0,0 +1,7 @@ +$version: "2.0" + +namespace common + +@trait +@protocolDefinition +structure fakeProtocol {} diff --git a/smithy-typescript-codegen-test/model/main.smithy b/smithy-typescript-codegen-test/model/weather/main.smithy similarity index 93% rename from smithy-typescript-codegen-test/model/main.smithy rename to smithy-typescript-codegen-test/model/weather/main.smithy index cc8bb5883e1..9315ccb6a39 100644 --- a/smithy-typescript-codegen-test/model/main.smithy +++ b/smithy-typescript-codegen-test/model/weather/main.smithy @@ -6,17 +6,15 @@ use aws.auth#sigv4 use smithy.test#httpRequestTests use smithy.test#httpResponseTests use smithy.waiters#waitable - -@authDefinition -@trait -structure customAuth {} +use common#fakeProtocol +use common#fakeAuth /// Provides weather forecasts. @fakeProtocol @httpApiKeyAuth(name: "X-Api-Key", in: "header") @httpBearerAuth @sigv4(name: "weather") -@customAuth +@fakeAuth @auth([sigv4]) @paginated(inputToken: "nextToken", outputToken: "nextToken", pageSize: "pageSize") service Weather { @@ -35,8 +33,8 @@ service Weather { OnlyHttpApiKeyAndBearerAuthReversed OnlySigv4Auth OnlySigv4AuthOptional - OnlyCustomAuth - OnlyCustomAuthOptional + OnlyFakeAuth + OnlyFakeAuthOptional SameAsService ] } @@ -76,14 +74,14 @@ operation OnlyHttpBearerAuthOptional {} @optionalAuth operation OnlySigv4AuthOptional {} -@http(method: "GET", uri: "/OnlyCustomAuth") -@auth([customAuth]) -operation OnlyCustomAuth {} +@http(method: "GET", uri: "/OnlyFakeAuth") +@auth([fakeAuth]) +operation OnlyFakeAuth {} -@http(method: "GET", uri: "/OnlyCustomAuthOptional") -@auth([customAuth]) +@http(method: "GET", uri: "/OnlyFakeAuthOptional") +@auth([fakeAuth]) @optionalAuth -operation OnlyCustomAuthOptional {} +operation OnlyFakeAuthOptional {} @http(method: "GET", uri: "/SameAsService") operation SameAsService {} @@ -126,7 +124,7 @@ apply GetCity @httpRequestTests( { id: "WriteGetCityAssertions" documentation: "Does something" - protocol: "example.weather#fakeProtocol" + protocol: "common#fakeProtocol" method: "GET" uri: "/cities/123" body: "" @@ -140,7 +138,7 @@ apply GetCity @httpResponseTests( { id: "WriteGetCityResponseAssertions" documentation: "Does something" - protocol: "example.weather#fakeProtocol" + protocol: "common#fakeProtocol" code: 200 body: """ { @@ -234,7 +232,7 @@ apply NoSuchResource @httpResponseTests( { id: "WriteNoSuchResourceAssertions" documentation: "Does something" - protocol: "example.weather#fakeProtocol" + protocol: "common#fakeProtocol" code: 404 body: """ { @@ -279,7 +277,7 @@ apply ListCities @httpRequestTests( { id: "WriteListCitiesAssertions" documentation: "Does something" - protocol: "example.weather#fakeProtocol" + protocol: "common#fakeProtocol" method: "GET" uri: "/cities" body: "" @@ -462,11 +460,6 @@ structure Message { author: String } -// Define a fake protocol trait for use. -@trait -@protocolDefinition -structure fakeProtocol {} - apply Weather @smithy.rules#endpointRuleSet({ "version": "1.3", "parameters": { @@ -492,4 +485,4 @@ apply Weather @smithy.rules#endpointRuleSet({ apply Weather @smithy.rules#clientContextParams( Region: {type: "string", documentation: "docs"} -) \ No newline at end of file +) diff --git a/smithy-typescript-codegen-test/model/more-nesting.smithy b/smithy-typescript-codegen-test/model/weather/more-nesting.smithy similarity index 100% rename from smithy-typescript-codegen-test/model/more-nesting.smithy rename to smithy-typescript-codegen-test/model/weather/more-nesting.smithy diff --git a/smithy-typescript-codegen-test/model/nested.smithy b/smithy-typescript-codegen-test/model/weather/nested.smithy similarity index 100% rename from smithy-typescript-codegen-test/model/nested.smithy rename to smithy-typescript-codegen-test/model/weather/nested.smithy diff --git a/smithy-typescript-codegen-test/smithy-build.json b/smithy-typescript-codegen-test/smithy-build.json index aacfa85f24f..f2166e741ba 100644 --- a/smithy-typescript-codegen-test/smithy-build.json +++ b/smithy-typescript-codegen-test/smithy-build.json @@ -8,6 +8,12 @@ "args": { "tags": ["client-only"] } + }, + { + "name": "includeServices", + "args": { + "services": ["example.weather#Weather"] + } } ], "plugins": { @@ -25,6 +31,14 @@ } }, "client-experimental-identity-and-auth": { + "transforms": [ + { + "name": "includeServices", + "args": { + "services": ["example.weather#Weather"] + } + } + ], "plugins": { "typescript-codegen": { "service": "example.weather#Weather", @@ -40,6 +54,14 @@ } }, "control-experimental-identity-and-auth": { + "transforms": [ + { + "name": "includeServices", + "args": { + "services": ["example.weather#Weather"] + } + } + ], "plugins": { "typescript-codegen": { "service": "example.weather#Weather", diff --git a/smithy-typescript-ssdk-codegen-test-utils/src/main/java/software/amazon/smithy/typescript/ssdk/codegen/test/utils/TestProtocolGenerator.java b/smithy-typescript-ssdk-codegen-test-utils/src/main/java/software/amazon/smithy/typescript/ssdk/codegen/test/utils/TestProtocolGenerator.java index c04c5cea3f2..4d5b18112c7 100644 --- a/smithy-typescript-ssdk-codegen-test-utils/src/main/java/software/amazon/smithy/typescript/ssdk/codegen/test/utils/TestProtocolGenerator.java +++ b/smithy-typescript-ssdk-codegen-test-utils/src/main/java/software/amazon/smithy/typescript/ssdk/codegen/test/utils/TestProtocolGenerator.java @@ -26,7 +26,7 @@ class TestProtocolGenerator extends HttpBindingProtocolGenerator { @Override public ShapeId getProtocol() { - return ShapeId.from("example.weather#fakeProtocol"); + return ShapeId.from("common#fakeProtocol"); } @Override