From 64316e71eea2b4452d0d9b57e351948631792951 Mon Sep 17 00:00:00 2001 From: kstich Date: Thu, 28 Sep 2023 10:57:56 -0700 Subject: [PATCH] Update endpoint rules engine tests --- gradle.properties | 2 +- .../model/main.smithy | 355 ++---------------- .../endpointsV2/EndpointsV2GeneratorTest.java | 6 +- .../codegen/endpointsV2/endpoints.smithy | 4 +- 4 files changed, 28 insertions(+), 339 deletions(-) diff --git a/gradle.properties b/gradle.properties index 72c015a99ef..d539ea0b591 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -smithyVersion=1.37.0 +smithyVersion=1.39.0 smithyGradleVersion=0.6.0 diff --git a/smithy-typescript-codegen-test/model/main.smithy b/smithy-typescript-codegen-test/model/main.smithy index 00a49baac90..cc8bb5883e1 100644 --- a/smithy-typescript-codegen-test/model/main.smithy +++ b/smithy-typescript-codegen-test/model/main.smithy @@ -467,342 +467,29 @@ structure Message { @protocolDefinition structure fakeProtocol {} -apply Weather @smithy.rules#endpointRuleSet( { - "version": "1.0", - "parameters": { +apply Weather @smithy.rules#endpointRuleSet({ + "version": "1.3", + "parameters": { "Region": { - "builtIn": "AWS::Region", - "required": false, - "documentation": "The AWS region used to dispatch the request.", - "type": "String" - }, - "UseDualStack": { - "builtIn": "AWS::UseDualStack", - "required": true, - "default": false, - "documentation": "When true, use the dual-stack endpoint. If the configured endpoint does not support dual-stack, dispatching the request MAY return an error.", - "type": "Boolean" - }, - "UseFIPS": { - "builtIn": "AWS::UseFIPS", - "required": true, - "default": false, - "documentation": "When true, send this request to the FIPS-compliant regional endpoint. If the configured endpoint does not have a FIPS compliant endpoint, dispatching the request will return an error.", - "type": "Boolean" - }, - "Endpoint": { - "builtIn": "SDK::Endpoint", - "required": false, - "documentation": "Override the endpoint used to send this request", - "type": "String" + "required": true, + "type": "String", + "documentation": "docs" } - }, - "rules": [ + }, + "rules": [ { - "conditions": [ - { - "fn": "isSet", - "argv": [ - { - "ref": "Endpoint" - } - ] - } - ], - "type": "tree", - "rules": [ - { - "conditions": [ - { - "fn": "booleanEquals", - "argv": [ - { - "ref": "UseFIPS" - }, - true - ] - } - ], - "error": "Invalid Configuration: FIPS and custom endpoint are not supported", - "type": "error" - }, - { - "conditions": [ - { - "fn": "booleanEquals", - "argv": [ - { - "ref": "UseDualStack" - }, - true - ] - } - ], - "error": "Invalid Configuration: Dualstack and custom endpoint are not supported", - "type": "error" - }, - { - "conditions": [], - "endpoint": { - "url": { - "ref": "Endpoint" - }, - "properties": {}, - "headers": {} - }, - "type": "endpoint" - } - ] - }, - { - "conditions": [ - { - "fn": "isSet", - "argv": [ - { - "ref": "Region" - } - ] - } - ], - "type": "tree", - "rules": [ - { - "conditions": [ - { - "fn": "aws.partition", - "argv": [ - { - "ref": "Region" - } - ], - "assign": "PartitionResult" - } - ], - "type": "tree", - "rules": [ - { - "conditions": [ - { - "fn": "booleanEquals", - "argv": [ - { - "ref": "UseFIPS" - }, - true - ] - }, - { - "fn": "booleanEquals", - "argv": [ - { - "ref": "UseDualStack" - }, - true - ] - } - ], - "type": "tree", - "rules": [ - { - "conditions": [ - { - "fn": "booleanEquals", - "argv": [ - true, - { - "fn": "getAttr", - "argv": [ - { - "ref": "PartitionResult" - }, - "supportsFIPS" - ] - } - ] - }, - { - "fn": "booleanEquals", - "argv": [ - true, - { - "fn": "getAttr", - "argv": [ - { - "ref": "PartitionResult" - }, - "supportsDualStack" - ] - } - ] - } - ], - "type": "tree", - "rules": [ - { - "conditions": [], - "endpoint": { - "url": "https://weather-fips.{Region}.{PartitionResult#dualStackDnsSuffix}", - "properties": {}, - "headers": {} - }, - "type": "endpoint" - } - ] - }, - { - "conditions": [], - "error": "FIPS and DualStack are enabled, but this partition does not support one or both", - "type": "error" - } - ] - }, - { - "conditions": [ - { - "fn": "booleanEquals", - "argv": [ - { - "ref": "UseFIPS" - }, - true - ] - } - ], - "type": "tree", - "rules": [ - { - "conditions": [ - { - "fn": "booleanEquals", - "argv": [ - true, - { - "fn": "getAttr", - "argv": [ - { - "ref": "PartitionResult" - }, - "supportsFIPS" - ] - } - ] - } - ], - "type": "tree", - "rules": [ - { - "conditions": [ - { - "fn": "stringEquals", - "argv": [ - "aws-us-gov", - { - "fn": "getAttr", - "argv": [ - { - "ref": "PartitionResult" - }, - "name" - ] - } - ] - } - ], - "endpoint": { - "url": "https://weather.{Region}.amazonaws.com", - "properties": {}, - "headers": {} - }, - "type": "endpoint" - }, - { - "conditions": [], - "endpoint": { - "url": "https://weather-fips.{Region}.{PartitionResult#dnsSuffix}", - "properties": {}, - "headers": {} - }, - "type": "endpoint" - } - ] - }, - { - "conditions": [], - "error": "FIPS is enabled but this partition does not support FIPS", - "type": "error" - } - ] - }, - { - "conditions": [ - { - "fn": "booleanEquals", - "argv": [ - { - "ref": "UseDualStack" - }, - true - ] - } - ], - "type": "tree", - "rules": [ - { - "conditions": [ - { - "fn": "booleanEquals", - "argv": [ - true, - { - "fn": "getAttr", - "argv": [ - { - "ref": "PartitionResult" - }, - "supportsDualStack" - ] - } - ] - } - ], - "type": "tree", - "rules": [ - { - "conditions": [], - "endpoint": { - "url": "https://weather.{Region}.{PartitionResult#dualStackDnsSuffix}", - "properties": {}, - "headers": {} - }, - "type": "endpoint" - } - ] - }, - { - "conditions": [], - "error": "DualStack is enabled but this partition does not support DualStack", - "type": "error" - } - ] - }, - { - "conditions": [], - "endpoint": { - "url": "https://weather.{Region}.{PartitionResult#dnsSuffix}", - "properties": {}, - "headers": {} - }, - "type": "endpoint" - } - ] - } - ] - }, - { - "conditions": [], - "error": "Invalid Configuration: Missing Region", - "type": "error" + "conditions": [], + "documentation": "base rule", + "endpoint": { + "url": "https://{Region}.amazonaws.com", + "properties": {}, + "headers": {} + }, + "type": "endpoint" } - ] + ] }) + +apply Weather @smithy.rules#clientContextParams( + Region: {type: "string", documentation: "docs"} +) \ No newline at end of file diff --git a/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/endpointsV2/EndpointsV2GeneratorTest.java b/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/endpointsV2/EndpointsV2GeneratorTest.java index ea64d04d2a2..544df2093f1 100644 --- a/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/endpointsV2/EndpointsV2GeneratorTest.java +++ b/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/endpointsV2/EndpointsV2GeneratorTest.java @@ -52,10 +52,14 @@ public void containsExtraContextParameter() { assertThat(endpointParameters, containsString( " return {\n" + " ...options,\n" + - " region: options.region ?? \"us-east-1\",\n" + " stage: options.stage ?? \"production\",\n" + " defaultSigningName: \"\",\n" + " }\n")); + assertThat(endpointParameters, containsString( + "export interface ClientInputEndpointParameters {\n" + + " region?: string|Provider;\n" + + " stage?: string|Provider;\n" + + " endpoint?:")); } private MockManifest testEndpoints(String filename) { diff --git a/smithy-typescript-codegen/src/test/resources/software/amazon/smithy/typescript/codegen/endpointsV2/endpoints.smithy b/smithy-typescript-codegen/src/test/resources/software/amazon/smithy/typescript/codegen/endpointsV2/endpoints.smithy index 1b739782d59..84b4291bf0d 100644 --- a/smithy-typescript-codegen/src/test/resources/software/amazon/smithy/typescript/codegen/endpointsV2/endpoints.smithy +++ b/smithy-typescript-codegen/src/test/resources/software/amazon/smithy/typescript/codegen/endpointsV2/endpoints.smithy @@ -6,10 +6,7 @@ namespace smithy.example "version": "1.3" "parameters": { "Region": { - "builtIn": "AWS::Region", "type": "String", - "required": true, - "default": "us-east-1", "documentation": "The region to dispatch this request, eg. `us-east-1`." }, "Stage": { @@ -108,6 +105,7 @@ namespace smithy.example }) @smithy.rules#clientContextParams( Stage: {type: "string", documentation: "The endpoint stage used to construct the hostname."} + Region: {type: "string", documentation: "The region to dispatch this request, eg. `us-east-1`."} ) service Example { version: "2023-01-01"