From 27701ce959330af0fb0a764f681fc0bb75381350 Mon Sep 17 00:00:00 2001 From: Sean O'Brien <60306702+stobrien89@users.noreply.github.com> Date: Tue, 17 Nov 2026 13:37:57 -0500 Subject: [PATCH 1/3] Bump generated runtime pins to smithy-core 0.13 and smithy-http 0.10 --- codegen-output-py/aws-json-1-0/.smithy-python-manifest.json | 2 +- codegen-output-py/aws-json-1-0/pyproject.toml | 2 +- codegen-output-py/aws-json-1-1/.smithy-python-manifest.json | 2 +- codegen-output-py/aws-json-1-1/pyproject.toml | 2 +- codegen-output-py/aws-query/.smithy-python-manifest.json | 2 +- codegen-output-py/aws-query/pyproject.toml | 2 +- codegen-output-py/ec2-query/.smithy-python-manifest.json | 2 +- codegen-output-py/ec2-query/pyproject.toml | 2 +- .../my-handwritten-json-model/.smithy-python-manifest.json | 2 +- codegen-output-py/my-handwritten-json-model/pyproject.toml | 2 +- .../my-handwritten-model/.smithy-python-manifest.json | 2 +- codegen-output-py/my-handwritten-model/pyproject.toml | 2 +- .../.smithy-python-manifest.json | 2 +- .../non-query-compatible-rpcv2-cbor/pyproject.toml | 2 +- .../partitioned-types/.smithy-python-manifest.json | 2 +- codegen-output-py/partitioned-types/pyproject.toml | 2 +- .../.smithy-python-manifest.json | 2 +- .../query-compatible-aws-json-1-0/pyproject.toml | 2 +- .../.smithy-python-manifest.json | 2 +- .../query-compatible-rpcv2-cbor/pyproject.toml | 2 +- codegen-output-py/rest-json-1/.smithy-python-manifest.json | 2 +- codegen-output-py/rest-json-1/pyproject.toml | 2 +- .../rest-xml-with-namespace/.smithy-python-manifest.json | 2 +- codegen-output-py/rest-xml-with-namespace/pyproject.toml | 2 +- codegen-output-py/rest-xml/.smithy-python-manifest.json | 2 +- codegen-output-py/rest-xml/pyproject.toml | 2 +- .../rpcv2-cbor-client/.smithy-python-manifest.json | 2 +- codegen-output-py/rpcv2-cbor-client/pyproject.toml | 4 ++-- codegen-output-py/rpcv2-cbor/.smithy-python-manifest.json | 2 +- codegen-output-py/rpcv2-cbor/pyproject.toml | 2 +- .../rpcv2-json-client/.smithy-python-manifest.json | 2 +- codegen-output-py/rpcv2-json-client/pyproject.toml | 4 ++-- codegen-output-py/rpcv2-json/.smithy-python-manifest.json | 2 +- codegen-output-py/rpcv2-json/pyproject.toml | 2 +- codegen-output-py/types/.smithy-python-manifest.json | 2 +- codegen-output-py/types/pyproject.toml | 2 +- ...-python-dependency-83bf4597c4cc4803833098d4ec9bce3f.json | 4 ++++ packages/smithy-python/src/smithy_python/dependencies.py | 4 ++-- packages/smithy-python/tests/unit/test_cli.py | 6 +++--- packages/smithy-python/tests/unit/test_dependencies.py | 4 ++-- 40 files changed, 49 insertions(+), 45 deletions(-) create mode 100644 packages/smithy-python/.changes/next-release/smithy-python-dependency-83bf4597c4cc4803833098d4ec9bce3f.json diff --git a/codegen-output-py/aws-json-1-0/.smithy-python-manifest.json b/codegen-output-py/aws-json-1-0/.smithy-python-manifest.json index 02bf6b261..418b42cce 100644 --- a/codegen-output-py/aws-json-1-0/.smithy-python-manifest.json +++ b/codegen-output-py/aws-json-1-0/.smithy-python-manifest.json @@ -1,7 +1,7 @@ { "files": { "README.md": "767e060d5d96f9a0ca03b7855b5c44f45c5b06969c3246b7e7f03fefb92300ec", - "pyproject.toml": "2b96d5ebbac8419f577edb844746bc7aae73354a671e05609e3b19314ea70d54", + "pyproject.toml": "015c1e66e81c31e73cf4eecca096b1f9f6fab83f4627d7c40c0c74f016d3a3d4", "src/awsjson10/__init__.py": "619a033058229139a02f912a44a6b8997fb35c5af6736d09edd49927876a49dd", "src/awsjson10/_private/__init__.py": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "src/awsjson10/_private/schemas.py": "80a90081368257ec9ab1f1518ac786c6b68191b08bdd591de11899e5510aaeae", diff --git a/codegen-output-py/aws-json-1-0/pyproject.toml b/codegen-output-py/aws-json-1-0/pyproject.toml index 7cb4dc9ba..961218f39 100644 --- a/codegen-output-py/aws-json-1-0/pyproject.toml +++ b/codegen-output-py/aws-json-1-0/pyproject.toml @@ -9,7 +9,7 @@ requires-python = ">=3.12" keywords = ["smithy", "awsjson10"] license = {text = "Apache-2.0"} dependencies = [ - "smithy-core~=0.12.0", + "smithy-core~=0.13.0", ] [build-system] diff --git a/codegen-output-py/aws-json-1-1/.smithy-python-manifest.json b/codegen-output-py/aws-json-1-1/.smithy-python-manifest.json index 2009f60ae..2205c1b51 100644 --- a/codegen-output-py/aws-json-1-1/.smithy-python-manifest.json +++ b/codegen-output-py/aws-json-1-1/.smithy-python-manifest.json @@ -1,7 +1,7 @@ { "files": { "README.md": "c4647f521c7bef71503b8a7d4d6cf0619345113a39bd0f32e683951ab170d284", - "pyproject.toml": "b58dac143dc87a184035ed8d111246ef15ddcc575bff1d9aa8aeedf966900f34", + "pyproject.toml": "48daaedd63df476c8ae1cf456b7cbd26de6d1556f4efff8a04533bcfbc84a49f", "src/awsjson11/__init__.py": "619a033058229139a02f912a44a6b8997fb35c5af6736d09edd49927876a49dd", "src/awsjson11/_private/__init__.py": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "src/awsjson11/_private/schemas.py": "9e4916f6f66be35ae119fad66e5fdbaa277a2d4f4c6b70b29f2b22065636273d", diff --git a/codegen-output-py/aws-json-1-1/pyproject.toml b/codegen-output-py/aws-json-1-1/pyproject.toml index 6939d6d25..b9d4acb6e 100644 --- a/codegen-output-py/aws-json-1-1/pyproject.toml +++ b/codegen-output-py/aws-json-1-1/pyproject.toml @@ -9,7 +9,7 @@ requires-python = ">=3.12" keywords = ["smithy", "awsjson11"] license = {text = "Apache-2.0"} dependencies = [ - "smithy-core~=0.12.0", + "smithy-core~=0.13.0", ] [build-system] diff --git a/codegen-output-py/aws-query/.smithy-python-manifest.json b/codegen-output-py/aws-query/.smithy-python-manifest.json index 1d786558f..0d658b9d4 100644 --- a/codegen-output-py/aws-query/.smithy-python-manifest.json +++ b/codegen-output-py/aws-query/.smithy-python-manifest.json @@ -1,7 +1,7 @@ { "files": { "README.md": "34e2e1a81a1bbc2412be2320d53c78a5c9d2557492c0a2a8826d60f7b12888a4", - "pyproject.toml": "8e62d7233cff08ab5afed75e1aaff7686bac750107937b4b6ebf26ce3c18262a", + "pyproject.toml": "393253cb05bfded5a02393b1f94c88b60a74901ba4e6cf3b7b75fb2a2a1ec8dd", "src/awsquery/__init__.py": "619a033058229139a02f912a44a6b8997fb35c5af6736d09edd49927876a49dd", "src/awsquery/_private/__init__.py": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "src/awsquery/_private/schemas.py": "c38f4206d96ebbbb13b43fb9de87fc8f210e49b2ebb5936213bc1586faaa5f4f", diff --git a/codegen-output-py/aws-query/pyproject.toml b/codegen-output-py/aws-query/pyproject.toml index 86f3a821f..c1a24ae9c 100644 --- a/codegen-output-py/aws-query/pyproject.toml +++ b/codegen-output-py/aws-query/pyproject.toml @@ -9,7 +9,7 @@ requires-python = ">=3.12" keywords = ["smithy", "awsquery"] license = {text = "Apache-2.0"} dependencies = [ - "smithy-core~=0.12.0", + "smithy-core~=0.13.0", ] [build-system] diff --git a/codegen-output-py/ec2-query/.smithy-python-manifest.json b/codegen-output-py/ec2-query/.smithy-python-manifest.json index 851c8997a..8daacc7d0 100644 --- a/codegen-output-py/ec2-query/.smithy-python-manifest.json +++ b/codegen-output-py/ec2-query/.smithy-python-manifest.json @@ -1,7 +1,7 @@ { "files": { "README.md": "88060523405669e4b71bf32d9f2888d510765cf5d1aa0514b652de95144609a1", - "pyproject.toml": "358fdd421084b9ee092ab914fc88d6c7ccd49845076c9f8022714a8862784707", + "pyproject.toml": "e0809d90933a2cb59f46fb11358c808d44caf077317a0761a4f81c797fc99fde", "src/ec2query/__init__.py": "619a033058229139a02f912a44a6b8997fb35c5af6736d09edd49927876a49dd", "src/ec2query/_private/__init__.py": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "src/ec2query/_private/schemas.py": "d5aed93dfd4bcd0e2352724f6390abe866531874f9e6b74ca01c71fc06b99ad1", diff --git a/codegen-output-py/ec2-query/pyproject.toml b/codegen-output-py/ec2-query/pyproject.toml index 7fef4dc2e..868f7354a 100644 --- a/codegen-output-py/ec2-query/pyproject.toml +++ b/codegen-output-py/ec2-query/pyproject.toml @@ -9,7 +9,7 @@ requires-python = ">=3.12" keywords = ["smithy", "ec2query"] license = {text = "Apache-2.0"} dependencies = [ - "smithy-core~=0.12.0", + "smithy-core~=0.13.0", ] [build-system] diff --git a/codegen-output-py/my-handwritten-json-model/.smithy-python-manifest.json b/codegen-output-py/my-handwritten-json-model/.smithy-python-manifest.json index 8b94470d8..c7f27f55c 100644 --- a/codegen-output-py/my-handwritten-json-model/.smithy-python-manifest.json +++ b/codegen-output-py/my-handwritten-json-model/.smithy-python-manifest.json @@ -1,7 +1,7 @@ { "files": { "README.md": "b62b9017d3b5f4ac588458f462dcf7da6232f960f8aac1d5ed16a4be3bd34695", - "pyproject.toml": "321817c332d0760a244c76bedaf7a21c70d92254ab9458b533f347c3860d4db4", + "pyproject.toml": "fd99e271e1a36a59f98e45c6bcd00ed94795312d19a9c5844e334a3b3b2f47a4", "src/my_handwritten_json_model/__init__.py": "619a033058229139a02f912a44a6b8997fb35c5af6736d09edd49927876a49dd", "src/my_handwritten_json_model/_private/__init__.py": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "src/my_handwritten_json_model/_private/schemas.py": "1a1bbc8bafb312919b994a51fc106c76578e1cffa9032fe9bbd9a02c0b102426", diff --git a/codegen-output-py/my-handwritten-json-model/pyproject.toml b/codegen-output-py/my-handwritten-json-model/pyproject.toml index a59e9c533..33bfc4edc 100644 --- a/codegen-output-py/my-handwritten-json-model/pyproject.toml +++ b/codegen-output-py/my-handwritten-json-model/pyproject.toml @@ -9,7 +9,7 @@ requires-python = ">=3.12" keywords = ["smithy", "my_handwritten_json_model"] license = {text = "Apache-2.0"} dependencies = [ - "smithy-core~=0.12.0", + "smithy-core~=0.13.0", ] [build-system] diff --git a/codegen-output-py/my-handwritten-model/.smithy-python-manifest.json b/codegen-output-py/my-handwritten-model/.smithy-python-manifest.json index c041ea733..39b5e7cb3 100644 --- a/codegen-output-py/my-handwritten-model/.smithy-python-manifest.json +++ b/codegen-output-py/my-handwritten-model/.smithy-python-manifest.json @@ -1,7 +1,7 @@ { "files": { "README.md": "47dc0fb73aa8673141f1fcde44fa3ba3995be83953b41c4f26e3ceb5c5b3ffda", - "pyproject.toml": "88e01463cc0d24fd7ab8bf99d96f0fe3b3f031f3348fc1c371c533c891184053", + "pyproject.toml": "7f629f025f463d2e7dc967cab569cc3c0e61c16738eeb1ac5ec0c97561487c10", "src/my_handwritten_model/__init__.py": "619a033058229139a02f912a44a6b8997fb35c5af6736d09edd49927876a49dd", "src/my_handwritten_model/_private/__init__.py": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "src/my_handwritten_model/_private/schemas.py": "dc76275b338c278172c30166e40c964952fdb5e9ae06f49dff33a37a58a39ff7", diff --git a/codegen-output-py/my-handwritten-model/pyproject.toml b/codegen-output-py/my-handwritten-model/pyproject.toml index 0dd267b42..f5991c5e8 100644 --- a/codegen-output-py/my-handwritten-model/pyproject.toml +++ b/codegen-output-py/my-handwritten-model/pyproject.toml @@ -9,7 +9,7 @@ requires-python = ">=3.12" keywords = ["smithy", "my_handwritten_model"] license = {text = "Apache-2.0"} dependencies = [ - "smithy-core~=0.12.0", + "smithy-core~=0.13.0", ] [build-system] diff --git a/codegen-output-py/non-query-compatible-rpcv2-cbor/.smithy-python-manifest.json b/codegen-output-py/non-query-compatible-rpcv2-cbor/.smithy-python-manifest.json index 580e625a9..de014f1ba 100644 --- a/codegen-output-py/non-query-compatible-rpcv2-cbor/.smithy-python-manifest.json +++ b/codegen-output-py/non-query-compatible-rpcv2-cbor/.smithy-python-manifest.json @@ -1,7 +1,7 @@ { "files": { "README.md": "0596f3af522471b12c17e5e2cb0f2e42bfeb3a7d910ca77e185f1bd493d12764", - "pyproject.toml": "e74dd66a00264ee014bb34b359a020d6ed1d5e5f384a9923cfcf73631d8967da", + "pyproject.toml": "7e8dbe8d60b2f1997c0c204eed60e7550b731c824efd53979df279e59375fe12", "src/nonquerycompatiblerpcv2cbor/__init__.py": "619a033058229139a02f912a44a6b8997fb35c5af6736d09edd49927876a49dd", "src/nonquerycompatiblerpcv2cbor/_private/__init__.py": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "src/nonquerycompatiblerpcv2cbor/_private/schemas.py": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", diff --git a/codegen-output-py/non-query-compatible-rpcv2-cbor/pyproject.toml b/codegen-output-py/non-query-compatible-rpcv2-cbor/pyproject.toml index ac39f6fbf..0faa7b411 100644 --- a/codegen-output-py/non-query-compatible-rpcv2-cbor/pyproject.toml +++ b/codegen-output-py/non-query-compatible-rpcv2-cbor/pyproject.toml @@ -9,7 +9,7 @@ requires-python = ">=3.12" keywords = ["smithy", "nonquerycompatiblerpcv2cbor"] license = {text = "Apache-2.0"} dependencies = [ - "smithy-core~=0.12.0", + "smithy-core~=0.13.0", ] [build-system] diff --git a/codegen-output-py/partitioned-types/.smithy-python-manifest.json b/codegen-output-py/partitioned-types/.smithy-python-manifest.json index 3ad916376..05716e662 100644 --- a/codegen-output-py/partitioned-types/.smithy-python-manifest.json +++ b/codegen-output-py/partitioned-types/.smithy-python-manifest.json @@ -1,7 +1,7 @@ { "files": { "README.md": "20221d6b4a6eb9d45105b926f3bf80197e6ed2bdcab748c5f15e9e6e28dd11ec", - "pyproject.toml": "43ff0dbf1cd3b0ea1027a275785a706c7d7053a900a803c17f7fe2b5a797d9d2", + "pyproject.toml": "7c77ad886214636fa2a9f6de5d491b190a407f619f3833af880309ce031a6a18", "src/partitioned_types/__init__.py": "27ea4bc5ba93a6fc6e1f11e9784565de24e9249f0d3e77a9e2fb64fa47d11012", "src/partitioned_types/_private/__init__.py": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "src/partitioned_types/_private/models_0.pyi": "43e2d95e8b75e1a63f4a6d7a60ead524045f688617e6433271a82b9d6eec3b95", diff --git a/codegen-output-py/partitioned-types/pyproject.toml b/codegen-output-py/partitioned-types/pyproject.toml index c965a36a2..78976b2f1 100644 --- a/codegen-output-py/partitioned-types/pyproject.toml +++ b/codegen-output-py/partitioned-types/pyproject.toml @@ -9,7 +9,7 @@ requires-python = ">=3.12" keywords = ["smithy", "partitioned_types"] license = {text = "Apache-2.0"} dependencies = [ - "smithy-core~=0.12.0", + "smithy-core~=0.13.0", ] [build-system] diff --git a/codegen-output-py/query-compatible-aws-json-1-0/.smithy-python-manifest.json b/codegen-output-py/query-compatible-aws-json-1-0/.smithy-python-manifest.json index 1f59b486f..873ab26e1 100644 --- a/codegen-output-py/query-compatible-aws-json-1-0/.smithy-python-manifest.json +++ b/codegen-output-py/query-compatible-aws-json-1-0/.smithy-python-manifest.json @@ -1,7 +1,7 @@ { "files": { "README.md": "9d9dc0e09a156d9f7690a98266d5ec9c0644da310a4906a8bf9c01597e72c931", - "pyproject.toml": "0d7b00d8e358af6de441ce92b3ebbd65ef41fa887501842f187db5551c331a64", + "pyproject.toml": "1e2b86bff158358e9ee032707c643205859bbbacf0eed1142b17f4579bc5df7e", "src/querycompatibleawsjson10/__init__.py": "619a033058229139a02f912a44a6b8997fb35c5af6736d09edd49927876a49dd", "src/querycompatibleawsjson10/_private/__init__.py": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "src/querycompatibleawsjson10/_private/schemas.py": "2f50162ef491662b8ce67108211e9e4720c37ba997d4fcdf5c686c7439f1660a", diff --git a/codegen-output-py/query-compatible-aws-json-1-0/pyproject.toml b/codegen-output-py/query-compatible-aws-json-1-0/pyproject.toml index f121ef8c6..893b0ca5a 100644 --- a/codegen-output-py/query-compatible-aws-json-1-0/pyproject.toml +++ b/codegen-output-py/query-compatible-aws-json-1-0/pyproject.toml @@ -9,7 +9,7 @@ requires-python = ">=3.12" keywords = ["smithy", "querycompatibleawsjson10"] license = {text = "Apache-2.0"} dependencies = [ - "smithy-core~=0.12.0", + "smithy-core~=0.13.0", ] [build-system] diff --git a/codegen-output-py/query-compatible-rpcv2-cbor/.smithy-python-manifest.json b/codegen-output-py/query-compatible-rpcv2-cbor/.smithy-python-manifest.json index c3a78a414..1d7d53b17 100644 --- a/codegen-output-py/query-compatible-rpcv2-cbor/.smithy-python-manifest.json +++ b/codegen-output-py/query-compatible-rpcv2-cbor/.smithy-python-manifest.json @@ -1,7 +1,7 @@ { "files": { "README.md": "ff19aa552a375f526c29baeaea614e7af167dea1461e78941b3375547b5d1e08", - "pyproject.toml": "c512a6a5f0446eb65281dd6a17758fcb46624f3edc159ed5d79a96dd9e19ce93", + "pyproject.toml": "906b14bcfbaa2a0df2c9703db740492f47092d9b6a3494d3fb8f576f2996b8c2", "src/querycompatiblerpcv2cbor/__init__.py": "619a033058229139a02f912a44a6b8997fb35c5af6736d09edd49927876a49dd", "src/querycompatiblerpcv2cbor/_private/__init__.py": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "src/querycompatiblerpcv2cbor/_private/schemas.py": "8bf49b97ee7af64900c0c5c2ebd4a41d740e2fa0a17c1be3f3d8f25a0d7d997c", diff --git a/codegen-output-py/query-compatible-rpcv2-cbor/pyproject.toml b/codegen-output-py/query-compatible-rpcv2-cbor/pyproject.toml index 6396984a7..b4f304f92 100644 --- a/codegen-output-py/query-compatible-rpcv2-cbor/pyproject.toml +++ b/codegen-output-py/query-compatible-rpcv2-cbor/pyproject.toml @@ -9,7 +9,7 @@ requires-python = ">=3.12" keywords = ["smithy", "querycompatiblerpcv2cbor"] license = {text = "Apache-2.0"} dependencies = [ - "smithy-core~=0.12.0", + "smithy-core~=0.13.0", ] [build-system] diff --git a/codegen-output-py/rest-json-1/.smithy-python-manifest.json b/codegen-output-py/rest-json-1/.smithy-python-manifest.json index 8c6cc5c26..cfbdba453 100644 --- a/codegen-output-py/rest-json-1/.smithy-python-manifest.json +++ b/codegen-output-py/rest-json-1/.smithy-python-manifest.json @@ -1,7 +1,7 @@ { "files": { "README.md": "ab6bb388bf358acca8bbf97c7dc3d54def01226a5e189d2b4ab762072b82c2c6", - "pyproject.toml": "1ae70465bf51189240e4a34dc9a0176ab133dcdf9ed0d3ad455054a13e13b21c", + "pyproject.toml": "21cf8a6cea8de2f645dc1edbb6adf5d5efefef76f930060da2c307e40efd5084", "src/restjson/__init__.py": "619a033058229139a02f912a44a6b8997fb35c5af6736d09edd49927876a49dd", "src/restjson/_private/__init__.py": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "src/restjson/_private/schemas.py": "133535695424fa890dd8cefb8f7f9957138813ae689c7d168e79763296813bcb", diff --git a/codegen-output-py/rest-json-1/pyproject.toml b/codegen-output-py/rest-json-1/pyproject.toml index 7ba322ddd..a724b1206 100644 --- a/codegen-output-py/rest-json-1/pyproject.toml +++ b/codegen-output-py/rest-json-1/pyproject.toml @@ -9,7 +9,7 @@ requires-python = ">=3.12" keywords = ["smithy", "restjson"] license = {text = "Apache-2.0"} dependencies = [ - "smithy-core~=0.12.0", + "smithy-core~=0.13.0", ] [build-system] diff --git a/codegen-output-py/rest-xml-with-namespace/.smithy-python-manifest.json b/codegen-output-py/rest-xml-with-namespace/.smithy-python-manifest.json index 0b8edac13..c8abb6759 100644 --- a/codegen-output-py/rest-xml-with-namespace/.smithy-python-manifest.json +++ b/codegen-output-py/rest-xml-with-namespace/.smithy-python-manifest.json @@ -1,7 +1,7 @@ { "files": { "README.md": "377281dbc896249f6395f7d63d1c0f4a3f8ed12dbe286778f00717980613ed4b", - "pyproject.toml": "ccdb41afb0a4ce2462ba7ef6c784070c136246fabc0e3d3bb6756a1940fb9a96", + "pyproject.toml": "79fabc6612ef976108a5b3950e297429a576c90f9563d1d75528a5bdd92533ff", "src/restxmlwithnamespace/__init__.py": "619a033058229139a02f912a44a6b8997fb35c5af6736d09edd49927876a49dd", "src/restxmlwithnamespace/_private/__init__.py": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "src/restxmlwithnamespace/_private/schemas.py": "bf8c282cb66ded22baad30d30ca84e9750c3135022ef1a0854cf4e95dc58c2bf", diff --git a/codegen-output-py/rest-xml-with-namespace/pyproject.toml b/codegen-output-py/rest-xml-with-namespace/pyproject.toml index c3f61837e..b82f04a8d 100644 --- a/codegen-output-py/rest-xml-with-namespace/pyproject.toml +++ b/codegen-output-py/rest-xml-with-namespace/pyproject.toml @@ -9,7 +9,7 @@ requires-python = ">=3.12" keywords = ["smithy", "restxmlwithnamespace"] license = {text = "Apache-2.0"} dependencies = [ - "smithy-core~=0.12.0", + "smithy-core~=0.13.0", ] [build-system] diff --git a/codegen-output-py/rest-xml/.smithy-python-manifest.json b/codegen-output-py/rest-xml/.smithy-python-manifest.json index 98e313974..5d5a20a06 100644 --- a/codegen-output-py/rest-xml/.smithy-python-manifest.json +++ b/codegen-output-py/rest-xml/.smithy-python-manifest.json @@ -1,7 +1,7 @@ { "files": { "README.md": "cb00d252893fb299db4c6569ec3abb219e606507fd61b8e45d46cfe0da47d35b", - "pyproject.toml": "d1086c2eecb5b2cab06fee98f74e396c88e0cc59a73cbad6c96b80e21bd92d4a", + "pyproject.toml": "545c322d1248cad579f4bbde139bfa7151208354650e401d0914e938b2339956", "src/restxml/__init__.py": "619a033058229139a02f912a44a6b8997fb35c5af6736d09edd49927876a49dd", "src/restxml/_private/__init__.py": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "src/restxml/_private/schemas.py": "5da8157a7bdd634430fd13506e7581cde70a6c5444f618ca6057f883290a046e", diff --git a/codegen-output-py/rest-xml/pyproject.toml b/codegen-output-py/rest-xml/pyproject.toml index 87eba63e8..b01c81c10 100644 --- a/codegen-output-py/rest-xml/pyproject.toml +++ b/codegen-output-py/rest-xml/pyproject.toml @@ -9,7 +9,7 @@ requires-python = ">=3.12" keywords = ["smithy", "restxml"] license = {text = "Apache-2.0"} dependencies = [ - "smithy-core~=0.12.0", + "smithy-core~=0.13.0", ] [build-system] diff --git a/codegen-output-py/rpcv2-cbor-client/.smithy-python-manifest.json b/codegen-output-py/rpcv2-cbor-client/.smithy-python-manifest.json index f23291b6b..e4edf86f6 100644 --- a/codegen-output-py/rpcv2-cbor-client/.smithy-python-manifest.json +++ b/codegen-output-py/rpcv2-cbor-client/.smithy-python-manifest.json @@ -1,7 +1,7 @@ { "files": { "README.md": "5342d0e6fd3d9d50c76bad8f4c6559812437b588fc964cf42f4f7706d0b327f6", - "pyproject.toml": "38923f97ee0bdf96de5de4aa9d4579f3bdedad51c10d6fb3092f7ed88fba01d3", + "pyproject.toml": "53732e2227b62434a68ef88b5470c476791f3720d59e31b89c58c95e0a75e2d4", "src/rpcv2cbor_client/__init__.py": "c8267efbae8c45cca2f1c7f4dccc6da6ce3fc6c99488ed58988b0747b85af0c5", "src/rpcv2cbor_client/_private/__init__.py": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "src/rpcv2cbor_client/_private/schemas.py": "cad2513bd74593541b05ebf5f96823205d254ac69b4d5eb075744503cfa8ba81", diff --git a/codegen-output-py/rpcv2-cbor-client/pyproject.toml b/codegen-output-py/rpcv2-cbor-client/pyproject.toml index 76a37b2a4..6b2d8d584 100644 --- a/codegen-output-py/rpcv2-cbor-client/pyproject.toml +++ b/codegen-output-py/rpcv2-cbor-client/pyproject.toml @@ -9,8 +9,8 @@ requires-python = ">=3.12" keywords = ["smithy", "rpcv2cbor_client"] license = {text = "Apache-2.0"} dependencies = [ - "smithy-core~=0.12.0", - "smithy-http[aiohttp,cbor,urllib3]~=0.9.0", + "smithy-core~=0.13.0", + "smithy-http[aiohttp,cbor,urllib3]~=0.10.0", ] [build-system] diff --git a/codegen-output-py/rpcv2-cbor/.smithy-python-manifest.json b/codegen-output-py/rpcv2-cbor/.smithy-python-manifest.json index 984ae9ff3..34d1b68a2 100644 --- a/codegen-output-py/rpcv2-cbor/.smithy-python-manifest.json +++ b/codegen-output-py/rpcv2-cbor/.smithy-python-manifest.json @@ -1,7 +1,7 @@ { "files": { "README.md": "b856f842a89c64e9cb4ff9a7b27607b66029e73b50597d59041db28f4f2b5180", - "pyproject.toml": "3c2189abb1bccb08f4ffa5afcf3f79068d28cc838bbe26533c268b31aca64077", + "pyproject.toml": "2f41e375828958c622ae82a494bcddbc5422d79126232a4b1ed37468d24d72de", "src/rpcv2cbor/__init__.py": "619a033058229139a02f912a44a6b8997fb35c5af6736d09edd49927876a49dd", "src/rpcv2cbor/_private/__init__.py": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "src/rpcv2cbor/_private/schemas.py": "2a75caf22b711ae4dec15bba8a4e327b7f8ad6c02b3ff32e539c277847fb395f", diff --git a/codegen-output-py/rpcv2-cbor/pyproject.toml b/codegen-output-py/rpcv2-cbor/pyproject.toml index d01bd7e7d..95e0909fc 100644 --- a/codegen-output-py/rpcv2-cbor/pyproject.toml +++ b/codegen-output-py/rpcv2-cbor/pyproject.toml @@ -9,7 +9,7 @@ requires-python = ">=3.12" keywords = ["smithy", "rpcv2cbor"] license = {text = "Apache-2.0"} dependencies = [ - "smithy-core~=0.12.0", + "smithy-core~=0.13.0", ] [build-system] diff --git a/codegen-output-py/rpcv2-json-client/.smithy-python-manifest.json b/codegen-output-py/rpcv2-json-client/.smithy-python-manifest.json index 0f1a8c17f..40956440b 100644 --- a/codegen-output-py/rpcv2-json-client/.smithy-python-manifest.json +++ b/codegen-output-py/rpcv2-json-client/.smithy-python-manifest.json @@ -1,7 +1,7 @@ { "files": { "README.md": "45e418df185f3c97645bb27cde96c23d25862660c4efb7e07daa6f2f4e541833", - "pyproject.toml": "347f20c1040a5efdf94ec4759b126867f8e62b2baa8790b8cec9c3c2a18ee315", + "pyproject.toml": "1e092d69b0fb9a1dc14899c713abb013b2a5580725aebcf3c945fc3121baecf7", "src/rpcv2json_client/__init__.py": "fa3fa16a23aaa1ad8d7a87a8c5475ac6b82cfeeabb83625ab4d28d3c3f6a0fbe", "src/rpcv2json_client/_private/__init__.py": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "src/rpcv2json_client/_private/schemas.py": "b52400dc7e9af25614f09ee4efe1e3ac3fe344436901b62109c94724ee0f0fa2", diff --git a/codegen-output-py/rpcv2-json-client/pyproject.toml b/codegen-output-py/rpcv2-json-client/pyproject.toml index abe56a74d..c86d64f5a 100644 --- a/codegen-output-py/rpcv2-json-client/pyproject.toml +++ b/codegen-output-py/rpcv2-json-client/pyproject.toml @@ -9,8 +9,8 @@ requires-python = ">=3.12" keywords = ["smithy", "rpcv2json_client"] license = {text = "Apache-2.0"} dependencies = [ - "smithy-core~=0.12.0", - "smithy-http[aiohttp,json,urllib3]~=0.9.0", + "smithy-core~=0.13.0", + "smithy-http[aiohttp,json,urllib3]~=0.10.0", ] [build-system] diff --git a/codegen-output-py/rpcv2-json/.smithy-python-manifest.json b/codegen-output-py/rpcv2-json/.smithy-python-manifest.json index 910cd39b6..1a4430708 100644 --- a/codegen-output-py/rpcv2-json/.smithy-python-manifest.json +++ b/codegen-output-py/rpcv2-json/.smithy-python-manifest.json @@ -1,7 +1,7 @@ { "files": { "README.md": "94b31362a2e131ea489a05430091f33d2320726f788873fd27452809a3d6aa6e", - "pyproject.toml": "8fa97e7efef46667fa9cb72bde4bacfb5bca1e336d8f759c198ae405b820f5c6", + "pyproject.toml": "5868ae6c5dc5eb29a14cb09e34172636035d17f93050bbbfbb0ee6dd949166d6", "src/rpcv2json/__init__.py": "619a033058229139a02f912a44a6b8997fb35c5af6736d09edd49927876a49dd", "src/rpcv2json/_private/__init__.py": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "src/rpcv2json/_private/schemas.py": "c7b5e9c410266bf04829d7654ceb370635fea033c7071f1c4bf2129a31b3ee05", diff --git a/codegen-output-py/rpcv2-json/pyproject.toml b/codegen-output-py/rpcv2-json/pyproject.toml index 2033cd53b..190131da6 100644 --- a/codegen-output-py/rpcv2-json/pyproject.toml +++ b/codegen-output-py/rpcv2-json/pyproject.toml @@ -9,7 +9,7 @@ requires-python = ">=3.12" keywords = ["smithy", "rpcv2json"] license = {text = "Apache-2.0"} dependencies = [ - "smithy-core~=0.12.0", + "smithy-core~=0.13.0", ] [build-system] diff --git a/codegen-output-py/types/.smithy-python-manifest.json b/codegen-output-py/types/.smithy-python-manifest.json index 31a3f8a01..28d5801d0 100644 --- a/codegen-output-py/types/.smithy-python-manifest.json +++ b/codegen-output-py/types/.smithy-python-manifest.json @@ -1,7 +1,7 @@ { "files": { "README.md": "b070865ebb1dc46192ea8a45f0961e1b0f812dfccd069537cfc04311b3327660", - "pyproject.toml": "4bbbb257ae858ba5210692ee7ee9697bfe3d31721bdfb53307a9ea63c9e7f62c", + "pyproject.toml": "7565450fbc245df3daf2f61a7de068d6ad818ebb7c01a149ffa17fc7e933032f", "src/example_types/__init__.py": "27ea4bc5ba93a6fc6e1f11e9784565de24e9249f0d3e77a9e2fb64fa47d11012", "src/example_types/_private/__init__.py": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "src/example_types/_private/schemas.py": "ef8526008f167b2f927c5f95d0b443400af99a3ff96047a494d7cdfb262b285c", diff --git a/codegen-output-py/types/pyproject.toml b/codegen-output-py/types/pyproject.toml index 26284eeb3..dd626c477 100644 --- a/codegen-output-py/types/pyproject.toml +++ b/codegen-output-py/types/pyproject.toml @@ -9,7 +9,7 @@ requires-python = ">=3.12" keywords = ["smithy", "example_types"] license = {text = "Apache-2.0"} dependencies = [ - "smithy-core~=0.12.0", + "smithy-core~=0.13.0", ] [build-system] diff --git a/packages/smithy-python/.changes/next-release/smithy-python-dependency-83bf4597c4cc4803833098d4ec9bce3f.json b/packages/smithy-python/.changes/next-release/smithy-python-dependency-83bf4597c4cc4803833098d4ec9bce3f.json new file mode 100644 index 000000000..aa9819073 --- /dev/null +++ b/packages/smithy-python/.changes/next-release/smithy-python-dependency-83bf4597c4cc4803833098d4ec9bce3f.json @@ -0,0 +1,4 @@ +{ + "type": "dependency", + "description": "Pin generated packages to smithy-core 0.13 and smithy-http 0.10." +} \ No newline at end of file diff --git a/packages/smithy-python/src/smithy_python/dependencies.py b/packages/smithy-python/src/smithy_python/dependencies.py index 8b943fe4e..1f05bf0af 100644 --- a/packages/smithy-python/src/smithy_python/dependencies.py +++ b/packages/smithy-python/src/smithy_python/dependencies.py @@ -104,7 +104,7 @@ def for_group(self, group: DependencyGroup) -> tuple[Dependency, ...]: SMITHY_CORE = Dependency( package="smithy-core", - specifier="~=0.12.0", + specifier="~=0.13.0", group="runtime", ) """Compatible smithy-core runtime for generated artifacts. @@ -114,7 +114,7 @@ def for_group(self, group: DependencyGroup) -> tuple[Dependency, ...]: SMITHY_HTTP = Dependency( package="smithy-http", - specifier="~=0.9.0", + specifier="~=0.10.0", group="runtime", ) """Compatible smithy-http runtime for generated HTTP clients.""" diff --git a/packages/smithy-python/tests/unit/test_cli.py b/packages/smithy-python/tests/unit/test_cli.py index 3b7b1e510..054ef82c4 100644 --- a/packages/smithy-python/tests/unit/test_cli.py +++ b/packages/smithy-python/tests/unit/test_cli.py @@ -101,8 +101,8 @@ def test_client_generation_writes_complete_package( project = tomllib.loads((output / "pyproject.toml").read_text()) assert project["project"]["description"] == "example_client client package" assert project["project"]["dependencies"] == [ - "smithy-core~=0.12.0", - "smithy-http[aiohttp,cbor,urllib3]~=0.9.0", + "smithy-core~=0.13.0", + "smithy-http[aiohttp,cbor,urllib3]~=0.10.0", ] monkeypatch.syspath_prepend( # pyright: ignore[reportUnknownMemberType] str(output / "src") @@ -178,7 +178,7 @@ def test_types_generation_writes_complete_package( "requires-python": ">=3.12", "keywords": ["smithy", "example_types"], "license": {"text": "Apache-2.0"}, - "dependencies": ["smithy-core~=0.12.0"], + "dependencies": ["smithy-core~=0.13.0"], } assert project["build-system"] == { "requires": ["hatchling"], diff --git a/packages/smithy-python/tests/unit/test_dependencies.py b/packages/smithy-python/tests/unit/test_dependencies.py index 5e7600208..3631fec33 100644 --- a/packages/smithy-python/tests/unit/test_dependencies.py +++ b/packages/smithy-python/tests/unit/test_dependencies.py @@ -67,6 +67,6 @@ def test_dependency_set_rejects_specifier_conflicts() -> None: def test_runtime_dependency_catalog() -> None: - assert SMITHY_CORE == Dependency("smithy-core", "~=0.12.0", "runtime") - assert SMITHY_HTTP == Dependency("smithy-http", "~=0.9.0", "runtime") + assert SMITHY_CORE == Dependency("smithy-core", "~=0.13.0", "runtime") + assert SMITHY_HTTP == Dependency("smithy-http", "~=0.10.0", "runtime") assert HATCHLING == Dependency("hatchling", "", "build") From 9d0b21230cb3b41f1c0f0022ec121458a2c3b57b Mon Sep 17 00:00:00 2001 From: Sean O'Brien <60306702+stobrien89@users.noreply.github.com> Date: Tue, 17 Nov 2026 13:55:32 -0500 Subject: [PATCH 2/3] Generate endpoint BDDs for Python clients --- .../.smithy-python-manifest.json | 5 +- .../rpcv2cbor_client/_private/endpoints.py | 27 + .../src/rpcv2cbor_client/aio/config.py | 7 +- .../src/rpcv2cbor_client/config.py | 7 +- .../.smithy-python-manifest.json | 5 +- .../rpcv2json_client/_private/endpoints.py | 27 + .../src/rpcv2json_client/aio/config.py | 7 +- .../src/rpcv2json_client/config.py | 7 +- designs/codegen/client.md | 63 +- ...ture-01b2f761fddb4174ae59f614a52ddf95.json | 4 + .../src/smithy_python/_client_emitter.py | 68 +- .../src/smithy_python/_endpoints.py | 665 ++++++++++++++++++ .../src/smithy_python/clients.py | 8 +- .../src/smithy_python/schemas.py | 5 +- .../tests/unit/test_client_generation.py | 81 +++ .../tests/unit/test_endpoints.py | 475 +++++++++++++ scripts/verifications/import-cost.json | 2 +- 17 files changed, 1417 insertions(+), 46 deletions(-) create mode 100644 codegen-output-py/rpcv2-cbor-client/src/rpcv2cbor_client/_private/endpoints.py create mode 100644 codegen-output-py/rpcv2-json-client/src/rpcv2json_client/_private/endpoints.py create mode 100644 packages/smithy-python/.changes/next-release/smithy-python-feature-01b2f761fddb4174ae59f614a52ddf95.json create mode 100644 packages/smithy-python/src/smithy_python/_endpoints.py create mode 100644 packages/smithy-python/tests/unit/test_endpoints.py diff --git a/codegen-output-py/rpcv2-cbor-client/.smithy-python-manifest.json b/codegen-output-py/rpcv2-cbor-client/.smithy-python-manifest.json index e4edf86f6..7840d997e 100644 --- a/codegen-output-py/rpcv2-cbor-client/.smithy-python-manifest.json +++ b/codegen-output-py/rpcv2-cbor-client/.smithy-python-manifest.json @@ -4,12 +4,13 @@ "pyproject.toml": "53732e2227b62434a68ef88b5470c476791f3720d59e31b89c58c95e0a75e2d4", "src/rpcv2cbor_client/__init__.py": "c8267efbae8c45cca2f1c7f4dccc6da6ce3fc6c99488ed58988b0747b85af0c5", "src/rpcv2cbor_client/_private/__init__.py": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "src/rpcv2cbor_client/_private/endpoints.py": "7d515fe771678e82ddbe07798d6b7e48c25c6c9bec19cec9318deb0bc5064ead", "src/rpcv2cbor_client/_private/schemas.py": "cad2513bd74593541b05ebf5f96823205d254ac69b4d5eb075744503cfa8ba81", "src/rpcv2cbor_client/aio/__init__.py": "31ed3d77a0cc3cc768d548990ef7216e9eb278a7161cb34f1f74d3310100f497", "src/rpcv2cbor_client/aio/client.py": "0c1d028b3cbb670a97219aaeed13f21a6fabcee6e5c57313d727aee616b7dc8e", - "src/rpcv2cbor_client/aio/config.py": "901cc7d8a26a07a33e263fb455b73cd416439ad67f085bbdfd43f1c196c8311d", + "src/rpcv2cbor_client/aio/config.py": "2585543e3bcb534f078e97b9d5d41205545f430de575ab859e8c08f6eb8a11e1", "src/rpcv2cbor_client/client.py": "5db8d2f687a182c4ea67f88a77201a45bf38632d055effdcf3d21b35b6b5f508", - "src/rpcv2cbor_client/config.py": "760818e0daced8b45291a96a7572bf1246e2fb05ffa98ef35245df2a86a105c2", + "src/rpcv2cbor_client/config.py": "f59a5615bdd6a588199a73aabd1a5985e5590a56b846676ac914086d24b872aa", "src/rpcv2cbor_client/models.py": "4f7443ca5d6a248346c39518734d165e4c6aa272347da8b12938dd4300368681", "src/rpcv2cbor_client/models.pyi": "1034372fafed1220d9ba996c3a50a274c43a6cd8932c7091011fab068078067f", "src/rpcv2cbor_client/py.typed": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" diff --git a/codegen-output-py/rpcv2-cbor-client/src/rpcv2cbor_client/_private/endpoints.py b/codegen-output-py/rpcv2-cbor-client/src/rpcv2cbor_client/_private/endpoints.py new file mode 100644 index 000000000..ad3066783 --- /dev/null +++ b/codegen-output-py/rpcv2-cbor-client/src/rpcv2cbor_client/_private/endpoints.py @@ -0,0 +1,27 @@ +from smithy_core.endpoints import EndpointBdd + +# fmt: off +# Tags: ref=0, attr=1, call=2, list=3, map=4, error=5, endpoint=6. +BDD = EndpointBdd( + # (name, type, required, default, builtin, client_context_attribute) + parameters=( + ("endpoint", "string", False, None, "SDK::Endpoint", None), + ), + functions=("isSet",), + conditions=( + ((2, "isSet", (0, "endpoint")), None), # 0: isSet(endpoint) + ), + results=( + None, # 0: no match + (6, (0, "endpoint"), None, ()), # 1 + (5, "(default endpointRuleSet) endpoint is not set - you must configure an endpoint."), # 2 + ), + root=2, + # (condition, high, low); 1 and -1 are terminals, a negative reference is a + # complement edge, and 100_000_000 + k is result k. + nodes=( + -1, 1, -1, + 0, 100_000_001, 100_000_002, + ), +) +# fmt: on diff --git a/codegen-output-py/rpcv2-cbor-client/src/rpcv2cbor_client/aio/config.py b/codegen-output-py/rpcv2-cbor-client/src/rpcv2cbor_client/aio/config.py index d410b4923..4023e41a0 100644 --- a/codegen-output-py/rpcv2-cbor-client/src/rpcv2cbor_client/aio/config.py +++ b/codegen-output-py/rpcv2-cbor-client/src/rpcv2cbor_client/aio/config.py @@ -5,7 +5,7 @@ from smithy_core.aio.interfaces import AsyncClientTransport, AsyncEndpointResolver from smithy_core.aio.interfaces.auth import AsyncAuthScheme from smithy_core.auth import DefaultAuthResolver -from smithy_core.endpoints import StaticEndpointResolver +from smithy_core.endpoints import BddEndpointResolver from smithy_core.interceptors import Interceptor from smithy_core.interfaces import ( ClientProtocol, @@ -21,6 +21,7 @@ from smithy_http.aio.aiohttp import AIOHTTPClient from smithy_http.aio.protocols import AsyncRpcV2CborClientProtocol +from rpcv2cbor_client._private.endpoints import BDD from rpcv2cbor_client._private.schemas import RPC_V2_PROTOCOL _PROTOCOL_SETTINGS = ProtocolSettings( @@ -45,7 +46,7 @@ class AsyncConfig: "Resolves the endpoint of each operation." endpoint_uri: str | URI | None - "The static URI requests are sent to." + "The endpoint URI, read by the endpoint rules as ``SDK::Endpoint``." interceptors: list[Interceptor[Any, Any, Any, Any]] "Hooks called during the execution of a request." @@ -75,7 +76,7 @@ def __init__( ) -> None: self.auth_scheme_resolver = auth_scheme_resolver or DefaultAuthResolver() self.auth_schemes = auth_schemes or {} - self.endpoint_resolver = endpoint_resolver or StaticEndpointResolver() + self.endpoint_resolver = endpoint_resolver or BddEndpointResolver(BDD) self.endpoint_uri = endpoint_uri self.interceptors = interceptors or [] if isinstance(protocol, type): diff --git a/codegen-output-py/rpcv2-cbor-client/src/rpcv2cbor_client/config.py b/codegen-output-py/rpcv2-cbor-client/src/rpcv2cbor_client/config.py index f39867134..516be21fe 100644 --- a/codegen-output-py/rpcv2-cbor-client/src/rpcv2cbor_client/config.py +++ b/codegen-output-py/rpcv2-cbor-client/src/rpcv2cbor_client/config.py @@ -3,7 +3,7 @@ from typing import Any, cast from smithy_core.auth import DefaultAuthResolver -from smithy_core.endpoints import StaticEndpointResolver +from smithy_core.endpoints import BddEndpointResolver from smithy_core.interceptors import Interceptor from smithy_core.interfaces import ( ClientProtocol, @@ -20,6 +20,7 @@ from smithy_http.protocols import RpcV2CborClientProtocol from smithy_http.urllib3 import Urllib3HTTPClient +from rpcv2cbor_client._private.endpoints import BDD from rpcv2cbor_client._private.schemas import RPC_V2_PROTOCOL _PROTOCOL_SETTINGS = ProtocolSettings( @@ -44,7 +45,7 @@ class Config: "Resolves the endpoint of each operation." endpoint_uri: str | URI | None - "The static URI requests are sent to." + "The endpoint URI, read by the endpoint rules as ``SDK::Endpoint``." interceptors: list[Interceptor[Any, Any, Any, Any]] "Hooks called during the execution of a request." @@ -74,7 +75,7 @@ def __init__( ) -> None: self.auth_scheme_resolver = auth_scheme_resolver or DefaultAuthResolver() self.auth_schemes = auth_schemes or {} - self.endpoint_resolver = endpoint_resolver or StaticEndpointResolver() + self.endpoint_resolver = endpoint_resolver or BddEndpointResolver(BDD) self.endpoint_uri = endpoint_uri self.interceptors = interceptors or [] if isinstance(protocol, type): diff --git a/codegen-output-py/rpcv2-json-client/.smithy-python-manifest.json b/codegen-output-py/rpcv2-json-client/.smithy-python-manifest.json index 40956440b..8f8ac4477 100644 --- a/codegen-output-py/rpcv2-json-client/.smithy-python-manifest.json +++ b/codegen-output-py/rpcv2-json-client/.smithy-python-manifest.json @@ -4,12 +4,13 @@ "pyproject.toml": "1e092d69b0fb9a1dc14899c713abb013b2a5580725aebcf3c945fc3121baecf7", "src/rpcv2json_client/__init__.py": "fa3fa16a23aaa1ad8d7a87a8c5475ac6b82cfeeabb83625ab4d28d3c3f6a0fbe", "src/rpcv2json_client/_private/__init__.py": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "src/rpcv2json_client/_private/endpoints.py": "7d515fe771678e82ddbe07798d6b7e48c25c6c9bec19cec9318deb0bc5064ead", "src/rpcv2json_client/_private/schemas.py": "b52400dc7e9af25614f09ee4efe1e3ac3fe344436901b62109c94724ee0f0fa2", "src/rpcv2json_client/aio/__init__.py": "a24a4208d8da09d3b8662a439db4ae9838585fc27fe431b42aa8dd05ec93c78c", "src/rpcv2json_client/aio/client.py": "d6f1faa50990e24e578d737acce46a7a9ec525f3e3c1e7ce9d2f656ab443b7ef", - "src/rpcv2json_client/aio/config.py": "c0a216a115fb3898ce38834cfa431fa3335ba058c56da59482451804cda325a0", + "src/rpcv2json_client/aio/config.py": "9a690c07e6d87a5c43e3a139dc7aafd6483a8be111954e096f80d0af37fc73b2", "src/rpcv2json_client/client.py": "64460ff50e711ab7d110b482a4c5d14ae4aa82b3e4938e4909a6b711462ee6bb", - "src/rpcv2json_client/config.py": "f59386780266cbcd806e0e2bb73e4e5bd43f085073f86737e86b30ba8245e2a2", + "src/rpcv2json_client/config.py": "427d621c929be7cadc23d8a5b2530e39ec5c8b05b04a2403d8e02a2b17efb7c8", "src/rpcv2json_client/models.py": "94050bb13fbc2a62b3299790c28b270e6f42fb038f77fdd72f54077269a9c9a0", "src/rpcv2json_client/models.pyi": "5f129d34dd7fd48915deb1396753bcd848eda16d5f1c043e988c605216cb4a8f", "src/rpcv2json_client/py.typed": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" diff --git a/codegen-output-py/rpcv2-json-client/src/rpcv2json_client/_private/endpoints.py b/codegen-output-py/rpcv2-json-client/src/rpcv2json_client/_private/endpoints.py new file mode 100644 index 000000000..ad3066783 --- /dev/null +++ b/codegen-output-py/rpcv2-json-client/src/rpcv2json_client/_private/endpoints.py @@ -0,0 +1,27 @@ +from smithy_core.endpoints import EndpointBdd + +# fmt: off +# Tags: ref=0, attr=1, call=2, list=3, map=4, error=5, endpoint=6. +BDD = EndpointBdd( + # (name, type, required, default, builtin, client_context_attribute) + parameters=( + ("endpoint", "string", False, None, "SDK::Endpoint", None), + ), + functions=("isSet",), + conditions=( + ((2, "isSet", (0, "endpoint")), None), # 0: isSet(endpoint) + ), + results=( + None, # 0: no match + (6, (0, "endpoint"), None, ()), # 1 + (5, "(default endpointRuleSet) endpoint is not set - you must configure an endpoint."), # 2 + ), + root=2, + # (condition, high, low); 1 and -1 are terminals, a negative reference is a + # complement edge, and 100_000_000 + k is result k. + nodes=( + -1, 1, -1, + 0, 100_000_001, 100_000_002, + ), +) +# fmt: on diff --git a/codegen-output-py/rpcv2-json-client/src/rpcv2json_client/aio/config.py b/codegen-output-py/rpcv2-json-client/src/rpcv2json_client/aio/config.py index 852ffc4c6..355a3483a 100644 --- a/codegen-output-py/rpcv2-json-client/src/rpcv2json_client/aio/config.py +++ b/codegen-output-py/rpcv2-json-client/src/rpcv2json_client/aio/config.py @@ -5,7 +5,7 @@ from smithy_core.aio.interfaces import AsyncClientTransport, AsyncEndpointResolver from smithy_core.aio.interfaces.auth import AsyncAuthScheme from smithy_core.auth import DefaultAuthResolver -from smithy_core.endpoints import StaticEndpointResolver +from smithy_core.endpoints import BddEndpointResolver from smithy_core.interceptors import Interceptor from smithy_core.interfaces import ( ClientProtocol, @@ -21,6 +21,7 @@ from smithy_http.aio.aiohttp import AIOHTTPClient from smithy_http.aio.protocols import AsyncRpcV2JsonClientProtocol +from rpcv2json_client._private.endpoints import BDD from rpcv2json_client._private.schemas import RPC_V2_JSON_PROTOCOL _PROTOCOL_SETTINGS = ProtocolSettings( @@ -45,7 +46,7 @@ class AsyncConfig: "Resolves the endpoint of each operation." endpoint_uri: str | URI | None - "The static URI requests are sent to." + "The endpoint URI, read by the endpoint rules as ``SDK::Endpoint``." interceptors: list[Interceptor[Any, Any, Any, Any]] "Hooks called during the execution of a request." @@ -75,7 +76,7 @@ def __init__( ) -> None: self.auth_scheme_resolver = auth_scheme_resolver or DefaultAuthResolver() self.auth_schemes = auth_schemes or {} - self.endpoint_resolver = endpoint_resolver or StaticEndpointResolver() + self.endpoint_resolver = endpoint_resolver or BddEndpointResolver(BDD) self.endpoint_uri = endpoint_uri self.interceptors = interceptors or [] if isinstance(protocol, type): diff --git a/codegen-output-py/rpcv2-json-client/src/rpcv2json_client/config.py b/codegen-output-py/rpcv2-json-client/src/rpcv2json_client/config.py index 503f13b56..9f78b3730 100644 --- a/codegen-output-py/rpcv2-json-client/src/rpcv2json_client/config.py +++ b/codegen-output-py/rpcv2-json-client/src/rpcv2json_client/config.py @@ -3,7 +3,7 @@ from typing import Any, cast from smithy_core.auth import DefaultAuthResolver -from smithy_core.endpoints import StaticEndpointResolver +from smithy_core.endpoints import BddEndpointResolver from smithy_core.interceptors import Interceptor from smithy_core.interfaces import ( ClientProtocol, @@ -20,6 +20,7 @@ from smithy_http.protocols import RpcV2JsonClientProtocol from smithy_http.urllib3 import Urllib3HTTPClient +from rpcv2json_client._private.endpoints import BDD from rpcv2json_client._private.schemas import RPC_V2_JSON_PROTOCOL _PROTOCOL_SETTINGS = ProtocolSettings( @@ -44,7 +45,7 @@ class Config: "Resolves the endpoint of each operation." endpoint_uri: str | URI | None - "The static URI requests are sent to." + "The endpoint URI, read by the endpoint rules as ``SDK::Endpoint``." interceptors: list[Interceptor[Any, Any, Any, Any]] "Hooks called during the execution of a request." @@ -74,7 +75,7 @@ def __init__( ) -> None: self.auth_scheme_resolver = auth_scheme_resolver or DefaultAuthResolver() self.auth_schemes = auth_schemes or {} - self.endpoint_resolver = endpoint_resolver or StaticEndpointResolver() + self.endpoint_resolver = endpoint_resolver or BddEndpointResolver(BDD) self.endpoint_uri = endpoint_uri self.interceptors = interceptors or [] if isinstance(protocol, type): diff --git a/designs/codegen/client.md b/designs/codegen/client.md index a57c1f745..669c46a34 100644 --- a/designs/codegen/client.md +++ b/designs/codegen/client.md @@ -5,7 +5,7 @@ This document describes how the Python generator produces client packages. It defines client settings, operation discovery, I/O normalization, client symbols, the client plan, operation and schema emission, protocol selection, -and the generated client and config modules. +endpoint rules, and the generated client and config modules. ## Goals @@ -186,7 +186,48 @@ Both also use: * `ProtocolSettings` with the service namespace, target, version, and schema. * `Urllib3HTTPClient` and `AIOHTTPClient` as default sync/async transports, which add the `urllib3` and `aiohttp` extras. -* `StaticEndpointResolver` with a configured endpoint URI. +* `BddEndpointResolver` over the generated endpoint BDD. + +## Endpoints + +Endpoint resolution has one runtime representation, the endpoint BDD. The +generator lowers the service's `smithy.rules#endpointBdd` trait into a +`smithy_core.endpoints.EndpointBdd` of Python literals in +`/_private/endpoints.py`. The module source matches the Java +generator's for the same trait. + +Lowering re-encodes the trait and makes no engine decisions: + +* Parameters become `(name, type, required, default, builtin, + client_context_attribute)` tuples in trait order. Optional parameters no + condition or result reads are dropped. +* Expressions and results become tuples led by small integer tags. Function + names stay names, and `getAttr` becomes an attribute expression. +* Templates are parsed as Smithy parses them and written back from their parts, + so escapes and `getAttr` paths take one canonical form. +* Nodes are decoded from the trait's big-endian `int32` triples and copied + verbatim. Node 0 must be the `(-1, 1, -1)` terminal, and no edge may + complement a result reference. + +Only trait version 1.1 is accepted. A service with no endpoint rules gets the +BDD compiled from the default ruleset of smithy-typescript, which reads +`SDK::Endpoint` and fails when it is unset. A service with +`smithy.rules#endpointRuleSet` alone fails generation, because compiling a +ruleset into a BDD is Smithy's `CompileBdd` transform. + +The generated client calls rules functions from the `smithy_core.endpoints` +standard library only. Rules that call any other function fail generation with +a diagnostic naming the functions. + +Each `smithy.rules#clientContextParams` entry becomes a config field typed `bool +| None` or `str | None` and defaulting to None. Its name is the snake-case form +of the parameter name, and its docstring is the entry's documentation. The BDD +records the field name as the parameter's config attribute. A field name that +matches a standard config field or another entry's field fails generation. + +Schemas retain `smithy.rules#contextParam`, `smithy.rules#staticContextParams`, +and `smithy.rules#operationContextParams`, which the runtime parameter plan +reads to bind input members and operation values. ## Clients and Configuration @@ -203,12 +244,14 @@ Generated packages use this layout: /aio/config.py /models.py and models.pyi /_private/schemas.py and partitions +/_private/endpoints.py ``` Package initialization lazily exports both clients and configs. Each config exposes protocol/transport overrides, endpoint URI/resolver, auth -resolver/schemes, retries, and interceptors. Both configs default to -`DefaultAuthResolver`, `StaticEndpointResolver`, the contribution's protocol, +resolver/schemes, retries, interceptors, and client context fields. Both +configs default to `DefaultAuthResolver`, `BddEndpointResolver(BDD)`, the +contribution's protocol, and its transport: `Urllib3HTTPClient` for sync and `AIOHTTPClient` for async. Client and types artifacts share package metadata emission, dependency tracking, README generation, and manifest ownership. @@ -243,9 +286,9 @@ runtime metadata. It covers `self`, `plugins`, defaults, and idempotency tokens. ## Supported Features The generator supports unsigned, non-streaming RPCv2 CBOR and RPCv2 JSON -operations with a static endpoint. Models that require auth schemes, event or data streams, or -modeled endpoint rules fail generation with a diagnostic naming the operation -and feature. +operations whose endpoint rules use the standard library. Models that require +auth schemes or event or data streams fail generation with a diagnostic naming +the operation and feature. Authentication and endpoint extension points are provider-neutral. AWS credentials, region defaults, SigV4, query compatibility, AWS endpoint @@ -256,7 +299,11 @@ functions, and AWS user agents are separate integrations. Tests generate a checked-in JSON service fixture. They exercise nested input/output models, a modeled error, Unit I/O, and explicit empty I/O through fake sync/async transports. They assert the request method, URI, headers, -decoded CBOR payload, response models, and error types. +decoded CBOR payload, response models, and error types. An endpoint test +resolves a host from a client context field, an input context parameter, and +a static context parameter. + +Lowering tests port the Java generator's tests. Client snapshots sit alongside the types snapshots and cover the provider-neutral RPCv2 CBOR and RPCv2 JSON projections. Checks cover deterministic diff --git a/packages/smithy-python/.changes/next-release/smithy-python-feature-01b2f761fddb4174ae59f614a52ddf95.json b/packages/smithy-python/.changes/next-release/smithy-python-feature-01b2f761fddb4174ae59f614a52ddf95.json new file mode 100644 index 000000000..ba9c82657 --- /dev/null +++ b/packages/smithy-python/.changes/next-release/smithy-python-feature-01b2f761fddb4174ae59f614a52ddf95.json @@ -0,0 +1,4 @@ +{ + "type": "feature", + "description": "Generate clients that resolve endpoints from the service's endpointBdd trait. Client context parameters become config fields, and a service with no endpoint rules requires `endpoint_uri`." +} \ No newline at end of file diff --git a/packages/smithy-python/src/smithy_python/_client_emitter.py b/packages/smithy-python/src/smithy_python/_client_emitter.py index 6b85adf9e..36904252d 100644 --- a/packages/smithy-python/src/smithy_python/_client_emitter.py +++ b/packages/smithy-python/src/smithy_python/_client_emitter.py @@ -7,7 +7,7 @@ from dataclasses import dataclass from typing import TYPE_CHECKING, Final -from . import _package +from . import _endpoints, _package from . import dependencies as _dependencies from . import exceptions as _exceptions from . import model as _model @@ -26,14 +26,6 @@ def check_supported(plan: ClientPlan) -> None: :raises CodegenError: Naming the first unsupported operation and feature. """ - service = plan.selection.service - assert service is not None # noqa: S101 - ClientPlan requires a service - for trait_id in _RULE_TRAITS: - if service.has_trait(trait_id): - raise _exceptions.CodegenError( - f"Service {service.id} uses {trait_id}, which client generation " - "does not support yet. Use a static endpoint." - ) for operation, exports in zip(plan.operations, plan.models.operations, strict=True): shape = operation.operation if _NO_AUTH not in exports.auth_scheme_ids: @@ -51,16 +43,35 @@ def check_supported(plan: ClientPlan) -> None: ) +def plan_endpoints(plan: ClientPlan) -> _endpoints.EndpointPlan: + """Lower the service's endpoint rules for its client. + + :raises CodegenError: If the rules are unsupported, or a client context + parameter's config field collides with another config field. + """ + service = plan.selection.service + assert service is not None # noqa: S101 - ClientPlan requires a service + return _endpoints.plan_endpoints(service, reserved=_CONFIG_FIELDS) + + def write_client( context: GenerationContext[ClientSettings], plan: ClientPlan, protocol: _protocols.ProtocolContribution, + endpoints: _endpoints.EndpointPlan, ) -> None: - """Register client, config, and package modules for both modes.""" + """Register client, config, endpoints, and package modules for both modes.""" package = context.settings.package directory = package.replace(".", "/") service = plan.selection.service assert service is not None # noqa: S101 - ClientPlan requires a service + endpoints_module = f"{package}._private.endpoints" + _endpoints.write_endpoints( + context.files.python_module( + f"src/{directory}/_private/endpoints.py", endpoints_module + ), + endpoints, + ) sync, aio = _modes(plan, protocol) for mode in (sync, aio): module = f"{package}.{mode.directory.replace('/', '.')}" @@ -71,6 +82,8 @@ def write_client( plan, mode, service, + endpoints, + TypeReference("BDD", endpoints_module), ) _write_client( context.files.python_module( @@ -127,7 +140,7 @@ def _typing(name: str) -> TypeReference: _URI: Final = _core("URI", "interfaces") _AUTH_SCHEME_RESOLVER: Final = _core("AuthSchemeResolver", "interfaces.auth") _DEFAULT_AUTH_RESOLVER: Final = _core("DefaultAuthResolver", "auth") -_STATIC_ENDPOINT_RESOLVER: Final = _core("StaticEndpointResolver", "endpoints") +_BDD_ENDPOINT_RESOLVER: Final = _core("BddEndpointResolver", "endpoints") _RETRY_STRATEGY: Final = _core("RetryStrategy", "interfaces.retries") _RETRY_STRATEGY_OPTIONS: Final = _core("RetryStrategyOptions", "retries") _SHAPE_ID: Final = _core("ShapeID", "shapes") @@ -203,10 +216,19 @@ def _modes( _NO_AUTH: Final = _model.ShapeId("smithy.api", "noAuth") -_RULE_TRAITS: Final = ( - _model.ShapeId("smithy.rules", "endpointRuleSet"), - _model.ShapeId("smithy.rules", "endpointBdd"), +_CONFIG_FIELDS: Final = frozenset( + { + "auth_scheme_resolver", + "auth_schemes", + "endpoint_resolver", + "endpoint_uri", + "interceptors", + "protocol", + "retry_strategy", + "transport", + } ) +"""The config fields every client has, which a client context field must not take.""" def _write_exports(writer: PythonWriter, exports: dict[str, str]) -> None: @@ -243,6 +265,8 @@ def _write_config( plan: ClientPlan, mode: _Mode, service: _model.ServiceShape, + endpoints: _endpoints.EndpointPlan, + bdd: TypeReference, ) -> None: client_protocol = _generic(_core("ClientProtocol", "interfaces"), _ANY, _ANY) interceptor = _generic(_core("Interceptor", "interceptors"), *_ANY4) @@ -279,7 +303,7 @@ def _write_config( ( "endpoint_uri", ("str | ", _URI, " | None"), - "The static URI requests are sent to.", + "The endpoint URI, read by the endpoint rules as ``SDK::Endpoint``.", ), ( "interceptors", @@ -301,6 +325,10 @@ def _write_config( (mode.transport_type,), "Sends requests, such as an HTTP client.", ), + *( + (field.attribute, (field.type, " | None"), field.documentation) + for field in endpoints.client_context_fields + ), ) writer.line("@", _DATACLASS, "(init=False)") writer.line("class ", mode.config, ":") @@ -331,6 +359,8 @@ def _write_config( ) writer.line("retry_strategy: ", *retry, " | None = None,") writer.line("transport: ", mode.transport_type, " | None = None,") + for field in endpoints.client_context_fields: + writer.line(field.attribute, ": ", field.type, " | None = None,") writer.line(") -> None:") with writer.indent(): writer.line( @@ -341,8 +371,10 @@ def _write_config( writer.line("self.auth_schemes = auth_schemes or {}") writer.line( "self.endpoint_resolver = endpoint_resolver or ", - _STATIC_ENDPOINT_RESOLVER, - "()", + _BDD_ENDPOINT_RESOLVER, + "(", + bdd, + ")", ) writer.line("self.endpoint_uri = endpoint_uri") writer.line("self.interceptors = interceptors or []") @@ -360,6 +392,8 @@ def _write_config( ) writer.line("self.retry_strategy = retry_strategy") writer.line("self.transport = transport or ", mode.transport, "()") + for field in endpoints.client_context_fields: + writer.line("self.", field.attribute, " = ", field.attribute) writer.line() writer.line() writer.line("type Plugin = ", _CALLABLE, "[[", mode.config, "], None]") diff --git a/packages/smithy-python/src/smithy_python/_endpoints.py b/packages/smithy-python/src/smithy_python/_endpoints.py new file mode 100644 index 000000000..ee71da60a --- /dev/null +++ b/packages/smithy-python/src/smithy_python/_endpoints.py @@ -0,0 +1,665 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 +"""Lowering of a service's endpoint rules into the BDD its client resolves with. + +The lowered BDD is a ``smithy_core.endpoints.EndpointBdd`` of Python literals that +re-encodes the ``smithy.rules#endpointBdd`` trait. Lowering keeps no engine +decisions: names stay names, tags are small ints, and the trait's nodes are copied +verbatim. A service with no endpoint rules gets a BDD that requires a configured +endpoint. +""" + +from __future__ import annotations + +import base64 +import binascii +import re +import struct +from collections.abc import Collection, Mapping +from dataclasses import dataclass +from typing import TYPE_CHECKING, Final + +from . import dependencies as _dependencies +from . import exceptions as _exceptions +from . import model as _model +from . import symbols as _symbols +from .symbols import TypeReference + +if TYPE_CHECKING: + from .writer import PythonWriter + +type Value = None | bool | int | str | tuple[Value, ...] +"""A lowered value: a Python literal, with tuples for every sequence.""" + + +@dataclass(frozen=True, slots=True) +class EndpointBdd: + """A lowered endpoint BDD: the fields of a Python ``EndpointBdd``.""" + + parameters: tuple[Value, ...] + functions: tuple[str, ...] + conditions: tuple[Value, ...] + results: tuple[Value, ...] + root: int + nodes: tuple[int, ...] + + +@dataclass(frozen=True, slots=True) +class ClientContextField: + """The config field a ``clientContextParams`` entry reads.""" + + parameter: str + """The endpoint parameter name.""" + + attribute: str + """The config attribute name.""" + + type: str + """The Python type of the value: ``bool`` or ``str``.""" + + documentation: str + + +@dataclass(frozen=True, slots=True) +class EndpointPlan: + """A service's lowered endpoint rules and the config fields they read.""" + + trait: Mapping[str, _model.Node] + """The endpointBdd trait the BDD was lowered from.""" + + bdd: EndpointBdd + client_context_fields: tuple[ClientContextField, ...] + + +def plan_endpoints( + service: _model.ServiceShape, *, reserved: Collection[str] = () +) -> EndpointPlan: + """Lower a service's endpoint rules. + + A service with no endpoint rules gets a BDD that requires the ``SDK::Endpoint`` + built-in, the config's ``endpoint_uri``. + + :param service: The service. + :param reserved: Config attribute names a client context field must not take. + :raises CodegenError: If the service has only an endpointRuleSet trait, its + endpointBdd trait is invalid, its rules call functions outside the rules + standard library, or a client context field is unsupported or collides. + """ + if service.has_trait(_ENDPOINT_BDD): + trait = _object(service.get_trait(_ENDPOINT_BDD), "the trait") + elif service.has_trait(_ENDPOINT_RULE_SET): + raise _exceptions.CodegenError( + f"Service {service.id} uses {_ENDPOINT_RULE_SET} without " + f"{_ENDPOINT_BDD}. Client generation reads {_ENDPOINT_BDD} only, so " + "compile the ruleset with Smithy's CompileBdd transform first." + ) + else: + trait = MANUAL_ENDPOINT_BDD + fields = client_context_fields(service, reserved=reserved) + bdd = lower(trait, {field.parameter: field.attribute for field in fields}) + unsupported = [name for name in bdd.functions if name not in STANDARD_FUNCTIONS] + if unsupported: + raise _exceptions.CodegenError( + f"Service {service.id} endpoint rules call {', '.join(unsupported)}, " + "which client generation does not support yet" + ) + return EndpointPlan(trait=trait, bdd=bdd, client_context_fields=fields) + + +def client_context_fields( + service: _model.ServiceShape, *, reserved: Collection[str] = () +) -> tuple[ClientContextField, ...]: + """The config field for each ``clientContextParams`` entry, in trait order. + + :raises CodegenError: If an entry's type is not boolean or string, or two + fields, or a field and a reserved name, share an attribute. + """ + if not service.has_trait(_CLIENT_CONTEXT_PARAMS): + return () + entries = _object(service.get_trait(_CLIENT_CONTEXT_PARAMS), "clientContextParams") + fields: list[ClientContextField] = [] + taken = dict.fromkeys(reserved, "") + for name, value in entries.items(): + definition = _object(value, f"client context parameter {name}") + type_ = _FIELD_TYPES.get(_string(definition.get("type"), f"{name} type")) + if type_ is None: + raise _exceptions.CodegenError( + f"Unsupported type {definition.get('type')} for client context " + f"parameter {name} of {service.id}" + ) + attribute = _symbols._name(name) # pyright: ignore[reportPrivateUsage] + if attribute in taken: + other = taken[attribute] + raise _exceptions.CodegenError( + f"Client context parameter {name} of {service.id} maps to the " + f"config field {attribute}, which " + + (f"{other} also maps to" if other else "the config already has") + ) + taken[attribute] = name + documentation = definition.get("documentation") + fields.append( + ClientContextField( + parameter=name, + attribute=attribute, + type=type_, + documentation=documentation + if isinstance(documentation, str) + else f"The {name} endpoint parameter.", + ) + ) + return tuple(fields) + + +def lower( + trait: Mapping[str, _model.Node], client_context_attributes: Mapping[str, str] +) -> EndpointBdd: + """Lower an endpointBdd trait value into an endpoint BDD. + + :param trait: The trait's JSON value. + :param client_context_attributes: The config attribute each of the service's + clientContextParams reads, by parameter name. + :raises CodegenError: If the trait is invalid or uses an unsupported version. + """ + return _Lowering(trait, client_context_attributes).bdd() + + +def write_endpoints(writer: PythonWriter, plan: EndpointPlan) -> None: + """Write the ``BDD`` constant of a generated endpoints module.""" + bdd = plan.bdd + writer.line("# fmt: off") + writer.line("# Tags: ref=0, attr=1, call=2, list=3, map=4, error=5, endpoint=6.") + writer.line("BDD = ", _ENDPOINT_BDD_TYPE, "(") + with writer.indent(): + if bdd.parameters: + writer.line( + "# (name, type, required, default, builtin, client_context_attribute)" + ) + _write_items(writer, "parameters", bdd.parameters, None) + writer.line("functions=", literal(bdd.functions), ",") + comments = [ + _condition_text(_object(condition, "condition")) + for condition in _array(plan.trait.get("conditions"), "conditions") + ] + _write_items(writer, "conditions", bdd.conditions, comments) + # Nodes point at results by index, so each result carries its index. + results = ["no match", *("" for _ in bdd.results[1:])] + _write_items(writer, "results", bdd.results, results) + writer.line("root=", _reference(bdd.root), ",") + _write_nodes(writer, bdd.nodes) + writer.line(")") + writer.line("# fmt: on") + + +def literal(value: Value) -> str: + """Render a lowered value as a one-line Python literal.""" + if value is None: + return "None" + if isinstance(value, bool): + return "True" if value else "False" + if isinstance(value, int): + return str(value) + if isinstance(value, str): + return _string_literal(value) + items = ", ".join(map(literal, value)) + return f"({items},)" if len(value) == 1 else f"({items})" + + +# Verbatim from smithy-typescript AddDefaultEndpointRuleSet.DEFAULT_RULESET, +# compiled by Smithy's CompileBdd. +MANUAL_ENDPOINT_BDD: Final[Mapping[str, _model.Node]] = { + "version": "1.1", + "parameters": { + "endpoint": { + "type": "string", + "builtIn": "SDK::Endpoint", + "documentation": "Endpoint used for making requests. Should be " + "formatted as a URI.", + } + }, + "conditions": ({"fn": "isSet", "argv": ({"ref": "endpoint"},)},), + "results": ( + { + "conditions": (), + "endpoint": {"url": {"ref": "endpoint"}}, + "type": "endpoint", + }, + { + "conditions": (), + "error": "(default endpointRuleSet) endpoint is not set - you must " + "configure an endpoint.", + "type": "error", + }, + ), + "root": 2, + "nodeCount": 2, + "nodes": base64.b64encode( + struct.pack(">6i", -1, 1, -1, 0, 100_000_001, 100_000_002) + ).decode(), +} +"""The endpointBdd of a service with no endpoint rules: it requires an endpoint.""" + +# The functions smithy_core.endpoints evaluates without an extension. +STANDARD_FUNCTIONS: Final = frozenset( + { + "booleanEquals", + "coalesce", + "isSet", + "isValidHostLabel", + "ite", + "not", + "parseURL", + "split", + "stringEquals", + "substring", + "uriEncode", + } +) + +RESULT_OFFSET: Final = 100_000_000 +"""BDD references at or above this value point at results.""" + +# Tags lead expression and result tuples; smithy_core.endpoints._types.Tag has the +# same values. +_REF: Final = 0 +_ATTR: Final = 1 +_CALL: Final = 2 +_LIST: Final = 3 +_MAP: Final = 4 +_ERROR: Final = 5 +_ENDPOINT: Final = 6 + +_ENDPOINT_BDD: Final = _model.ShapeId("smithy.rules", "endpointBdd") +_ENDPOINT_RULE_SET: Final = _model.ShapeId("smithy.rules", "endpointRuleSet") +_CLIENT_CONTEXT_PARAMS: Final = _model.ShapeId("smithy.rules", "clientContextParams") +_FIELD_TYPES: Final = {"boolean": "bool", "string": "str"} +_ENDPOINT_BDD_TYPE: Final = TypeReference( + "EndpointBdd", + "smithy_core.endpoints", + dependencies=(_dependencies.SMITHY_CORE,), +) +_INDEX: Final = re.compile(r"[+-]?[0-9]+") +_ESCAPES: Final = {"\\": "\\\\", '"': '\\"', "\n": "\\n", "\r": "\\r", "\t": "\\t"} + + +class _Lowering: + def __init__( + self, + trait: Mapping[str, _model.Node], + client_context_attributes: Mapping[str, str], + ) -> None: + self._trait = trait + self._client_context_attributes = client_context_attributes + self._references: set[str] = set() + self._functions: set[str] = set() + + def bdd(self) -> EndpointBdd: + trait = self._trait + version = trait.get("version") + if version != "1.1": + raise _invalid( + f"endpointBdd version {version} is not supported; expected 1.1" + ) + parameters = _object(trait.get("parameters"), "parameters") + conditions = tuple( + self._condition(_object(condition, "condition")) + for condition in _array(trait.get("conditions"), "conditions") + ) + rules = _array(trait.get("results"), "results") + results: tuple[Value, ...] = ( + None, + *( + self._result(index, _object(rule, f"result {index}")) + for index, rule in enumerate(rules, start=1) + ), + ) + nodes = self._nodes() + return EndpointBdd( + parameters=self._parameters(parameters), + functions=tuple(sorted(self._functions)), + conditions=conditions, + results=results, + root=_int(trait.get("root"), "root"), + nodes=nodes, + ) + + # Normalized parameter fields; unread optional parameters are dropped. + def _parameters(self, parameters: Mapping[str, _model.Node]) -> tuple[Value, ...]: + lowered: list[Value] = [] + for name, value in parameters.items(): + definition = _object(value, f"parameter {name}") + required = definition.get("required", False) + if not isinstance(required, bool): + raise _invalid(f"parameter {name} required must be a boolean") + if not required and name not in self._references: + continue + builtin = definition.get("builtIn") + if builtin is not None: + builtin = _string(builtin, f"parameter {name} builtIn") + default = definition.get("default") + lowered.append( + ( + name, + _parameter_type(definition.get("type"), name), + required, + None if default is None else _default(default, name), + builtin, + self._client_context_attributes.get(name), + ) + ) + return tuple(lowered) + + def _condition(self, condition: Mapping[str, _model.Node]) -> Value: + assign = condition.get("assign") + return ( + self._function(condition), + None if assign is None else _string(assign, "condition assign"), + ) + + # Results after the no-match result at index 0. + def _result(self, index: int, rule: Mapping[str, _model.Node]) -> Value: + if _array(rule.get("conditions", ()), f"result {index} conditions"): + raise _invalid(f"result {index} has conditions") + kind = rule.get("type") + if kind == "error": + return (_ERROR, self._expression(rule.get("error"))) + if kind == "endpoint": + endpoint = _object(rule.get("endpoint"), f"result {index} endpoint") + properties = _object(endpoint.get("properties", {}), "endpoint properties") + headers = _object(endpoint.get("headers", {}), "endpoint headers") + return ( + _ENDPOINT, + self._expression(endpoint.get("url")), + self._map(properties) if properties else None, + tuple( + ( + name, + tuple( + self._expression(item) + for item in _array(values, f"header {name}") + ), + ) + for name, values in headers.items() + ), + ) + raise _invalid(f"result {index} is not an endpoint or error result") + + def _expression(self, node: _model.Node) -> Value: + if isinstance(node, Mapping): + has_ref = "ref" in node + if has_ref == ("fn" in node): + raise _invalid("an expression object needs exactly one of ref or fn") + if has_ref: + return (_REF, self._name(_string(node["ref"], "ref"))) + return self._function(node) + return self._literal(node) + + def _function(self, node: Mapping[str, _model.Node]) -> Value: + name = _string(node.get("fn"), "fn") + arguments = _array(node.get("argv"), f"{name} argv") + if name == "getAttr": + if len(arguments) != 2: + raise _invalid("getAttr takes two arguments") + target = self._expression(arguments[0]) + return (_ATTR, target, _path(_string(arguments[1], "getAttr path"))) + self._functions.add(name) + return (_CALL, name, *map(self._expression, arguments)) + + def _literal(self, node: _model.Node) -> Value: + if isinstance(node, bool): + return node + if isinstance(node, int): + return node + if isinstance(node, str): + return self._template(node) + if isinstance(node, tuple): + return (_LIST, *map(self._literal, node)) + if isinstance(node, Mapping): + return self._map(node) + raise _invalid(f"unsupported literal {node!r}") + + def _map(self, members: Mapping[str, _model.Node]) -> Value: + return (_MAP, tuple(members), *map(self._literal, members.values())) + + # Every string in an expression position is a template, kept as a template + # string. It is rendered back from its parsed parts. + def _template(self, template: str) -> str: + parts: list[str] = [] + for is_placeholder, part in _template_parts(template): + if is_placeholder: + parts.append("{" + self._placeholder(part) + "}") + else: + parts.append(part.replace("{", "{{").replace("}", "}}")) + return "".join(parts) + + def _placeholder(self, raw: str) -> str: + if "#" in raw: + name, path = raw.split("#", 1) + return self._name(name) + "#" + _path(path) + return self._name(raw) + + def _name(self, name: str) -> str: + self._references.add(name) + return name + + # Nodes copied verbatim. Smithy's validator checks the indexes and references, + # but not that node 0 is the terminal the runtime relies on, nor that no edge + # complements a result reference. + def _nodes(self) -> tuple[int, ...]: + trait = self._trait + count = _int(trait.get("nodeCount"), "nodeCount") + try: + data = base64.b64decode(_string(trait.get("nodes"), "nodes"), validate=True) + except binascii.Error as error: + raise _invalid("nodes are not base64") from error + if count < 1 or len(data) != count * 12: + raise _invalid(f"nodes do not hold {count} nodes") + nodes = struct.unpack(f">{count * 3}i", data) + if nodes[:3] != (-1, 1, -1): + raise _invalid("node 0 must be the terminal (-1, 1, -1)") + for index in range(count): + if min(nodes[index * 3 + 1 : index * 3 + 3]) <= -RESULT_OFFSET: + raise _invalid(f"node {index} complements a result reference") + return nodes + + +def _template_parts(template: str) -> list[tuple[bool, str]]: + """Split a template into (is_placeholder, text) parts, as Smithy parses it. + + Literal text is unescaped and a placeholder's text is the raw text between its + braces. + """ + parts: list[tuple[bool, str]] = [] + start: int | None = None + depth = 0 + end = 0 + i = 0 + while i < len(template): + if template.startswith(("{{", "}}"), i): + i += 2 + continue + if template[i] == "{": + if depth == 0: + if end != i: + parts.append((False, _unescape(template[end:i]))) + start = i + 1 + depth += 1 + if template[i] == "}": + depth -= 1 + if depth < 0: + raise _invalid(f"unmatched }} in template {template!r}") + if depth == 0: + assert start is not None # noqa: S101 - set when depth became 1 + parts.append((True, template[start:i])) + start = None + end = i + 1 + i += 1 + if depth != 0: + raise _invalid(f"unmatched {{ in template {template!r}") + if end < len(template): + parts.append((False, _unescape(template[end:]))) + return parts + + +def _unescape(text: str) -> str: + return text.replace("{{", "{").replace("}}", "}") + + +# A getAttr path, parsed as Smithy parses it and written back: keys joined by '.', +# each index as [i]. +def _path(path: str) -> str: + components = path.split(".") + # Java's String.split drops trailing empty components. + while components and not components[-1]: + components.pop() + text = "" + for component in components or [""]: + bracket = component.find("[") + if bracket < 0: + text += ("." if text else "") + component + continue + index = component[bracket + 1 : -1] + if not component.endswith("]") or not _INDEX.fullmatch(index): + raise _invalid(f"invalid getAttr path component {component!r}") + if bracket > 0: + text += ("." if text else "") + component[:bracket] + text += f"[{int(index)}]" + if not text: + raise _invalid(f"empty getAttr path {path!r}") + return text + + +def _parameter_type(node: _model.Node, name: str) -> str: + value = _string(node, f"parameter {name} type") + if value.lower() in ("string", "boolean"): + return value.lower() + if value == "stringArray": + return value + raise _invalid(f"parameter {name} has unsupported type {value}") + + +def _default(node: _model.Node, name: str) -> Value: + if isinstance(node, str | bool): + return node + if isinstance(node, tuple) and all(isinstance(item, str) for item in node): + return tuple(item for item in node if isinstance(item, str)) + raise _invalid(f"parameter {name} has unsupported default {node!r}") + + +def _condition_text(condition: Mapping[str, _model.Node]) -> str: + """A condition as Smithy's ``Condition.toString`` writes it.""" + text = _expression_text(condition) + assign = condition.get("assign") + return f"{assign} = {text}" if isinstance(assign, str) else text + + +def _expression_text(node: _model.Node) -> str: + if isinstance(node, Mapping): + if "ref" in node: + return str(node["ref"]) + arguments = _array(node.get("argv"), "argv") + if node.get("fn") == "getAttr": + return f"{_expression_text(arguments[0])}#{arguments[1]}" + return f"{node.get('fn')}({', '.join(map(_expression_text, arguments))})" + return _literal_text(node) + + +def _literal_text(node: _model.Node) -> str: + if isinstance(node, bool): + return "true" if node else "false" + if isinstance(node, str): + return f'"{node}"' + if isinstance(node, tuple): + return "[" + ", ".join(map(_literal_text, node)) + "]" + if isinstance(node, Mapping): + members = ", ".join(f"{k}={_literal_text(v)}" for k, v in node.items()) + return "{" + members + "}" + return str(node) + + +def _write_items( + writer: PythonWriter, + field: str, + items: tuple[Value, ...], + comments: list[str] | None, +) -> None: + if not items: + writer.line(field, "=(),") + return + writer.line(field, "=(") + with writer.indent(): + for index, item in enumerate(items): + comment = "" + if comments is not None: + text = comments[index] + printable = text and all(" " <= c <= "~" for c in text) + comment = f" # {index}" + (f": {text}" if printable else "") + writer.line(literal(item), ",", comment) + writer.line("),") + + +def _write_nodes(writer: PythonWriter, nodes: tuple[int, ...]) -> None: + if not nodes: + writer.line("nodes=(),") + return + writer.line( + "# (condition, high, low); 1 and -1 are terminals, a negative reference is a" + ) + writer.line("# complement edge, and 100_000_000 + k is result k.") + writer.line("nodes=(") + with writer.indent(): + for index in range(0, len(nodes), 3): + variable, high, low = nodes[index : index + 3] + writer.line(f"{variable}, {_reference(high)}, {_reference(low)},") + writer.line("),") + + +# A node or result reference; result references are written 100_000_000 + k, so k is +# easy to read. +def _reference(ref: int) -> str: + return str(ref) if ref < RESULT_OFFSET else f"{ref:_}" + + +# An ASCII-only, double-quoted Python str literal. +def _string_literal(value: str) -> str: + out: list[str] = [] + for char in value: + code = ord(char) + if char in _ESCAPES: + out.append(_ESCAPES[char]) + elif code < 0x20 or code == 0x7F: + out.append(f"\\x{code:02x}") + elif code < 0x7F: + out.append(char) + elif code <= 0xFFFF: + out.append(f"\\u{code:04x}") + else: + out.append(f"\\U{code:08x}") + return '"' + "".join(out) + '"' + + +def _object(node: _model.Node, what: str) -> Mapping[str, _model.Node]: + if not isinstance(node, Mapping): + raise _invalid(f"{what} must be an object") + return node + + +def _array(node: _model.Node, what: str) -> tuple[_model.Node, ...]: + if not isinstance(node, tuple): + raise _invalid(f"{what} must be an array") + return node + + +def _string(node: _model.Node, what: str) -> str: + if not isinstance(node, str): + raise _invalid(f"{what} must be a string") + return node + + +def _int(node: _model.Node, what: str) -> int: + if isinstance(node, bool) or not isinstance(node, int): + raise _invalid(f"{what} must be an integer") + return node + + +def _invalid(message: str) -> _exceptions.CodegenError: + return _exceptions.CodegenError(f"Invalid endpointBdd trait: {message}") diff --git a/packages/smithy-python/src/smithy_python/clients.py b/packages/smithy-python/src/smithy_python/clients.py index fb1ffa310..3429e9099 100644 --- a/packages/smithy-python/src/smithy_python/clients.py +++ b/packages/smithy-python/src/smithy_python/clients.py @@ -42,8 +42,9 @@ def generate( ) -> None: """Register every file and dependency in the generation context. - :raises CodegenError: If no supported protocol can be selected, or the - service needs a feature client generation does not support yet. + :raises CodegenError: If no supported protocol can be selected, the + service's endpoint rules are unsupported, or the service needs another + feature client generation does not support yet. """ plan = self._plan service = plan.selection.service @@ -52,9 +53,10 @@ def generate( service, context.settings.protocol, self._protocols ) _client_emitter.check_supported(plan) + endpoints = _client_emitter.plan_endpoints(plan) _schemas.SchemaGenerator().generate(context) _models.ModelGenerator().generate(context) - _client_emitter.write_client(context, plan, protocol) + _client_emitter.write_client(context, plan, protocol, endpoints) def context( self, diff --git a/packages/smithy-python/src/smithy_python/schemas.py b/packages/smithy-python/src/smithy_python/schemas.py index bac9538a7..d4757bfb0 100644 --- a/packages/smithy-python/src/smithy_python/schemas.py +++ b/packages/smithy-python/src/smithy_python/schemas.py @@ -320,7 +320,10 @@ def _shape_id(value: str) -> _model.ShapeId: "smithy.api#timestampFormat", "smithy.synthetic#originalShapeId", "aws.api#service", - "smithy.rules#endpointBdd", + # Endpoint parameter plans read these at runtime. + "smithy.rules#contextParam", + "smithy.rules#staticContextParams", + "smithy.rules#operationContextParams", "smithy.api#longPoll", "smithy.api#requestCompression", "smithy.api#jsonName", diff --git a/packages/smithy-python/tests/unit/test_client_generation.py b/packages/smithy-python/tests/unit/test_client_generation.py index 20adddb6a..7e5d2a001 100644 --- a/packages/smithy-python/tests/unit/test_client_generation.py +++ b/packages/smithy-python/tests/unit/test_client_generation.py @@ -2,8 +2,10 @@ # SPDX-License-Identifier: Apache-2.0 import asyncio +import base64 import importlib import json +import struct import subprocess import sys from collections.abc import Callable @@ -14,6 +16,7 @@ import pytest from smithy_cbor import loads from smithy_core.aio.types import AsyncBytesReader +from smithy_core.exceptions import EndpointResolutionError from smithy_core.retries import SimpleRetryStrategy from smithy_http import HTTPResponse, tuples_to_fields from smithy_http.interfaces import HTTPRequest, HTTPRequestConfiguration @@ -404,3 +407,81 @@ def test_a_service_with_both_protocols_needs_a_protocol_selection() -> None: model = load_model({"smithy": "2.0", "shapes": shapes}) generator = ClientGenerator(ClientPlan.from_model(model, settings)) generator.generate(generator.context()) + + +def _add_endpoint_rules(shapes: dict[str, Any]) -> None: + nodes = (-1, 1, -1, 0, 100_000_001, 100_000_002) + traits = shapes["example#Greeter"]["traits"] + traits["smithy.rules#clientContextParams"] = { + "Stage": {"type": "string", "documentation": "The deployment stage."} + } + traits["smithy.rules#endpointBdd"] = { + "version": "1.1", + "parameters": { + "Stage": {"type": "string"}, + "Name": {"type": "string"}, + "Op": {"type": "string"}, + }, + "conditions": [{"fn": "isSet", "argv": [{"ref": "Stage"}]}], + "results": [ + { + "conditions": [], + "type": "endpoint", + "endpoint": {"url": "https://{Name}-{Op}.{Stage}.example.com"}, + }, + {"conditions": [], "type": "error", "error": "Stage is not set"}, + ], + "root": 2, + "nodeCount": 2, + "nodes": base64.b64encode(struct.pack(">6i", *nodes)).decode(), + } + shapes["example#GreetInput"]["members"]["name"]["traits"][ + "smithy.rules#contextParam" + ] = {"name": "Name"} + shapes["example#Greet"]["traits"]["smithy.rules#staticContextParams"] = { + "Op": {"value": "greet"} + } + + +def test_endpoint_rules_read_config_input_and_operation_parameters( + tmp_path: Path, monkeypatch: pytest.MonkeyPatch +) -> None: + shapes = _shapes() + _add_endpoint_rules(shapes) + _generate(tmp_path, "greeter_rules", shapes) + config_source = (tmp_path / "src/greeter_rules/config.py").read_text() + assert "stage: str | None\n" in config_source + assert '"The deployment stage."' in config_source + + monkeypatch.syspath_prepend( # pyright: ignore[reportUnknownMemberType] + str(tmp_path / "src") + ) + package = importlib.import_module("greeter_rules") + transport = _Transport(body=_cbor_map({"greeting": "Hi"})) + retry = SimpleRetryStrategy(max_attempts=1) + client = package.Greeter( + package.Config(stage="beta", transport=transport, retry_strategy=retry) + ) + client.greet(name="ana") + (request,) = transport.requests + assert request.destination.host == "ana-greet.beta.example.com" + + unstaged = package.Greeter( + package.Config(transport=transport, retry_strategy=retry) + ) + with pytest.raises(EndpointResolutionError, match="Stage is not set"): + unstaged.greet(name="ana") + + +def test_a_service_without_rules_requires_an_endpoint_uri( + package: ModuleType, +) -> None: + transport = _Transport() + client = package.Greeter( + package.Config( + transport=transport, retry_strategy=SimpleRetryStrategy(max_attempts=1) + ) + ) + with pytest.raises(EndpointResolutionError, match="must configure an endpoint"): + client.ping() + assert not transport.requests diff --git a/packages/smithy-python/tests/unit/test_endpoints.py b/packages/smithy-python/tests/unit/test_endpoints.py new file mode 100644 index 000000000..02b4d2d1f --- /dev/null +++ b/packages/smithy-python/tests/unit/test_endpoints.py @@ -0,0 +1,475 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +import base64 +import struct +from collections.abc import Mapping +from typing import Any + +import pytest +from smithy_core.endpoints import BddEndpointResolver, EndpointBdd +from smithy_python._endpoints import ( + MANUAL_ENDPOINT_BDD, + EndpointPlan, + client_context_fields, + literal, + lower, + plan_endpoints, + write_endpoints, +) +from smithy_python.exceptions import CodegenError +from smithy_python.model import Node, ServiceShape, load_model +from smithy_python.writer import PythonWriter + +_PARAMETERS = { + "Region": { + "type": "String", + "builtIn": "AWS::Region", + "documentation": "The region.", + }, + "UseFIPS": { + "type": "Boolean", + "required": True, + "default": False, + "builtIn": "AWS::UseFIPS", + "deprecated": {"message": "old"}, + }, + "Endpoint": {"type": "string", "builtIn": "SDK::Endpoint"}, + "Key": {"type": "string"}, + "Bucket": {"type": "String", "required": True}, + "ForcePathStyle": {"type": "boolean", "builtIn": "AWS::S3::ForcePathStyle"}, + "Tables": {"type": "stringArray", "required": True, "default": ["a", "b"]}, + "Unused": {"type": "boolean", "default": True, "required": True}, +} + +_CONDITIONS: list[Any] = [ + {"fn": "isSet", "argv": [{"ref": "Endpoint"}]}, + {"fn": "parseURL", "argv": ["{Endpoint}"], "assign": "url"}, + {"fn": "booleanEquals", "argv": [{"ref": "UseFIPS"}, True]}, + { + "fn": "stringEquals", + "argv": [{"fn": "getAttr", "argv": [{"ref": "url"}, "scheme"]}, "http"], + }, + {"fn": "isSet", "argv": [{"ref": "Region"}]}, + {"fn": "isValidHostLabel", "argv": [{"ref": "Region"}, False]}, + { + "fn": "stringEquals", + "argv": [ + { + "fn": "coalesce", + "argv": [ + {"fn": "substring", "argv": [{"ref": "Bucket"}, 0, 4, False]}, + "", + ], + }, + "ab{{c}}", + ], + }, + {"fn": "split", "argv": [{"ref": "Bucket"}, "--", 0], "assign": "parts"}, + {"fn": "isSet", "argv": [{"fn": "getAttr", "argv": [{"ref": "parts"}, "[-1]"]}]}, + { + "fn": "ite", + "argv": [ + {"fn": "coalesce", "argv": [{"ref": "ForcePathStyle"}, False]}, + "path", + "vhost", + ], + "assign": "style", + }, +] + +_RESULTS: list[Any] = [ + { + "conditions": [], + "type": "error", + "error": "Invalid {Region}: {{escaped}} {Bucket}{Bucket}", + }, + { + "conditions": [], + "type": "endpoint", + "endpoint": { + "url": "{url#scheme}://{url#authority}{url#path}", + "properties": { + "authSchemes": [ + { + "name": "sigv4", + "signingRegion": "{Region}", + "disableDoubleEncoding": True, + } + ], + "literal": { + "ref": "Region", + "fn": "isSet", + "n": 2, + "list": ["{style}", ["x"]], + }, + }, + "headers": {"x-b": ["{Region}", "b"], "x-a": []}, + }, + }, + { + "conditions": [], + "type": "endpoint", + "endpoint": {"url": {"ref": "Endpoint"}, "properties": {}, "headers": {}}, + }, + { + "conditions": [], + "type": "endpoint", + "endpoint": {"url": "https://{Bucket}.example.com"}, + }, +] + +_NODES = (-1, 1, -1, 0, 3, 100_000_003, 1, 100_000_002, 100_000_001) + + +def _raw_trait( + parameters: Mapping[str, Any] = _PARAMETERS, + conditions: list[Any] = _CONDITIONS, + results: list[Any] = _RESULTS, + root: int = 2, + nodes: tuple[int, ...] = _NODES, + version: str = "1.1", +) -> dict[str, Any]: + return { + "version": version, + "parameters": parameters, + "conditions": conditions, + "results": results, + "root": root, + "nodeCount": len(nodes) // 3, + "nodes": base64.b64encode(struct.pack(f">{len(nodes)}i", *nodes)).decode(), + } + + +def _trait(**changes: Any) -> Mapping[str, Node]: + service = _service({"smithy.rules#endpointBdd": _raw_trait(**changes)}) + value = service.get_trait("smithy.rules#endpointBdd") + assert isinstance(value, Mapping) + return value + + +def _service(traits: Mapping[str, Any]) -> ServiceShape: + model = load_model( + { + "smithy": "2.0", + "shapes": {"example#Service": {"type": "service", "traits": traits}}, + } + ) + return model.expect_shape("example#Service", ServiceShape) + + +def _lines(items: tuple[Any, ...]) -> list[str]: + return [literal(item) for item in items] + + +def test_rejects_other_trait_versions() -> None: + with pytest.raises(CodegenError, match=r"version 1\.2"): + lower(_trait(version="1.2"), {}) + + +def test_normalizes_and_drops_parameters() -> None: + bdd = lower(_trait(), {"ForcePathStyle": "path_style"}) + # Key is optional and unread, so it is dropped. Unused and Tables are required. + assert literal(bdd.parameters) == ( + '(("Region", "string", False, None, "AWS::Region", None), ' + '("UseFIPS", "boolean", True, False, "AWS::UseFIPS", None), ' + '("Endpoint", "string", False, None, "SDK::Endpoint", None), ' + '("Bucket", "string", True, None, None, None), ' + '("ForcePathStyle", "boolean", False, None, "AWS::S3::ForcePathStyle", ' + '"path_style"), ' + '("Tables", "stringArray", True, ("a", "b"), None, None), ' + '("Unused", "boolean", True, True, None, None))' + ) + + +def test_keeps_parameters_read_as_get_attr_bases() -> None: + bdd = lower( + _trait( + parameters={ + "A": {"type": "string"}, + "T": {"type": "stringArray"}, + "C": {"type": "string"}, + }, + conditions=[ + {"fn": "isSet", "argv": [{"ref": "A"}]}, + {"fn": "isSet", "argv": [{"ref": "T"}]}, + { + "fn": "isSet", + "argv": [{"fn": "getAttr", "argv": [{"ref": "T"}, "[0]"]}], + }, + ], + results=[{"conditions": [], "type": "error", "error": "{A}"}], + root=100_000_001, + nodes=(-1, 1, -1), + ), + {}, + ) + # C is optional and unread, so it is dropped. + assert literal(bdd.parameters) == ( + '(("A", "string", False, None, None, None), ' + '("T", "stringArray", False, None, None, None))' + ) + + +def test_sorts_functions_by_code_point() -> None: + assert lower(_trait(), {}).functions == ( + "booleanEquals", + "coalesce", + "isSet", + "isValidHostLabel", + "ite", + "parseURL", + "split", + "stringEquals", + "substring", + ) + + +def test_lowers_conditions() -> None: + conditions = _lines(lower(_trait(), {}).conditions) + assert conditions[0] == '((2, "isSet", (0, "Endpoint")), None)' + # A string argument that is a single placeholder is still a template. + assert conditions[1] == '((2, "parseURL", "{Endpoint}"), "url")' + assert conditions[2] == '((2, "booleanEquals", (0, "UseFIPS"), True), None)' + assert conditions[3] == ( + '((2, "stringEquals", (1, (0, "url"), "scheme"), "http"), None)' + ) + assert conditions[5] == '((2, "isValidHostLabel", (0, "Region"), False), None)' + # Literal strings keep their escaped braces, and integers stay integers. + assert conditions[6] == ( + '((2, "stringEquals", (2, "coalesce", ' + '(2, "substring", (0, "Bucket"), 0, 4, False), ""), "ab{{c}}"), None)' + ) + assert conditions[7] == '((2, "split", (0, "Bucket"), "--", 0), "parts")' + # A negative index counts from the end. + assert conditions[8] == '((2, "isSet", (1, (0, "parts"), "[-1]")), None)' + assert conditions[9] == ( + '((2, "ite", (2, "coalesce", (0, "ForcePathStyle"), False), ' + '"path", "vhost"), "style")' + ) + + +def test_lowers_results() -> None: + results = _lines(lower(_trait(), {}).results) + assert results[0] == "None" + assert results[1] == '(5, "Invalid {Region}: {{escaped}} {Bucket}{Bucket}")' + # Objects in properties are maps even with ref or fn keys. Header order is kept. + assert results[2] == ( + '(6, "{url#scheme}://{url#authority}{url#path}", ' + '(4, ("authSchemes", "literal"), ' + '(3, (4, ("name", "signingRegion", "disableDoubleEncoding"), "sigv4", ' + '"{Region}", True)), ' + '(4, ("ref", "fn", "n", "list"), "Region", "isSet", 2, ' + '(3, "{style}", (3, "x")))), ' + '(("x-b", ("{Region}", "b")), ("x-a", ())))' + ) + # Empty properties become None and empty headers (). + assert results[3] == '(6, (0, "Endpoint"), None, ())' + assert results[4] == '(6, "https://{Bucket}.example.com", None, ())' + assert len(results) == 5 + + +@pytest.mark.parametrize( + ("template", "expected"), + [ + ("{{{url#authority} }} {Endpoint}{{}}", "{{{url#authority} }} {Endpoint}{{}}"), + ("{url#a.b[1]}", "{url#a.b[1]}"), + ("{url#[+1]}", "{url#[1]}"), + ("{url#.a}", "{url#a}"), + ], +) +def test_renders_templates_from_their_parsed_parts( + template: str, expected: str +) -> None: + bdd = lower( + _trait( + parameters={"Endpoint": {"type": "string", "required": True}}, + conditions=[ + {"fn": "parseURL", "argv": [{"ref": "Endpoint"}], "assign": "url"} + ], + results=[{"conditions": [], "type": "error", "error": template}], + nodes=(-1, 1, -1, 0, 100_000_001, 1), + ), + {}, + ) + assert bdd.results[1] == (5, expected) + + +@pytest.mark.parametrize( + ("template", "message"), + [ + ("{a", "unmatched {"), + ("a}", "unmatched }"), + ("{url#a[x]}", "invalid getAttr path"), + ("{url#.}", "empty getAttr path"), + ], +) +def test_rejects_malformed_templates(template: str, message: str) -> None: + with pytest.raises(CodegenError, match=message): + lower( + _trait( + results=[{"conditions": [], "type": "error", "error": template}], + nodes=(-1, 1, -1), + root=-1, + ), + {}, + ) + + +def test_copies_nodes_verbatim() -> None: + nodes = (-1, 1, -1, 0, -3, 1, 1, 100_000_001, -1) + assert lower(_trait(nodes=nodes), {}).nodes == nodes + + +def test_accepts_terminal_root() -> None: + bdd = lower(_trait(root=-1, nodes=(-1, 1, -1)), {}) + assert bdd.root == -1 + assert bdd.nodes == (-1, 1, -1) + + +@pytest.mark.parametrize( + ("nodes", "message"), + [ + ((-1, 1, -1, 0, -100_000_001, 1), "node 1 complements a result reference"), + ((0, 1, -1, 0, 1, -1), "node 0"), + ], +) +def test_rejects_invalid_nodes(nodes: tuple[int, ...], message: str) -> None: + with pytest.raises(CodegenError, match=message): + lower(_trait(nodes=nodes), {}) + + +def test_rejects_results_with_conditions() -> None: + results = [{**_RESULTS[0], "conditions": [_CONDITIONS[0]]}] + with pytest.raises(CodegenError, match="result 1 has conditions"): + lower(_trait(results=results), {}) + + +def test_renders_literals() -> None: + assert literal(()) == "()" + assert literal(("a",)) == '("a",)' + assert literal((None, True, False, -5)) == "(None, True, False, -5)" + assert literal('q"b\\n\n\t\x01é😀') == '"q\\"b\\\\n\\n\\t\\x01\\u00e9\\U0001f600"' + + +def test_writes_the_endpoints_module() -> None: + trait = _trait( + parameters={"Endpoint": {"type": "string", "builtIn": "SDK::Endpoint"}}, + conditions=[{"fn": "isSet", "argv": [{"ref": "Endpoint"}]}], + results=[ + { + "conditions": [], + "type": "endpoint", + "endpoint": {"url": {"ref": "Endpoint"}}, + }, + {"conditions": [], "type": "error", "error": "no endpoint"}, + ], + nodes=(-1, 1, -1, 0, 100_000_001, 100_000_002), + ) + writer = PythonWriter("example._private.endpoints") + write_endpoints(writer, EndpointPlan(trait, lower(trait, {}), ())) + assert writer.render() == ( + "from smithy_core.endpoints import EndpointBdd\n" + "\n" + "\n" + "# fmt: off\n" + "# Tags: ref=0, attr=1, call=2, list=3, map=4, error=5, endpoint=6.\n" + "BDD = EndpointBdd(\n" + " # (name, type, required, default, builtin, client_context_attribute)\n" + " parameters=(\n" + ' ("Endpoint", "string", False, None, "SDK::Endpoint", None),\n' + " ),\n" + ' functions=("isSet",),\n' + " conditions=(\n" + ' ((2, "isSet", (0, "Endpoint")), None), # 0: isSet(Endpoint)\n' + " ),\n" + " results=(\n" + " None, # 0: no match\n" + ' (6, (0, "Endpoint"), None, ()), # 1\n' + ' (5, "no endpoint"), # 2\n' + " ),\n" + " root=2,\n" + " # (condition, high, low); 1 and -1 are terminals, a negative reference" + " is a\n" + " # complement edge, and 100_000_000 + k is result k.\n" + " nodes=(\n" + " -1, 1, -1,\n" + " 0, 100_000_001, 100_000_002,\n" + " ),\n" + ")\n" + "# fmt: on\n" + ) + + +def test_written_bdd_evaluates_with_smithy_core() -> None: + trait = _trait() + writer = PythonWriter("example._private.endpoints") + write_endpoints(writer, EndpointPlan(trait, lower(trait, {}), ())) + namespace: dict[str, Any] = {} + exec(writer.render(), namespace) + assert isinstance(namespace["BDD"], EndpointBdd) + BddEndpointResolver(namespace["BDD"]) + + +def test_a_service_without_rules_requires_an_endpoint() -> None: + plan = plan_endpoints(_service({})) + assert plan.trait is MANUAL_ENDPOINT_BDD + assert plan.bdd.parameters == ( + ("endpoint", "string", False, None, "SDK::Endpoint", None), + ) + assert plan.bdd.results[2] == ( + 5, + "(default endpointRuleSet) endpoint is not set - you must configure an " + "endpoint.", + ) + + +def test_a_ruleset_without_a_bdd_is_rejected() -> None: + with pytest.raises(CodegenError, match=r"smithy\.rules#endpointRuleSet without"): + plan_endpoints(_service({"smithy.rules#endpointRuleSet": {}})) + + +def test_functions_outside_the_standard_library_are_rejected() -> None: + conditions = [{"fn": "aws.partition", "argv": ["us-east-1"], "assign": "p"}] + trait = _raw_trait(conditions=conditions, root=-1, nodes=(-1, 1, -1)) + with pytest.raises(CodegenError, match=r"call aws\.partition"): + plan_endpoints(_service({"smithy.rules#endpointBdd": trait})) + + +def test_client_context_fields_are_snake_case_config_fields() -> None: + service = _service( + { + "smithy.rules#clientContextParams": { + "ForcePathStyle": {"type": "boolean", "documentation": "Path style."}, + "UseFIPS": {"type": "boolean"}, + "Stage": {"type": "string"}, + } + } + ) + fields = client_context_fields(service) + assert [(f.parameter, f.attribute, f.type) for f in fields] == [ + ("ForcePathStyle", "force_path_style", "bool"), + ("UseFIPS", "use_fips", "bool"), + ("Stage", "stage", "str"), + ] + assert fields[0].documentation == "Path style." + assert fields[1].documentation == "The UseFIPS endpoint parameter." + + +@pytest.mark.parametrize( + ("parameters", "message"), + [ + ({"Tables": {"type": "stringArray"}}, "Unsupported type stringArray"), + ({"Protocol": {"type": "string"}}, "which the config already has"), + ( + {"UseFips": {"type": "boolean"}, "UseFIPS": {"type": "boolean"}}, + "which UseFips also maps to", + ), + ], +) +def test_client_context_fields_must_be_supported_and_distinct( + parameters: Mapping[str, Any], message: str +) -> None: + service = _service({"smithy.rules#clientContextParams": parameters}) + with pytest.raises(CodegenError, match=message): + client_context_fields(service, reserved={"protocol"}) diff --git a/scripts/verifications/import-cost.json b/scripts/verifications/import-cost.json index 99b6ed08f..dc03ea645 100644 --- a/scripts/verifications/import-cost.json +++ b/scripts/verifications/import-cost.json @@ -16,7 +16,7 @@ "smithy_json": 21, "smithy_json (all public modules)": 21, "smithy_python": 1, - "smithy_python (all public modules)": 24, + "smithy_python (all public modules)": 25, "smithy_test": 44, "smithy_test (all public modules)": 60, "smithy_xml": 20, From d21d48c4b7fe372f52f894850de7f44c90a00cc9 Mon Sep 17 00:00:00 2001 From: Sean O'Brien <60306702+stobrien89@users.noreply.github.com> Date: Tue, 17 Nov 2026 14:16:42 -0500 Subject: [PATCH 3/3] Generate endpoint tests for Python clients --- .../.smithy-python-manifest.json | 20 + .../endpoint-rules-client/README.md | 5 + .../endpoint-rules-client/pyproject.toml | 44 ++ .../src/endpoint_rules_client/__init__.py | 25 + .../_private/__init__.py | 0 .../_private/endpoints.py | 48 ++ .../endpoint_rules_client/_private/schemas.py | 108 ++++ .../src/endpoint_rules_client/aio/__init__.py | 19 + .../src/endpoint_rules_client/aio/client.py | 86 +++ .../src/endpoint_rules_client/aio/config.py | 102 +++ .../src/endpoint_rules_client/client.py | 86 +++ .../src/endpoint_rules_client/config.py | 101 +++ .../src/endpoint_rules_client/models.py | 71 +++ .../src/endpoint_rules_client/models.pyi | 98 +++ .../src/endpoint_rules_client/py.typed | 0 .../tests/test_endpoints.py | 191 ++++++ designs/codegen/client.md | 39 +- ...ture-01b2f761fddb4174ae59f614a52ddf95.json | 2 +- .../src/smithy_python/_client_emitter.py | 9 +- .../src/smithy_python/_endpoint_tests.py | 500 +++++++++++++++ .../src/smithy_python/dependencies.py | 24 + .../tests/unit/test_client_generation.py | 96 +++ .../tests/unit/test_dependencies.py | 6 + scripts/api-snapshot/api.json | 5 +- .../codegen-output-py/client-projections.json | 7 + .../models/endpoint-rules.json | 601 ++++++++++++++++++ .../models/endpoint-rules.smithy | 190 ++++++ scripts/codegen-output-py/pyrightconfig.json | 7 +- .../tests/test_client_snapshots.py | 26 + scripts/verifications/import-cost.json | 2 +- 30 files changed, 2509 insertions(+), 9 deletions(-) create mode 100644 codegen-output-py/endpoint-rules-client/.smithy-python-manifest.json create mode 100644 codegen-output-py/endpoint-rules-client/README.md create mode 100644 codegen-output-py/endpoint-rules-client/pyproject.toml create mode 100644 codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/__init__.py create mode 100644 codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/_private/__init__.py create mode 100644 codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/_private/endpoints.py create mode 100644 codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/_private/schemas.py create mode 100644 codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/aio/__init__.py create mode 100644 codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/aio/client.py create mode 100644 codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/aio/config.py create mode 100644 codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/client.py create mode 100644 codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/config.py create mode 100644 codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/models.py create mode 100644 codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/models.pyi create mode 100644 codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/py.typed create mode 100644 codegen-output-py/endpoint-rules-client/tests/test_endpoints.py create mode 100644 packages/smithy-python/src/smithy_python/_endpoint_tests.py create mode 100644 scripts/codegen-output-py/models/endpoint-rules.json create mode 100644 scripts/codegen-output-py/models/endpoint-rules.smithy diff --git a/codegen-output-py/endpoint-rules-client/.smithy-python-manifest.json b/codegen-output-py/endpoint-rules-client/.smithy-python-manifest.json new file mode 100644 index 000000000..aa397b733 --- /dev/null +++ b/codegen-output-py/endpoint-rules-client/.smithy-python-manifest.json @@ -0,0 +1,20 @@ +{ + "files": { + "README.md": "21b6af5d2c11ca92be799a611365291e00be66fee36e0e94876c35ff323358ec", + "pyproject.toml": "41e367adbc95e6d6198626246c8645aa2d156325785209e97f64267a712c5b75", + "src/endpoint_rules_client/__init__.py": "f85901beed783e493475b1ccde6669b030eafa7a9b98f796d9a62e3d584e5286", + "src/endpoint_rules_client/_private/__init__.py": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "src/endpoint_rules_client/_private/endpoints.py": "f5bec5c0c17f9ec3fab86ea81c1472b1771118e6064f52cbb58cf85d89e09b20", + "src/endpoint_rules_client/_private/schemas.py": "804820a7542d2b6df7be9a0e146c17d81ea02eec9e145c056f859e8f6a2c5871", + "src/endpoint_rules_client/aio/__init__.py": "9d803a788ce4051a5e037f67248d7cb3c278781e1bd8380e8a35a67cca039e13", + "src/endpoint_rules_client/aio/client.py": "b2b375ec339945500d429023176de2aae003eaf2255df15fa9e317af6834d2ca", + "src/endpoint_rules_client/aio/config.py": "dc2b548541bdec4ccf2757638c7fed7a7cb07d432193a87e465274a8f187e557", + "src/endpoint_rules_client/client.py": "33e88867c1dcbac308a159a5974db2c7ddcbfebca1728aa789a6ec49b7e30623", + "src/endpoint_rules_client/config.py": "ec161b5e6c5bc00f5f55d3b4f9a41dc52967e6b80240b58ce3dcc0426a00a129", + "src/endpoint_rules_client/models.py": "74fd08f8085335f26b9aa7c46696666700a0e71235a3ae666a40139c19a8eb18", + "src/endpoint_rules_client/models.pyi": "87c615ea467d648b79ca9bdb0eef29006463720de95f71303a39d908cfc4a277", + "src/endpoint_rules_client/py.typed": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "tests/test_endpoints.py": "f24e7dc5f6052b3f5d2e6b55e77c00f4265579619e453d996056da72fbd2014a" + }, + "version": 1 +} diff --git a/codegen-output-py/endpoint-rules-client/README.md b/codegen-output-py/endpoint-rules-client/README.md new file mode 100644 index 000000000..602cdb0a6 --- /dev/null +++ b/codegen-output-py/endpoint-rules-client/README.md @@ -0,0 +1,5 @@ + + +## endpoint_rules_client Client Package + +Python client for the endpoint rules fixture diff --git a/codegen-output-py/endpoint-rules-client/pyproject.toml b/codegen-output-py/endpoint-rules-client/pyproject.toml new file mode 100644 index 000000000..ec8160ef7 --- /dev/null +++ b/codegen-output-py/endpoint-rules-client/pyproject.toml @@ -0,0 +1,44 @@ +# Code generated by smithy-python-codegen DO NOT EDIT. + +[project] +name = "endpoint_rules_client" +version = "0.0.1" +description = "Python client for the endpoint rules fixture" +readme = "README.md" +requires-python = ">=3.12" +keywords = ["smithy", "endpoint_rules_client"] +license = {text = "Apache-2.0"} +dependencies = [ + "smithy-core~=0.13.0", + "smithy-http[aiohttp,cbor,urllib3]~=0.10.0", +] + +[dependency-groups] +test = [ + "pytest>=9.0.3,<10.0.0", + "pytest-asyncio>=1.3.0,<1.4.0", + "smithy-test~=0.5.0", +] + +[build-system] +requires = [ + "hatchling", +] +build-backend = "hatchling.build" + +[tool.hatch.build.targets.wheel] +packages = [ + "src/endpoint_rules_client", +] + +[tool.pyright] +typeCheckingMode = "strict" + +[tool.ruff] +target-version = "py312" + +[tool.ruff.lint] +ignore = ["F841"] + +[tool.ruff.format] +skip-magic-trailing-comma = true diff --git a/codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/__init__.py b/codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/__init__.py new file mode 100644 index 000000000..ae4cf8845 --- /dev/null +++ b/codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/__init__.py @@ -0,0 +1,25 @@ +from importlib import import_module +from typing import TYPE_CHECKING, Any + +__version__: str = "0.0.1" + +if TYPE_CHECKING: + from .aio.client import AsyncEndpointService + from .aio.config import AsyncConfig + from .client import EndpointService + from .config import Config + +__all__ = ["AsyncConfig", "AsyncEndpointService", "Config", "EndpointService"] + +_EXPORTS = { + "EndpointService": ".client", + "Config": ".config", + "AsyncEndpointService": ".aio.client", + "AsyncConfig": ".aio.config", +} + + +def __getattr__(name: str) -> Any: + if name in _EXPORTS: + return getattr(import_module(_EXPORTS[name], __name__), name) + raise AttributeError(f"module {__name__!r} has no attribute {name!r}") diff --git a/codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/_private/__init__.py b/codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/_private/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/_private/endpoints.py b/codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/_private/endpoints.py new file mode 100644 index 000000000..1cca3f69f --- /dev/null +++ b/codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/_private/endpoints.py @@ -0,0 +1,48 @@ +from smithy_core.endpoints import EndpointBdd + +# fmt: off +# Tags: ref=0, attr=1, call=2, list=3, map=4, error=5, endpoint=6. +BDD = EndpointBdd( + # (name, type, required, default, builtin, client_context_attribute) + parameters=( + ("Endpoint", "string", False, None, "SDK::Endpoint", None), + ("Region", "string", False, None, "AWS::Region", None), + ("Stage", "string", False, None, None, "stage"), + ("ForcePathStyle", "boolean", True, False, None, "force_path_style"), + ("Name", "string", False, None, None, None), + ("Kind", "string", False, None, None, None), + ), + functions=("booleanEquals", "isSet", "isValidHostLabel"), + conditions=( + ((2, "isSet", (0, "Endpoint")), None), # 0: isSet(Endpoint) + ((2, "isSet", (0, "Region")), None), # 1: isSet(Region) + ((2, "booleanEquals", (0, "ForcePathStyle"), True), None), # 2: booleanEquals(ForcePathStyle, true) + ((2, "isSet", (0, "Kind")), None), # 3: isSet(Kind) + ((2, "isSet", (0, "Stage")), None), # 4: isSet(Stage) + ((2, "isSet", (0, "Name")), None), # 5: isSet(Name) + ((2, "isValidHostLabel", (0, "Name"), False), None), # 6: isValidHostLabel(Name, false) + ), + results=( + None, # 0: no match + (6, (0, "Endpoint"), None, ()), # 1 + (6, "https://{Region}.example.com", None, ()), # 2 + (6, "https://path.example.com", None, ()), # 3 + (6, "https://{Name}.{Stage}.example.com", None, (("x-kind", ("{Kind}",)),)), # 4 + (6, "https://{Stage}.example.com", (4, ("kind",), "{Kind}"), ()), # 5 + (5, "No stage"), # 6 + ), + root=2, + # (condition, high, low); 1 and -1 are terminals, a negative reference is a + # complement edge, and 100_000_000 + k is result k. + nodes=( + -1, 1, -1, + 0, 100_000_001, 3, + 1, 100_000_002, 4, + 2, 100_000_003, 5, + 3, 6, 100_000_006, + 4, 7, 100_000_006, + 5, 8, 100_000_005, + 6, 100_000_004, 100_000_005, + ), +) +# fmt: on diff --git a/codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/_private/schemas.py b/codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/_private/schemas.py new file mode 100644 index 000000000..10b959240 --- /dev/null +++ b/codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/_private/schemas.py @@ -0,0 +1,108 @@ +from types import MappingProxyType + +from smithy_core._schema_compact import StaticOperationSchema, StaticSchema + +n0 = "example.endpoints" +_s0 = "PluginNames" +_s1 = "member" +_s2 = "ThingTag" +_s3 = "key" +_s4 = "value" +_s5 = "PutThingInput" +_s6 = "smithy.synthetic#originalShapeId" +_s7 = "example.endpoints#PutThingInput" +_s8 = "smithy.api#input" +_s9 = "name" +_s10 = "smithy.rules#contextParam" +_s11 = "smithy.api#required" +_s12 = "tag" +_s13 = "plugins" +_s14 = "PingInput" +_s15 = "smithy.api#Unit" +_s16 = "PingOutput" +_s17 = "smithy.api#output" +_s18 = "PutThingOutput" +_s19 = "Ping" +_s20 = "smithy.rules#staticContextParams" +_s21 = "PutThing" +_s22 = "EndpointService" +_s23 = "smithy.protocols#rpcv2Cbor" + +PLUGIN_NAMES: StaticSchema = ( + 16, + n0, + _s0, + 0, + (_s1,), + ((3, 0),), +) + +THING_TAG: StaticSchema = ( + 18, + n0, + _s2, + 0, + (_s3, _s4), + ((3, 0), (3, 0)), +) + +PUT_THING_INPUT: StaticSchema = ( + 18, + n0, + _s5, + {_s6: _s7, _s8: None}, + (_s9, _s12, _s13), + ( + (3, {_s10: MappingProxyType({"name": "Name"}), _s11: None}), + (THING_TAG, 0), + (PLUGIN_NAMES, 0), + ), +) + +PING_INPUT: StaticSchema = ( + 18, + n0, + _s14, + {_s6: _s15, _s8: None}, +) + +PING_OUTPUT: StaticSchema = ( + 18, + n0, + _s16, + {_s6: _s15, _s17: None}, +) + +PUT_THING_OUTPUT: StaticSchema = ( + 18, + n0, + _s18, + {_s6: _s15, _s17: None}, +) + +PING: StaticOperationSchema = ( + 23, + n0, + _s19, + {_s20: MappingProxyType({"Kind": MappingProxyType({"value": "ping"})})}, + PING_INPUT, + PING_OUTPUT, + (), +) + +PUT_THING: StaticOperationSchema = ( + 23, + n0, + _s21, + {_s20: MappingProxyType({"Kind": MappingProxyType({"value": "put"})})}, + PUT_THING_INPUT, + PUT_THING_OUTPUT, + (), +) + +ENDPOINT_SERVICE: StaticSchema = ( + 21, + n0, + _s22, + {_s23: None}, +) diff --git a/codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/aio/__init__.py b/codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/aio/__init__.py new file mode 100644 index 000000000..7dee4fc86 --- /dev/null +++ b/codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/aio/__init__.py @@ -0,0 +1,19 @@ +from importlib import import_module +from typing import TYPE_CHECKING, Any + +if TYPE_CHECKING: + from .client import AsyncEndpointService + from .config import AsyncConfig + +__all__ = ["AsyncConfig", "AsyncEndpointService"] + +_EXPORTS = { + "AsyncEndpointService": ".client", + "AsyncConfig": ".config", +} + + +def __getattr__(name: str) -> Any: + if name in _EXPORTS: + return getattr(import_module(_EXPORTS[name], __name__), name) + raise AttributeError(f"module {__name__!r} has no attribute {name!r}") diff --git a/codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/aio/client.py b/codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/aio/client.py new file mode 100644 index 000000000..37e97b008 --- /dev/null +++ b/codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/aio/client.py @@ -0,0 +1,86 @@ +from __future__ import annotations + +from typing import Unpack, overload + +from smithy_core.aio.client import AsyncClient +from smithy_http.plugins import user_agent_plugin + +from endpoint_rules_client import models +from endpoint_rules_client.aio.config import AsyncConfig, Plugin + + +class AsyncEndpointService(AsyncClient[AsyncConfig]): + "A service whose endpoint rules read config, input, and operation values." + + _client_plugins = (user_agent_plugin,) + + @overload + async def ping( + self, + request: models.PingInput | models.PingInputDict, + /, + *, + plugins: list[Plugin] | None = None, + ) -> models.PingOutput: ... + + @overload + async def ping( + self, + /, + *, + plugins: list[Plugin] | None = None, + **kwargs: Unpack[models.PingInputDict], + ) -> models.PingOutput: + """ + Invokes the Ping operation. + + :param plugins: Callables that change the configuration for this call + only. + """ + + async def ping( + self, /, *args: object, plugins: list[Plugin] | None = None, **kwargs: object + ) -> models.PingOutput: + return await self._invoke( + self._select_input(models.PING, args, kwargs), + models.PING, + [], + plugins, + ) + + @overload + async def put_thing( + self, + request: models.PutThingInput | models.PutThingInputDict, + /, + *, + plugins: list[Plugin] | None = None, + ) -> models.PutThingOutput: ... + + @overload + async def put_thing( + self, + /, + *, + plugins: list[Plugin] | None = None, + **kwargs: Unpack[models.PutThingInputDict], + ) -> models.PutThingOutput: + """ + Invokes the PutThing operation. + + :param plugins: Callables that change the configuration for this call + only. + """ + + async def put_thing( + self, /, *args: object, plugins: list[Plugin] | None = None, **kwargs: object + ) -> models.PutThingOutput: + return await self._invoke( + self._select_input(models.PUT_THING, args, kwargs), + models.PUT_THING, + [], + plugins, + ) + + def _new_config(self) -> AsyncConfig: + return AsyncConfig() diff --git a/codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/aio/config.py b/codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/aio/config.py new file mode 100644 index 000000000..4b72802e0 --- /dev/null +++ b/codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/aio/config.py @@ -0,0 +1,102 @@ +from collections.abc import Callable +from dataclasses import dataclass +from typing import Any, cast + +from smithy_core.aio.interfaces import AsyncClientTransport, AsyncEndpointResolver +from smithy_core.aio.interfaces.auth import AsyncAuthScheme +from smithy_core.auth import DefaultAuthResolver +from smithy_core.endpoints import BddEndpointResolver +from smithy_core.interceptors import Interceptor +from smithy_core.interfaces import ( + ClientProtocol, + EndpointResolver, + ProtocolConstructor, + ProtocolSettings, + URI, +) +from smithy_core.interfaces.auth import AuthSchemeResolver +from smithy_core.interfaces.retries import RetryStrategy +from smithy_core.retries import RetryStrategyOptions +from smithy_core.shapes import ShapeID +from smithy_http.aio.aiohttp import AIOHTTPClient +from smithy_http.aio.protocols import AsyncRpcV2CborClientProtocol + +from endpoint_rules_client._private.endpoints import BDD +from endpoint_rules_client._private.schemas import ENDPOINT_SERVICE + +_PROTOCOL_SETTINGS = ProtocolSettings( + namespace="example.endpoints", + service_target="EndpointService", + version="2026-11-20", + service_schema=ENDPOINT_SERVICE, +) + + +@dataclass(init=False) +class AsyncConfig: + "Configuration for AsyncEndpointService." + + auth_scheme_resolver: AuthSchemeResolver + "Determines the auth scheme for each operation." + + auth_schemes: dict[ShapeID, AsyncAuthScheme[Any, Any, Any, Any]] + "Auth schemes by auth scheme ID." + + endpoint_resolver: EndpointResolver | AsyncEndpointResolver + "Resolves the endpoint of each operation." + + endpoint_uri: str | URI | None + "The endpoint URI, read by the endpoint rules as ``SDK::Endpoint``." + + interceptors: list[Interceptor[Any, Any, Any, Any]] + "Hooks called during the execution of a request." + + protocol: ClientProtocol[Any, Any] + "Serializes requests and deserializes responses." + + retry_strategy: RetryStrategy | RetryStrategyOptions | None + "The retry strategy, or options to create one." + + transport: AsyncClientTransport[Any, Any] + "Sends requests, such as an HTTP client." + + stage: str | None + "The deployment stage." + + force_path_style: bool | None + "Forces path-style addressing." + + def __init__( + self, + *, + auth_scheme_resolver: AuthSchemeResolver | None = None, + auth_schemes: dict[ShapeID, AsyncAuthScheme[Any, Any, Any, Any]] | None = None, + endpoint_resolver: EndpointResolver | AsyncEndpointResolver | None = None, + endpoint_uri: str | URI | None = None, + interceptors: list[Interceptor[Any, Any, Any, Any]] | None = None, + protocol: ClientProtocol[Any, Any] + | ProtocolConstructor[ClientProtocol[Any, Any]] + | None = None, + retry_strategy: RetryStrategy | RetryStrategyOptions | None = None, + transport: AsyncClientTransport[Any, Any] | None = None, + stage: str | None = None, + force_path_style: bool | None = None, + ) -> None: + self.auth_scheme_resolver = auth_scheme_resolver or DefaultAuthResolver() + self.auth_schemes = auth_schemes or {} + self.endpoint_resolver = endpoint_resolver or BddEndpointResolver(BDD) + self.endpoint_uri = endpoint_uri + self.interceptors = interceptors or [] + if isinstance(protocol, type): + protocol = protocol(_PROTOCOL_SETTINGS) + self.protocol = cast( + ClientProtocol[Any, Any], protocol + ) or AsyncRpcV2CborClientProtocol(_PROTOCOL_SETTINGS) + self.retry_strategy = retry_strategy + self.transport = transport or AIOHTTPClient() + self.stage = stage + self.force_path_style = force_path_style + + +type Plugin = Callable[[AsyncConfig], None] +"A callable that customizes the client configuration." diff --git a/codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/client.py b/codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/client.py new file mode 100644 index 000000000..99267d6c1 --- /dev/null +++ b/codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/client.py @@ -0,0 +1,86 @@ +from __future__ import annotations + +from typing import Unpack, overload + +from smithy_core.client import Client +from smithy_http.plugins import user_agent_plugin + +from endpoint_rules_client import models +from endpoint_rules_client.config import Config, Plugin + + +class EndpointService(Client[Config]): + "A service whose endpoint rules read config, input, and operation values." + + _client_plugins = (user_agent_plugin,) + + @overload + def ping( + self, + request: models.PingInput | models.PingInputDict, + /, + *, + plugins: list[Plugin] | None = None, + ) -> models.PingOutput: ... + + @overload + def ping( + self, + /, + *, + plugins: list[Plugin] | None = None, + **kwargs: Unpack[models.PingInputDict], + ) -> models.PingOutput: + """ + Invokes the Ping operation. + + :param plugins: Callables that change the configuration for this call + only. + """ + + def ping( + self, /, *args: object, plugins: list[Plugin] | None = None, **kwargs: object + ) -> models.PingOutput: + return self._invoke( + self._select_input(models.PING, args, kwargs), + models.PING, + [], + plugins, + ) + + @overload + def put_thing( + self, + request: models.PutThingInput | models.PutThingInputDict, + /, + *, + plugins: list[Plugin] | None = None, + ) -> models.PutThingOutput: ... + + @overload + def put_thing( + self, + /, + *, + plugins: list[Plugin] | None = None, + **kwargs: Unpack[models.PutThingInputDict], + ) -> models.PutThingOutput: + """ + Invokes the PutThing operation. + + :param plugins: Callables that change the configuration for this call + only. + """ + + def put_thing( + self, /, *args: object, plugins: list[Plugin] | None = None, **kwargs: object + ) -> models.PutThingOutput: + return self._invoke( + self._select_input(models.PUT_THING, args, kwargs), + models.PUT_THING, + [], + plugins, + ) + + def _new_config(self) -> Config: + return Config() diff --git a/codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/config.py b/codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/config.py new file mode 100644 index 000000000..a8706e2b2 --- /dev/null +++ b/codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/config.py @@ -0,0 +1,101 @@ +from collections.abc import Callable +from dataclasses import dataclass +from typing import Any, cast + +from smithy_core.auth import DefaultAuthResolver +from smithy_core.endpoints import BddEndpointResolver +from smithy_core.interceptors import Interceptor +from smithy_core.interfaces import ( + ClientProtocol, + ClientTransport, + EndpointResolver, + ProtocolConstructor, + ProtocolSettings, + URI, +) +from smithy_core.interfaces.auth import AuthScheme, AuthSchemeResolver +from smithy_core.interfaces.retries import RetryStrategy +from smithy_core.retries import RetryStrategyOptions +from smithy_core.shapes import ShapeID +from smithy_http.protocols import RpcV2CborClientProtocol +from smithy_http.urllib3 import Urllib3HTTPClient + +from endpoint_rules_client._private.endpoints import BDD +from endpoint_rules_client._private.schemas import ENDPOINT_SERVICE + +_PROTOCOL_SETTINGS = ProtocolSettings( + namespace="example.endpoints", + service_target="EndpointService", + version="2026-11-20", + service_schema=ENDPOINT_SERVICE, +) + + +@dataclass(init=False) +class Config: + "Configuration for EndpointService." + + auth_scheme_resolver: AuthSchemeResolver + "Determines the auth scheme for each operation." + + auth_schemes: dict[ShapeID, AuthScheme[Any, Any, Any, Any]] + "Auth schemes by auth scheme ID." + + endpoint_resolver: EndpointResolver + "Resolves the endpoint of each operation." + + endpoint_uri: str | URI | None + "The endpoint URI, read by the endpoint rules as ``SDK::Endpoint``." + + interceptors: list[Interceptor[Any, Any, Any, Any]] + "Hooks called during the execution of a request." + + protocol: ClientProtocol[Any, Any] + "Serializes requests and deserializes responses." + + retry_strategy: RetryStrategy | RetryStrategyOptions | None + "The retry strategy, or options to create one." + + transport: ClientTransport[Any, Any] + "Sends requests, such as an HTTP client." + + stage: str | None + "The deployment stage." + + force_path_style: bool | None + "Forces path-style addressing." + + def __init__( + self, + *, + auth_scheme_resolver: AuthSchemeResolver | None = None, + auth_schemes: dict[ShapeID, AuthScheme[Any, Any, Any, Any]] | None = None, + endpoint_resolver: EndpointResolver | None = None, + endpoint_uri: str | URI | None = None, + interceptors: list[Interceptor[Any, Any, Any, Any]] | None = None, + protocol: ClientProtocol[Any, Any] + | ProtocolConstructor[ClientProtocol[Any, Any]] + | None = None, + retry_strategy: RetryStrategy | RetryStrategyOptions | None = None, + transport: ClientTransport[Any, Any] | None = None, + stage: str | None = None, + force_path_style: bool | None = None, + ) -> None: + self.auth_scheme_resolver = auth_scheme_resolver or DefaultAuthResolver() + self.auth_schemes = auth_schemes or {} + self.endpoint_resolver = endpoint_resolver or BddEndpointResolver(BDD) + self.endpoint_uri = endpoint_uri + self.interceptors = interceptors or [] + if isinstance(protocol, type): + protocol = protocol(_PROTOCOL_SETTINGS) + self.protocol = cast( + ClientProtocol[Any, Any], protocol + ) or RpcV2CborClientProtocol(_PROTOCOL_SETTINGS) + self.retry_strategy = retry_strategy + self.transport = transport or Urllib3HTTPClient() + self.stage = stage + self.force_path_style = force_path_style + + +type Plugin = Callable[[Config], None] +"A callable that customizes the client configuration." diff --git a/codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/models.py b/codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/models.py new file mode 100644 index 000000000..65b2b9cda --- /dev/null +++ b/codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/models.py @@ -0,0 +1,71 @@ +from smithy_core._dynamic_models import ModelRegistry +from smithy_core.exceptions import ModeledError + +from ._private import schemas + + +class ServiceError(ModeledError): + """ + Base error for all errors in the service. + + Some exceptions do not extend from this class, including synthetic, + implicit, and shared exception types. + """ + + +_MODEL_INDEX = { + "PutThingInput": "PUT_THING_INPUT", + "ThingTag": "THING_TAG", + "PingInput": "PING_INPUT", + "PingOutput": "PING_OUTPUT", + "PutThingOutput": "PUT_THING_OUTPUT", +} + +_RENAMES: dict[str, str] = {} + +_TARGET_NAMES: dict[str, str] = {} + +_OPERATIONS: dict[str, tuple[tuple[str, ...], tuple[str, ...]]] = { + "PING": ( + (), + ("smithy.api#noAuth",), + ), + "PUT_THING": ( + (), + ("smithy.api#noAuth",), + ), +} + +_MODEL_NAMES = tuple(_MODEL_INDEX) +__all__ = ("ServiceError", *_MODEL_NAMES, *_OPERATIONS) # pyright: ignore[reportUnsupportedDunderAll] + + +_registry = ModelRegistry( + schemas, + renames=_RENAMES, + index=_MODEL_INDEX, + target_names=_TARGET_NAMES, + shape_names=frozenset( + { + "PingInput", + "PingOutput", + "PutThingInput", + "PutThingOutput", + "ThingTag", + } + ), + service_error="ServiceError", +) +del schemas, ModelRegistry, ModeledError + + +def __getattr__(name: str): + if (data := _OPERATIONS.get(name)) is not None: + return globals().setdefault(name, _registry.build_operation(name, *data)) + value = _registry.build(name) + globals()[name] = value + return value + + +def __dir__() -> list[str]: + return sorted({*globals(), *__all__}) diff --git a/codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/models.pyi b/codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/models.pyi new file mode 100644 index 000000000..d8fc0c837 --- /dev/null +++ b/codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/models.pyi @@ -0,0 +1,98 @@ +from collections.abc import Sequence +from dataclasses import dataclass +from typing import Required, Self, TypedDict + +from smithy_core.deserializers import ShapeDeserializer +from smithy_core.exceptions import ModeledError +from smithy_core.response import ResponseMetadata +from smithy_core.schemas import APIOperation +from smithy_core.serializers import ShapeSerializer + +__all__ = [ + "PING", + "PUT_THING", + "PingInput", + "PingOutput", + "PutThingInput", + "PutThingOutput", + "ServiceError", + "ThingTag", +] + +class _SerdeShape: + def serialize(self, serializer: ShapeSerializer) -> None: ... + def serialize_members(self, serializer: ShapeSerializer) -> None: ... + @classmethod + def deserialize(cls, deserializer: ShapeDeserializer) -> Self: ... + +class ServiceError(ModeledError): + """ + Base error for all errors in the service. + + Some exceptions do not extend from this class, including synthetic, + implicit, and shared exception types. + """ + +@dataclass(kw_only=True) +class PutThingInput(_SerdeShape): + "Dataclass for PutThingInput structure." + + name: str | None = ... + tag: ThingTag | None = ... + plugins_: list[str] | None = ... + +class PutThingInputDict(TypedDict, total=False): + "Dictionary form of `PutThingInput`." + + name: Required[str] + tag: ThingTag | ThingTagDict | None + plugins_: Sequence[str] | None + +@dataclass(kw_only=True) +class ThingTag(_SerdeShape): + "Dataclass for ThingTag structure." + + key: str | None = ... + value: str | None = ... + +class ThingTagDict(TypedDict, total=False): + "Dictionary form of `ThingTag`." + + key: str | None + value: str | None + +@dataclass(kw_only=True) +class PingInput(_SerdeShape): + "Dataclass for PingInput structure." + +class PingInputDict(TypedDict, total=False): + "Dictionary form of `PingInput`." + +@dataclass(kw_only=True) +class PingOutput(_SerdeShape): + "Dataclass for PingOutput structure." + + response_metadata: ResponseMetadata = ... + """ + Metadata about the response that produced this output. + + Use this to recover the request identifiers a service's support team + needs in order to investigate a call. Members of the metadata are + individually optional. + """ + +@dataclass(kw_only=True) +class PutThingOutput(_SerdeShape): + "Dataclass for PutThingOutput structure." + + response_metadata: ResponseMetadata = ... + """ + Metadata about the response that produced this output. + + Use this to recover the request identifiers a service's support team + needs in order to investigate a call. Members of the metadata are + individually optional. + """ + +PING: APIOperation[PingInput, PingOutput] +PUT_THING: APIOperation[PutThingInput, PutThingOutput] diff --git a/codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/py.typed b/codegen-output-py/endpoint-rules-client/src/endpoint_rules_client/py.typed new file mode 100644 index 000000000..e69de29bb diff --git a/codegen-output-py/endpoint-rules-client/tests/test_endpoints.py b/codegen-output-py/endpoint-rules-client/tests/test_endpoints.py new file mode 100644 index 000000000..ed05beb20 --- /dev/null +++ b/codegen-output-py/endpoint-rules-client/tests/test_endpoints.py @@ -0,0 +1,191 @@ +from collections.abc import Awaitable, Callable, Mapping +from typing import Any, Concatenate + +from endpoint_rules_client.aio.client import AsyncEndpointService +from endpoint_rules_client.aio.config import AsyncConfig +from pytest import mark, param +from smithy_core.aio.utils import close_async +from smithy_core.endpoints import BddEndpointResolver +from smithy_core.interceptors import Interceptor +from smithy_core.retries import SimpleRetryStrategy +from smithy_test import check_rules_case +from smithy_test.aio import check_client_case_async + +# Endpoint tests from the endpointTests trait of example.endpoints#EndpointService. + +pytestmark = mark.asyncio + + +async def _config(**fields: Any) -> AsyncConfig: + return AsyncConfig(**fields, retry_strategy=SimpleRetryStrategy(max_attempts=1)) + + +# Every rules test shares one resolver, so its caches see changing parameters. +_resolver: BddEndpointResolver | None = None + + +async def _endpoint_resolver() -> BddEndpointResolver: + global _resolver + if _resolver is None: + config = await _config() + # Only the resolver is used, so the transport is closed right away. + await close_async(config.transport) + # The rules checks are sync, so they need the default sync resolver. + resolver = config.endpoint_resolver + if not isinstance(resolver, BddEndpointResolver): + raise TypeError( + "The default endpoint resolver is not a BddEndpointResolver" + ) + _resolver = resolver + return _resolver + + +async def _client( + config: Mapping[str, Any], capture: Interceptor[Any, Any, Any, Any] +) -> AsyncEndpointService: + return AsyncEndpointService(config=await _config(**config, interceptors=[capture])) + + +RULES_CASES = [ + param( + {"Stage": "beta", "Kind": "ping"}, + { + "endpoint": { + "url": "https://beta.example.com", + "properties": {"kind": "ping"}, + } + }, + id="Stage from config", + ), + param( + {"Stage": "beta", "Name": "thing", "Kind": "put"}, + { + "endpoint": { + "url": "https://thing.beta.example.com", + "headers": {"x-kind": ["put"]}, + } + }, + id="Name from input", + ), + param( + {"Stage": "beta", "Name": "not a label", "Kind": "put"}, + { + "endpoint": { + "url": "https://beta.example.com", + "properties": {"kind": "put"}, + } + }, + id="Invalid name falls back to the stage", + ), + param( + {"ForcePathStyle": True}, + {"endpoint": {"url": "https://path.example.com"}}, + id="Path style from config", + ), + param( + {"Endpoint": "https://custom.example.com", "Stage": "beta"}, + {"endpoint": {"url": "https://custom.example.com"}}, + id="Custom endpoint", + ), + param( + {"Region": "us-west-2"}, + {"endpoint": {"url": "https://us-west-2.example.com"}}, + id="Region from the built-in", + ), + param( + {}, + {"error": "No stage"}, + id="Missing stage", + ), + param( + {"Kind": "put"}, + {"error": "No stage"}, + id="Missing stage (2)", + ), +] + + +@mark.parametrize(("params", "expect"), RULES_CASES) +async def test_endpoint_rules(params: dict[str, Any], expect: dict[str, Any]) -> None: + check_rules_case(await _endpoint_resolver(), params, expect) + + +CLIENT_CASES = [ + param( + {"stage": "beta"}, + AsyncEndpointService.ping, + {}, + { + "endpoint": { + "url": "https://beta.example.com", + "properties": {"kind": "ping"}, + } + }, + id="Stage from config", + ), + param( + {"stage": "beta"}, + AsyncEndpointService.put_thing, + {"name": "thing", "tag": {"key": "k", "value": "v"}, "plugins_": ["p"]}, + { + "endpoint": { + "url": "https://thing.beta.example.com", + "headers": {"x-kind": ["put"]}, + } + }, + id="Name from input", + ), + param( + {"stage": "beta"}, + AsyncEndpointService.put_thing, + {"name": "not a label"}, + { + "endpoint": { + "url": "https://beta.example.com", + "properties": {"kind": "put"}, + } + }, + id="Invalid name falls back to the stage", + ), + param( + {"force_path_style": True}, + AsyncEndpointService.ping, + {}, + {"endpoint": {"url": "https://path.example.com"}}, + id="Path style from config", + ), + param( + {"endpoint_uri": "https://custom.example.com", "stage": "beta"}, + AsyncEndpointService.ping, + {}, + {"endpoint": {"url": "https://custom.example.com"}}, + id="Custom endpoint", + ), + param( + {}, + AsyncEndpointService.ping, + {}, + {"endpoint": {"url": "https://us-west-2.example.com"}}, + id="Region from the built-in", + marks=mark.skip(reason="No config field sets the built-in AWS::Region"), + ), + param( + {}, + AsyncEndpointService.ping, + {}, + {"error": "No stage"}, + id="Missing stage", + ), +] + + +@mark.parametrize(("config", "operation", "input", "expect"), CLIENT_CASES) +async def test_endpoint_client( + config: dict[str, Any], + operation: Callable[Concatenate[AsyncEndpointService, ...], Awaitable[Any]], + input: dict[str, Any], + expect: dict[str, Any], +) -> None: + await check_client_case_async( + lambda capture: _client(config, capture), operation, input, expect + ) diff --git a/designs/codegen/client.md b/designs/codegen/client.md index 669c46a34..b928cd108 100644 --- a/designs/codegen/client.md +++ b/designs/codegen/client.md @@ -5,7 +5,7 @@ This document describes how the Python generator produces client packages. It defines client settings, operation discovery, I/O normalization, client symbols, the client plan, operation and schema emission, protocol selection, -endpoint rules, and the generated client and config modules. +endpoint rules, endpoint tests, and the generated client and config modules. ## Goals @@ -229,6 +229,34 @@ Schemas retain `smithy.rules#contextParam`, `smithy.rules#staticContextParams`, and `smithy.rules#operationContextParams`, which the runtime parameter plan reads to bind input members and operation values. +## Endpoint Tests + +A service with an endpointBdd trait and `smithy.rules#endpointTests` cases gets +`tests/test_endpoints.py`. Its layout follows the Java generator's: + +* Every case becomes a rules test. `smithy_test.check_rules_case` resolves the + case's `params` with the default endpoint resolver of the async config. All + rules tests share one resolver, so its caches see changing parameters. +* Every operation input of a case becomes a client test. + `smithy_test.aio.check_client_case_async` calls the operation through the + async client and checks the endpoint it resolves and the request it sends. +* A client test's config sets the client context fields from `clientParams`. + `SDK::Endpoint` sets `endpoint_uri`, and a built-in that is also a client + context parameter sets its field. +* `operationParams` become the call's keyword arguments, keyed by member field + name. Nested structures and unions are written in their dictionary forms. +* Cases keep the trait's `params` and `expect` objects. Test IDs come from the + case documentation, numbered when one repeats. + +A client test the client can't express is generated as skipped, with the +reasons. These are a built-in with no config field set to a value other than its +default, a client parameter that is not a client context parameter, and a blob, +timestamp, big decimal, or document value. An input that names an operation the +service lacks, or a member its input lacks, fails generation. + +The module marks its tests with `pytest.mark.asyncio`. The package's `test` +dependency group adds `pytest`, `pytest-asyncio`, and `smithy-test`. + ## Clients and Configuration Service classes are thin subclasses of `Client[Config]` and @@ -245,6 +273,7 @@ Generated packages use this layout: /models.py and models.pyi /_private/schemas.py and partitions /_private/endpoints.py +tests/test_endpoints.py, for services with endpoint tests ``` Package initialization lazily exports both clients and configs. Each config @@ -303,7 +332,13 @@ decoded CBOR payload, response models, and error types. An endpoint test resolves a host from a client context field, an input context parameter, and a static context parameter. -Lowering tests port the Java generator's tests. +Lowering tests port the Java generator's tests. The `endpoint-rules-client` +snapshot is generated from a fixture whose endpoint rules read client context +fields, `SDK::Endpoint`, an input context parameter, and static context +parameters. `models/endpoint-rules.smithy` is its source, and +`models/endpoint-rules.json` is that model assembled by Smithy with its ruleset +compiled by `CompileBdd`. The snapshot tests run the snapshot's generated +endpoint tests. Client snapshots sit alongside the types snapshots and cover the provider-neutral RPCv2 CBOR and RPCv2 JSON projections. Checks cover deterministic diff --git a/packages/smithy-python/.changes/next-release/smithy-python-feature-01b2f761fddb4174ae59f614a52ddf95.json b/packages/smithy-python/.changes/next-release/smithy-python-feature-01b2f761fddb4174ae59f614a52ddf95.json index ba9c82657..8c2d9fa53 100644 --- a/packages/smithy-python/.changes/next-release/smithy-python-feature-01b2f761fddb4174ae59f614a52ddf95.json +++ b/packages/smithy-python/.changes/next-release/smithy-python-feature-01b2f761fddb4174ae59f614a52ddf95.json @@ -1,4 +1,4 @@ { "type": "feature", - "description": "Generate clients that resolve endpoints from the service's endpointBdd trait. Client context parameters become config fields, and a service with no endpoint rules requires `endpoint_uri`." + "description": "Generate clients that resolve endpoints from the service's endpointBdd trait. Client context parameters become config fields, and a service with no endpoint rules requires `endpoint_uri`. A service's endpointTests cases become `tests/test_endpoints.py`." } \ No newline at end of file diff --git a/packages/smithy-python/src/smithy_python/_client_emitter.py b/packages/smithy-python/src/smithy_python/_client_emitter.py index 36904252d..01e1320ca 100644 --- a/packages/smithy-python/src/smithy_python/_client_emitter.py +++ b/packages/smithy-python/src/smithy_python/_client_emitter.py @@ -7,7 +7,7 @@ from dataclasses import dataclass from typing import TYPE_CHECKING, Final -from . import _endpoints, _package +from . import _endpoint_tests, _endpoints, _package from . import dependencies as _dependencies from . import exceptions as _exceptions from . import model as _model @@ -96,6 +96,13 @@ def write_client( f"{module}config", service, ) + _endpoint_tests.write_endpoint_tests( + context, + plan, + endpoints, + TypeReference(aio.client, f"{package}.aio.client"), + TypeReference(aio.config, f"{package}.aio.config"), + ) aio_init = context.files.python_module( f"src/{directory}/aio/__init__.py", f"{package}.aio" ) diff --git a/packages/smithy-python/src/smithy_python/_endpoint_tests.py b/packages/smithy-python/src/smithy_python/_endpoint_tests.py new file mode 100644 index 000000000..79bce3e32 --- /dev/null +++ b/packages/smithy-python/src/smithy_python/_endpoint_tests.py @@ -0,0 +1,500 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 +"""Emission of ``tests/test_endpoints.py`` from ``smithy.rules#endpointTests``. + +Every case becomes a rules test, which resolves the case's parameter values with the +client's own endpoint resolver. Every operation input of a case also becomes a client +test, which calls the operation through the async client with config from the +input's built-in and client parameters and checks the endpoint the client resolves. +The input's operation parameters become the call's keyword arguments, with nested +values in their dictionary forms. A client test the client can't express is +generated as skipped, with the reason. Cases keep the trait's ``params`` and +``expect`` objects as they are. +""" + +from __future__ import annotations + +from collections.abc import Mapping +from typing import TYPE_CHECKING, Final + +from . import _endpoints +from . import dependencies as _dependencies +from . import exceptions as _exceptions +from . import model as _model +from .symbols import TypeReference + +if TYPE_CHECKING: + from .clients import ClientPlan, OperationPlan + from .generation import ClientSettings, GenerationContext + from .writer import PythonWriter + + +def write_endpoint_tests( + context: GenerationContext[ClientSettings], + plan: ClientPlan, + endpoints: _endpoints.EndpointPlan, + client: TypeReference, + config: TypeReference, +) -> None: + """Register ``tests/test_endpoints.py`` when the service has endpoint tests. + + :param client: The async client class. + :param config: The async config class. + :raises CodegenError: If a case names an operation the service doesn't + contain, expects neither an endpoint nor an error, or gives an operation + an input member it doesn't have. + """ + service = plan.selection.service + assert service is not None # noqa: S101 - ClientPlan requires a service + if endpoints.trait is _endpoints.MANUAL_ENDPOINT_BDD: + return + trait = service.get_trait(_ENDPOINT_TESTS) + cases = ( + _array(trait.get("testCases", ()), "testCases") + if isinstance(trait, Mapping) + else () + ) + if not cases: + return + # pytestmark names pytest-asyncio's marker, which nothing imports. + context.dependencies.add(_dependencies.PYTEST_ASYNCIO) + _Writer( + context.files.python_module("tests/test_endpoints.py", "tests.test_endpoints"), + plan, + endpoints, + client, + config, + ).write(service, tuple(_object(case, "test case") for case in cases)) + + +def literal(node: _model.Node) -> str: + """Render a JSON node as a one-line Python literal of lists and dicts.""" + if node is None: + return "None" + if isinstance(node, bool): + return "True" if node else "False" + if isinstance(node, int | float): + return str(node) + if isinstance(node, str): + return _endpoints.literal(node) + if isinstance(node, tuple): + return "[" + ", ".join(map(literal, node)) + "]" + return ( + "{" + + ", ".join(f"{_endpoints.literal(k)}: {literal(v)}" for k, v in node.items()) + + "}" + ) + + +_ENDPOINT_TESTS: Final = _model.ShapeId("smithy.rules", "endpointTests") +_PYTEST_MARK: Final = TypeReference( + "mark", "pytest", dependencies=(_dependencies.PYTEST,) +) +_PYTEST_PARAM: Final = TypeReference( + "param", "pytest", dependencies=(_dependencies.PYTEST,) +) +_ANY: Final = TypeReference("Any", "typing") +_MAPPING: Final = TypeReference("Mapping", "collections.abc") +_AWAITABLE: Final = TypeReference("Awaitable", "collections.abc") +_CALLABLE: Final = TypeReference("Callable", "collections.abc") +_CONCATENATE: Final = TypeReference("Concatenate", "typing") +_CORE: Final = (_dependencies.SMITHY_CORE,) +_CLOSE_ASYNC: Final = TypeReference( + "close_async", "smithy_core.aio.utils", dependencies=_CORE +) +_BDD_RESOLVER: Final = TypeReference( + "BddEndpointResolver", "smithy_core.endpoints", dependencies=_CORE +) +_INTERCEPTOR: Final = TypeReference( + "Interceptor", "smithy_core.interceptors", dependencies=_CORE +) +_RETRY: Final = TypeReference( + "SimpleRetryStrategy", "smithy_core.retries", dependencies=_CORE +) +_TEST: Final = (_dependencies.SMITHY_TEST,) +_CHECK_RULES: Final = TypeReference( + "check_rules_case", "smithy_test", dependencies=_TEST +) +_CHECK_CLIENT: Final = TypeReference( + "check_client_case_async", "smithy_test.aio", dependencies=_TEST +) +# Member types whose values a test can't write as JSON literals. +_UNWRITABLE: Final = frozenset( + { + _model.ShapeType.BLOB, + _model.ShapeType.TIMESTAMP, + _model.ShapeType.BIG_DECIMAL, + _model.ShapeType.DOCUMENT, + } +) + + +class _Writer: + def __init__( + self, + writer: PythonWriter, + plan: ClientPlan, + endpoints: _endpoints.EndpointPlan, + client: TypeReference, + config: TypeReference, + ) -> None: + self._writer = writer + self._plan = plan + self._client = client + self._config = config + self._fields = { + field.parameter: field.attribute + for field in endpoints.client_context_fields + } + parameters = _object(endpoints.trait.get("parameters", {}), "parameters") + self._builtins: dict[str, Mapping[str, _model.Node]] = {} + for name, value in parameters.items(): + definition = _object(value, f"parameter {name}") + builtin = definition.get("builtIn") + if isinstance(builtin, str): + self._builtins[builtin] = {**definition, "name": name} + + def write( + self, service: _model.ServiceShape, cases: tuple[Mapping[str, _model.Node], ...] + ) -> None: + writer = self._writer + writer.line(f"# Endpoint tests from the endpointTests trait of {service.id}.") + writer.line() + writer.line("pytestmark = ", _PYTEST_MARK, ".asyncio") + self._write_factories() + self._write_rules_tests(cases) + self._write_client_tests(cases) + + def _write_factories(self) -> None: + w = self._writer + any_ = _ANY + w.line() + w.line() + w.line("async def _config(**fields: ", any_, ") -> ", self._config, ":") + with w.indent(): + w.line( + "return ", + self._config, + "(**fields, retry_strategy=", + _RETRY, + "(max_attempts=1))", + ) + w.line() + w.line() + w.line( + "# Every rules test shares one resolver, so its caches see changing" + " parameters." + ) + w.line("_resolver: ", _BDD_RESOLVER, " | None = None") + w.line() + w.line() + w.line("async def _endpoint_resolver() -> ", _BDD_RESOLVER, ":") + with w.indent(): + w.line("global _resolver") + w.line("if _resolver is None:") + with w.indent(): + w.line("config = await _config()") + w.line( + "# Only the resolver is used, so the transport is closed right" + " away." + ) + w.line("await ", _CLOSE_ASYNC, "(config.transport)") + w.line( + "# The rules checks are sync, so they need the default sync" + " resolver." + ) + w.line("resolver = config.endpoint_resolver") + w.line("if not isinstance(resolver, ", _BDD_RESOLVER, "):") + with w.indent(): + w.line( + 'raise TypeError("The default endpoint resolver is not a ' + 'BddEndpointResolver")' + ) + w.line("_resolver = resolver") + w.line("return _resolver") + w.line() + w.line() + w.line("async def _client(") + with w.indent(): + w.line( + "config: ", + _MAPPING, + "[str, ", + any_, + "], capture: ", + _INTERCEPTOR, + "[", + any_, + ", ", + any_, + ", ", + any_, + ", ", + any_, + "]", + ) + w.line(") -> ", self._client, ":") + with w.indent(): + w.line( + "return ", + self._client, + "(config=await _config(**config, interceptors=[capture]))", + ) + + def _write_rules_tests(self, cases: tuple[Mapping[str, _model.Node], ...]) -> None: + w = self._writer + ids = _CaseIds() + w.line() + w.line() + w.line("RULES_CASES = [") + with w.indent(): + for case in cases: + w.line(_PYTEST_PARAM, "(") + with w.indent(): + w.line(literal(_object(case.get("params", {}), "params")), ",") + w.line(_expectation(case), ",") + w.line("id=", _endpoints.literal(ids.next(case)), ",") + w.line("),") + w.line("]") + w.line() + w.line() + w.line("@", _PYTEST_MARK, '.parametrize(("params", "expect"), RULES_CASES)') + w.line("async def test_endpoint_rules(") + with w.indent(): + w.line("params: dict[str, ", _ANY, "], expect: dict[str, ", _ANY, "]") + w.line(") -> None:") + with w.indent(): + w.line(_CHECK_RULES, "(await _endpoint_resolver(), params, expect)") + + def _write_client_tests(self, cases: tuple[Mapping[str, _model.Node], ...]) -> None: + inputs = [ + (case, _object(item, "operation input")) + for case in cases + for item in _array(case.get("operationInputs", ()), "operationInputs") + ] + if not inputs: + return + w = self._writer + ids = _CaseIds() + w.line() + w.line() + w.line("CLIENT_CASES = [") + with w.indent(): + for case, operation_input in inputs: + self._write_client_case(case, operation_input, ids.next(case)) + w.line("]") + w.line() + w.line() + w.line( + "@", + _PYTEST_MARK, + '.parametrize(("config", "operation", "input", "expect"), CLIENT_CASES)', + ) + w.line("async def test_endpoint_client(") + with w.indent(): + w.line("config: dict[str, ", _ANY, "],") + w.line( + "operation: ", + _CALLABLE, + "[", + _CONCATENATE, + "[", + self._client, + ", ...], ", + _AWAITABLE, + "[", + _ANY, + "]],", + ) + w.line("input: dict[str, ", _ANY, "],") + w.line("expect: dict[str, ", _ANY, "],") + w.line(") -> None:") + with w.indent(): + w.line("await ", _CHECK_CLIENT, "(") + with w.indent(): + w.line( + "lambda capture: _client(config, capture), operation, input, expect" + ) + w.line(")") + + def _write_client_case( + self, + case: Mapping[str, _model.Node], + operation_input: Mapping[str, _model.Node], + case_id: str, + ) -> None: + w = self._writer + name = _string(operation_input.get("operationName"), "operationName") + operation = self._operation(name) + skips: list[str] = [] + entries = self._config_entries(operation_input, skips) + params = _object(operation_input.get("operationParams", {}), "operationParams") + arguments = self._arguments( + self._plan.model.get_shape(operation.operation.input), params, skips + ) + w.line(_PYTEST_PARAM, "(") + with w.indent(): + w.line("{", ", ".join(entries), "},") + w.line(self._client, ".", operation.method_name, ",") + w.line("{", ", ".join(arguments), "},") + w.line(_expectation(case), ",") + w.line("id=", _endpoints.literal(case_id), ",") + if skips: + reason = _endpoints.literal("; ".join(dict.fromkeys(skips))) + w.line("marks=", _PYTEST_MARK, ".skip(reason=", reason, "),") + w.line("),") + + # The config entries an operation input's built-in and client parameters set. A + # parameter the client has no config field for adds the reason the case is + # skipped. + def _config_entries( + self, operation_input: Mapping[str, _model.Node], skips: list[str] + ) -> list[str]: + entries: list[str] = [] + builtins = _object(operation_input.get("builtInParams", {}), "builtInParams") + for builtin, value in builtins.items(): + parameter = self._builtins.get(builtin) + # A built-in that is also a client context parameter reads its field. + field = ( + None if parameter is None else self._fields.get(str(parameter["name"])) + ) + if field is None and builtin == "SDK::Endpoint": + field = "endpoint_uri" + if field is not None: + entries.append(f"{_endpoints.literal(field)}: {literal(value)}") + elif parameter is not None and parameter.get("default") != value: + skips.append(f"No config field sets the built-in {builtin}") + clients = _object(operation_input.get("clientParams", {}), "clientParams") + for name, value in clients.items(): + field = self._fields.get(name) + if field is None: + skips.append(f"{name} is not a client context parameter") + else: + entries.append(f"{_endpoints.literal(field)}: {literal(value)}") + return entries + + def _arguments( + self, + shape: _model.Shape, + params: Mapping[str, _model.Node], + skips: list[str], + ) -> list[str]: + return [ + f"{_endpoints.literal(field)}: {value}" + for field, value in self._members(shape, params, skips) + ] + + # A structure or union value in its dictionary form: (field name, literal). + def _members( + self, + shape: _model.Shape, + values: Mapping[str, _model.Node], + skips: list[str], + ) -> list[tuple[str, str]]: + members: list[tuple[str, str]] = [] + for name, value in values.items(): + member = shape.members.get(name) + if member is None: + raise _exceptions.CodegenError( + f"Endpoint test input for {shape.id} sets {name}, which it " + "doesn't have" + ) + members.append( + ( + self._plan.symbols.member_name(member.id), + self._value(self._plan.model.get_target(member), value, skips), + ) + ) + return members + + def _value(self, shape: _model.Shape, value: _model.Node, skips: list[str]) -> str: + if value is None: + return "None" + if shape.type in _UNWRITABLE: + skips.append(f"Endpoint tests can't set {shape.type} values") + return literal(value) + if isinstance(shape, _model.ListShape): + target = self._plan.model.get_target(shape.member) + items = _array(value, f"{shape.id} value") + return "[" + ", ".join(self._value(target, v, skips) for v in items) + "]" + if isinstance(shape, _model.MapShape): + target = self._plan.model.get_target(shape.value) + entries = _object(value, f"{shape.id} value") + return ( + "{" + + ", ".join( + f"{_endpoints.literal(k)}: {self._value(target, v, skips)}" + for k, v in entries.items() + ) + + "}" + ) + if shape.type in (_model.ShapeType.STRUCTURE, _model.ShapeType.UNION): + members = self._members(shape, _object(value, f"{shape.id} value"), skips) + return ( + "{" + + ", ".join(f"{_endpoints.literal(k)}: {v}" for k, v in members) + + "}" + ) + return literal(value) + + def _operation(self, name: str) -> OperationPlan: + for operation in self._plan.operations: + if operation.operation.id.name == name: + return operation + service = self._plan.selection.service + assert service is not None # noqa: S101 - ClientPlan requires a service + raise _exceptions.CodegenError( + f"Endpoint test operation {name} is not in service {service.id}" + ) + + +# The case's expect object as the trait models it. +def _expectation(case: Mapping[str, _model.Node]) -> str: + expect = _object(case.get("expect"), "expect") + if "error" in expect: + return literal({"error": expect["error"]}) + endpoint = expect.get("endpoint") + if not isinstance(endpoint, Mapping): + raise _exceptions.CodegenError( + "An endpoint test case expects neither an endpoint nor an error" + ) + expected: dict[str, _model.Node] = {"url": endpoint.get("url")} + for key in ("headers", "properties"): + if endpoint.get(key): + expected[key] = endpoint[key] + return literal({"endpoint": expected}) + + +# Test ids from case documentation, numbered when a description repeats. +class _CaseIds: + def __init__(self) -> None: + self._used: set[str] = set() + + def next(self, case: Mapping[str, _model.Node]) -> str: + documentation = case.get("documentation") + base = documentation if isinstance(documentation, str) else "undocumented" + case_id = base + n = 2 + while case_id in self._used: + case_id = f"{base} ({n})" + n += 1 + self._used.add(case_id) + return case_id + + +def _object(node: _model.Node, what: str) -> Mapping[str, _model.Node]: + if not isinstance(node, Mapping): + raise _exceptions.CodegenError(f"Invalid endpointTests trait: {what}") + return node + + +def _array(node: _model.Node, what: str) -> tuple[_model.Node, ...]: + if not isinstance(node, tuple): + raise _exceptions.CodegenError(f"Invalid endpointTests trait: {what}") + return node + + +def _string(node: _model.Node, what: str) -> str: + if not isinstance(node, str): + raise _exceptions.CodegenError(f"Invalid endpointTests trait: {what}") + return node diff --git a/packages/smithy-python/src/smithy_python/dependencies.py b/packages/smithy-python/src/smithy_python/dependencies.py index 1f05bf0af..57be9100d 100644 --- a/packages/smithy-python/src/smithy_python/dependencies.py +++ b/packages/smithy-python/src/smithy_python/dependencies.py @@ -12,8 +12,11 @@ __all__ = [ "HATCHLING", + "PYTEST", + "PYTEST_ASYNCIO", "SMITHY_CORE", "SMITHY_HTTP", + "SMITHY_TEST", "Dependency", "DependencyGroup", "DependencySet", @@ -119,6 +122,27 @@ def for_group(self, group: DependencyGroup) -> tuple[Dependency, ...]: ) """Compatible smithy-http runtime for generated HTTP clients.""" +SMITHY_TEST = Dependency( + package="smithy-test", + specifier="~=0.5.0", + group="test", +) +"""Endpoint test checks for generated client tests.""" + +PYTEST = Dependency( + package="pytest", + specifier=">=9.0.3,<10.0.0", + group="test", +) +"""Test runner for generated client tests.""" + +PYTEST_ASYNCIO = Dependency( + package="pytest-asyncio", + specifier=">=1.3.0,<1.4.0", + group="test", +) +"""Async test support for generated client tests.""" + HATCHLING = Dependency( package="hatchling", specifier="", diff --git a/packages/smithy-python/tests/unit/test_client_generation.py b/packages/smithy-python/tests/unit/test_client_generation.py index 7e5d2a001..32bc70285 100644 --- a/packages/smithy-python/tests/unit/test_client_generation.py +++ b/packages/smithy-python/tests/unit/test_client_generation.py @@ -485,3 +485,99 @@ def test_a_service_without_rules_requires_an_endpoint_uri( with pytest.raises(EndpointResolutionError, match="must configure an endpoint"): client.ping() assert not transport.requests + + +def _add_endpoint_tests(shapes: dict[str, Any], *inputs: dict[str, Any]) -> None: + _add_endpoint_rules(shapes) + traits = shapes["example#Greeter"]["traits"] + traits["smithy.rules#endpointBdd"]["parameters"]["Region"] = { + "type": "string", + "builtIn": "AWS::Region", + "default": "us-east-1", + "required": True, + } + traits["smithy.rules#endpointTests"] = { + "version": "1.0", + "testCases": [ + { + "documentation": "A case", + "params": {"Stage": "beta"}, + "expect": {"endpoint": {"url": "https://beta.example.com"}}, + "operationInputs": list(inputs), + } + ], + } + + +def _endpoint_tests(tmp_path: Path, shapes: dict[str, Any]) -> str: + _generate(tmp_path, "greeter_endpoint_tests", shapes) + return (tmp_path / "tests/test_endpoints.py").read_text() + + +def test_endpoint_tests_set_config_and_keyword_arguments(tmp_path: Path) -> None: + shapes = _shapes() + _add_endpoint_tests( + shapes, + { + "operationName": "Greet", + "builtInParams": {"AWS::Region": "us-east-1"}, + "clientParams": {"Stage": "beta"}, + "operationParams": {"name": "ana", "friends": [{"name": "bo"}]}, + }, + ) + tests = _endpoint_tests(tmp_path, shapes) + assert ' {"stage": "beta"},\n' in tests + assert "AsyncGreeter.greet,\n" in tests + assert '{"name": "ana", "friends": [{"name": "bo"}]},' in tests + # A built-in at its default needs no config field. + assert "mark.skip" not in tests + project = (tmp_path / "pyproject.toml").read_text() + assert '"smithy-test~=0.5.0",' in project + assert '"pytest-asyncio>=1.3.0,<1.4.0",' in project + + +def test_endpoint_tests_skip_inputs_the_client_cannot_express(tmp_path: Path) -> None: + shapes = _shapes() + shapes["example#GreetInput"]["members"]["photo"] = {"target": "smithy.api#Blob"} + _add_endpoint_tests( + shapes, + { + "operationName": "Greet", + "builtInParams": {"AWS::Region": "us-west-2"}, + "clientParams": {"Other": "x"}, + "operationParams": {"name": "ana", "photo": "abc"}, + }, + ) + tests = _endpoint_tests(tmp_path, shapes) + assert ( + 'marks=mark.skip(reason="No config field sets the built-in AWS::Region; ' + "Other is not a client context parameter; " + "Endpoint tests can't set blob values\")," + ) in tests + + +@pytest.mark.parametrize( + ("operation_input", "message"), + [ + ({"operationName": "Missing"}, "operation Missing is not in service"), + ( + {"operationName": "Greet", "operationParams": {"nope": 1}}, + "sets nope, which it doesn't have", + ), + ], +) +def test_endpoint_tests_reject_unknown_operations_and_members( + tmp_path: Path, operation_input: dict[str, Any], message: str +) -> None: + shapes = _shapes() + _add_endpoint_tests(shapes, operation_input) + with pytest.raises(CodegenError, match=message): + _generate(tmp_path, "greeter_bad_endpoint_tests", shapes) + + +def test_services_without_endpoint_tests_get_no_test_module(tmp_path: Path) -> None: + shapes = _shapes() + _add_endpoint_rules(shapes) + _generate(tmp_path, "greeter_no_endpoint_tests", shapes) + assert not (tmp_path / "tests").exists() + assert "[dependency-groups]" not in (tmp_path / "pyproject.toml").read_text() diff --git a/packages/smithy-python/tests/unit/test_dependencies.py b/packages/smithy-python/tests/unit/test_dependencies.py index 3631fec33..15dc0b3e2 100644 --- a/packages/smithy-python/tests/unit/test_dependencies.py +++ b/packages/smithy-python/tests/unit/test_dependencies.py @@ -4,8 +4,11 @@ import pytest from smithy_python.dependencies import ( HATCHLING, + PYTEST, + PYTEST_ASYNCIO, SMITHY_CORE, SMITHY_HTTP, + SMITHY_TEST, Dependency, DependencySet, ) @@ -70,3 +73,6 @@ def test_runtime_dependency_catalog() -> None: assert SMITHY_CORE == Dependency("smithy-core", "~=0.13.0", "runtime") assert SMITHY_HTTP == Dependency("smithy-http", "~=0.10.0", "runtime") assert HATCHLING == Dependency("hatchling", "", "build") + assert SMITHY_TEST == Dependency("smithy-test", "~=0.5.0", "test") + assert PYTEST == Dependency("pytest", ">=9.0.3,<10.0.0", "test") + assert PYTEST_ASYNCIO == Dependency("pytest-asyncio", ">=1.3.0,<1.4.0", "test") diff --git a/scripts/api-snapshot/api.json b/scripts/api-snapshot/api.json index 98ce3b812..1b89da49d 100644 --- a/scripts/api-snapshot/api.json +++ b/scripts/api-snapshot/api.json @@ -849,8 +849,11 @@ "Dependency": "class", "DependencySet": "class", "HATCHLING": "Dependency", + "PYTEST": "Dependency", + "PYTEST_ASYNCIO": "Dependency", "SMITHY_CORE": "Dependency", - "SMITHY_HTTP": "Dependency" + "SMITHY_HTTP": "Dependency", + "SMITHY_TEST": "Dependency" }, "smithy_python.environment": { "PluginEnvironment": "class" diff --git a/scripts/codegen-output-py/client-projections.json b/scripts/codegen-output-py/client-projections.json index 9a8941d49..620057790 100644 --- a/scripts/codegen-output-py/client-projections.json +++ b/scripts/codegen-output-py/client-projections.json @@ -1,4 +1,11 @@ { + "endpoint-rules-client": { + "description": "Python client for the endpoint rules fixture", + "model": "models/endpoint-rules.json", + "package": "endpoint_rules_client", + "service": "example.endpoints#EndpointService", + "version": "0.0.1" + }, "rpcv2-cbor-client": { "description": "Python client for the rpcv2-cbor projection", "model": "models/rpcv2-cbor.json", diff --git a/scripts/codegen-output-py/models/endpoint-rules.json b/scripts/codegen-output-py/models/endpoint-rules.json new file mode 100644 index 000000000..bd33c5612 --- /dev/null +++ b/scripts/codegen-output-py/models/endpoint-rules.json @@ -0,0 +1,601 @@ +{ + "smithy": "2.0", + "shapes": { + "example.endpoints#EndpointService": { + "type": "service", + "version": "2026-11-20", + "operations": [ + { + "target": "example.endpoints#Ping" + }, + { + "target": "example.endpoints#PutThing" + } + ], + "traits": { + "smithy.api#documentation": "A service whose endpoint rules read config, input, and operation values.", + "smithy.protocols#rpcv2Cbor": {}, + "smithy.rules#clientContextParams": { + "Stage": { + "type": "string", + "documentation": "The deployment stage." + }, + "ForcePathStyle": { + "type": "boolean", + "documentation": "Forces path-style addressing." + } + }, + "smithy.rules#endpointBdd": { + "version": "1.1", + "parameters": { + "Endpoint": { + "builtIn": "SDK::Endpoint", + "required": false, + "documentation": "A custom endpoint.", + "type": "string" + }, + "Region": { + "builtIn": "AWS::Region", + "required": false, + "documentation": "The region.", + "type": "string" + }, + "Stage": { + "required": false, + "documentation": "The deployment stage.", + "type": "string" + }, + "ForcePathStyle": { + "required": true, + "default": false, + "documentation": "Forces path-style addressing.", + "type": "boolean" + }, + "Name": { + "required": false, + "documentation": "The thing name.", + "type": "string" + }, + "Kind": { + "required": false, + "documentation": "The operation kind.", + "type": "string" + } + }, + "conditions": [ + { + "fn": "isSet", + "argv": [ + { + "ref": "Endpoint" + } + ] + }, + { + "fn": "isSet", + "argv": [ + { + "ref": "Region" + } + ] + }, + { + "fn": "booleanEquals", + "argv": [ + { + "ref": "ForcePathStyle" + }, + true + ] + }, + { + "fn": "isSet", + "argv": [ + { + "ref": "Kind" + } + ] + }, + { + "fn": "isSet", + "argv": [ + { + "ref": "Stage" + } + ] + }, + { + "fn": "isSet", + "argv": [ + { + "ref": "Name" + } + ] + }, + { + "fn": "isValidHostLabel", + "argv": [ + { + "ref": "Name" + }, + false + ] + } + ], + "results": [ + { + "conditions": [], + "endpoint": { + "url": { + "ref": "Endpoint" + }, + "properties": {}, + "headers": {} + }, + "type": "endpoint" + }, + { + "conditions": [], + "endpoint": { + "url": "https://{Region}.example.com", + "properties": {}, + "headers": {} + }, + "type": "endpoint" + }, + { + "conditions": [], + "endpoint": { + "url": "https://path.example.com", + "properties": {}, + "headers": {} + }, + "type": "endpoint" + }, + { + "conditions": [], + "endpoint": { + "url": "https://{Name}.{Stage}.example.com", + "properties": {}, + "headers": { + "x-kind": [ + "{Kind}" + ] + } + }, + "type": "endpoint" + }, + { + "conditions": [], + "endpoint": { + "url": "https://{Stage}.example.com", + "properties": { + "kind": "{Kind}" + }, + "headers": {} + }, + "type": "endpoint" + }, + { + "conditions": [], + "error": "No stage", + "type": "error" + } + ], + "root": 2, + "nodeCount": 8, + "nodes": "/////wAAAAH/////AAAAAAX14QEAAAADAAAAAQX14QIAAAAEAAAAAgX14QMAAAAFAAAAAwAAAAYF9eEGAAAABAAAAAcF9eEGAAAABQAAAAgF9eEFAAAABgX14QQF9eEF" + }, + "smithy.rules#endpointRuleSet": { + "version": "1.0", + "parameters": { + "Endpoint": { + "type": "string", + "builtIn": "SDK::Endpoint", + "documentation": "A custom endpoint." + }, + "Region": { + "type": "string", + "builtIn": "AWS::Region", + "documentation": "The region." + }, + "Stage": { + "type": "string", + "documentation": "The deployment stage." + }, + "ForcePathStyle": { + "type": "boolean", + "required": true, + "default": false, + "documentation": "Forces path-style addressing." + }, + "Name": { + "type": "string", + "documentation": "The thing name." + }, + "Kind": { + "type": "string", + "documentation": "The operation kind." + } + }, + "rules": [ + { + "conditions": [ + { + "fn": "isSet", + "argv": [ + { + "ref": "Endpoint" + } + ] + } + ], + "endpoint": { + "url": { + "ref": "Endpoint" + } + }, + "type": "endpoint" + }, + { + "conditions": [ + { + "fn": "isSet", + "argv": [ + { + "ref": "Region" + } + ] + } + ], + "endpoint": { + "url": "https://{Region}.example.com" + }, + "type": "endpoint" + }, + { + "conditions": [ + { + "fn": "booleanEquals", + "argv": [ + { + "ref": "ForcePathStyle" + }, + true + ] + } + ], + "endpoint": { + "url": "https://path.example.com" + }, + "type": "endpoint" + }, + { + "conditions": [ + { + "fn": "isSet", + "argv": [ + { + "ref": "Stage" + } + ] + }, + { + "fn": "isSet", + "argv": [ + { + "ref": "Name" + } + ] + }, + { + "fn": "isValidHostLabel", + "argv": [ + { + "ref": "Name" + }, + false + ] + }, + { + "fn": "isSet", + "argv": [ + { + "ref": "Kind" + } + ] + } + ], + "endpoint": { + "url": "https://{Name}.{Stage}.example.com", + "headers": { + "x-kind": [ + "{Kind}" + ] + } + }, + "type": "endpoint" + }, + { + "conditions": [ + { + "fn": "isSet", + "argv": [ + { + "ref": "Stage" + } + ] + }, + { + "fn": "isSet", + "argv": [ + { + "ref": "Kind" + } + ] + } + ], + "endpoint": { + "url": "https://{Stage}.example.com", + "properties": { + "kind": "{Kind}" + } + }, + "type": "endpoint" + }, + { + "conditions": [], + "error": "No stage", + "type": "error" + } + ] + }, + "smithy.rules#endpointTests": { + "version": "1.0", + "testCases": [ + { + "documentation": "Stage from config", + "params": { + "Stage": "beta", + "Kind": "ping" + }, + "expect": { + "endpoint": { + "url": "https://beta.example.com", + "properties": { + "kind": "ping" + } + } + }, + "operationInputs": [ + { + "operationName": "Ping", + "clientParams": { + "Stage": "beta" + } + } + ] + }, + { + "documentation": "Name from input", + "params": { + "Stage": "beta", + "Name": "thing", + "Kind": "put" + }, + "expect": { + "endpoint": { + "url": "https://thing.beta.example.com", + "headers": { + "x-kind": [ + "put" + ] + } + } + }, + "operationInputs": [ + { + "operationName": "PutThing", + "clientParams": { + "Stage": "beta" + }, + "operationParams": { + "name": "thing", + "tag": { + "key": "k", + "value": "v" + }, + "plugins": [ + "p" + ] + } + } + ] + }, + { + "documentation": "Invalid name falls back to the stage", + "params": { + "Stage": "beta", + "Name": "not a label", + "Kind": "put" + }, + "expect": { + "endpoint": { + "url": "https://beta.example.com", + "properties": { + "kind": "put" + } + } + }, + "operationInputs": [ + { + "operationName": "PutThing", + "clientParams": { + "Stage": "beta" + }, + "operationParams": { + "name": "not a label" + } + } + ] + }, + { + "documentation": "Path style from config", + "params": { + "ForcePathStyle": true + }, + "expect": { + "endpoint": { + "url": "https://path.example.com" + } + }, + "operationInputs": [ + { + "operationName": "Ping", + "clientParams": { + "ForcePathStyle": true + } + } + ] + }, + { + "documentation": "Custom endpoint", + "params": { + "Endpoint": "https://custom.example.com", + "Stage": "beta" + }, + "expect": { + "endpoint": { + "url": "https://custom.example.com" + } + }, + "operationInputs": [ + { + "operationName": "Ping", + "builtInParams": { + "SDK::Endpoint": "https://custom.example.com" + }, + "clientParams": { + "Stage": "beta" + } + } + ] + }, + { + "documentation": "Region from the built-in", + "params": { + "Region": "us-west-2" + }, + "expect": { + "endpoint": { + "url": "https://us-west-2.example.com" + } + }, + "operationInputs": [ + { + "operationName": "Ping", + "builtInParams": { + "AWS::Region": "us-west-2" + } + } + ] + }, + { + "documentation": "Missing stage", + "params": {}, + "expect": { + "error": "No stage" + }, + "operationInputs": [ + { + "operationName": "Ping" + } + ] + }, + { + "documentation": "Missing stage", + "params": { + "Kind": "put" + }, + "expect": { + "error": "No stage" + } + } + ] + } + } + }, + "example.endpoints#Ping": { + "type": "operation", + "input": { + "target": "smithy.api#Unit" + }, + "output": { + "target": "smithy.api#Unit" + }, + "traits": { + "smithy.rules#staticContextParams": { + "Kind": { + "value": "ping" + } + } + } + }, + "example.endpoints#PluginNames": { + "type": "list", + "member": { + "target": "smithy.api#String" + } + }, + "example.endpoints#PutThing": { + "type": "operation", + "input": { + "target": "example.endpoints#PutThingInput" + }, + "output": { + "target": "smithy.api#Unit" + }, + "traits": { + "smithy.rules#staticContextParams": { + "Kind": { + "value": "put" + } + } + } + }, + "example.endpoints#PutThingInput": { + "type": "structure", + "members": { + "name": { + "target": "smithy.api#String", + "traits": { + "smithy.api#required": {}, + "smithy.rules#contextParam": { + "name": "Name" + } + } + }, + "tag": { + "target": "example.endpoints#ThingTag" + }, + "plugins": { + "target": "example.endpoints#PluginNames" + } + }, + "traits": { + "smithy.api#input": {} + } + }, + "example.endpoints#ThingTag": { + "type": "structure", + "members": { + "key": { + "target": "smithy.api#String" + }, + "value": { + "target": "smithy.api#String" + } + } + } + } +} diff --git a/scripts/codegen-output-py/models/endpoint-rules.smithy b/scripts/codegen-output-py/models/endpoint-rules.smithy new file mode 100644 index 000000000..d902eeb76 --- /dev/null +++ b/scripts/codegen-output-py/models/endpoint-rules.smithy @@ -0,0 +1,190 @@ +$version: "2.0" + +namespace example.endpoints + +use smithy.protocols#rpcv2Cbor +use smithy.rules#clientContextParams +use smithy.rules#contextParam +use smithy.rules#endpointRuleSet +use smithy.rules#endpointTests +use smithy.rules#staticContextParams + +/// A service whose endpoint rules read config, input, and operation values. +@rpcv2Cbor +@clientContextParams( + Stage: { type: "string", documentation: "The deployment stage." } + ForcePathStyle: { type: "boolean", documentation: "Forces path-style addressing." } +) +@endpointRuleSet({ + version: "1.0" + parameters: { + Endpoint: { type: "string", builtIn: "SDK::Endpoint", documentation: "A custom endpoint." } + Region: { type: "string", builtIn: "AWS::Region", documentation: "The region." } + Stage: { type: "string", documentation: "The deployment stage." } + ForcePathStyle: { type: "boolean", required: true, default: false, documentation: "Forces path-style addressing." } + Name: { type: "string", documentation: "The thing name." } + Kind: { type: "string", documentation: "The operation kind." } + } + rules: [ + { + conditions: [{ fn: "isSet", argv: [{ ref: "Endpoint" }] }] + endpoint: { url: { ref: "Endpoint" } } + type: "endpoint" + } + { + conditions: [{ fn: "isSet", argv: [{ ref: "Region" }] }] + endpoint: { url: "https://{Region}.example.com" } + type: "endpoint" + } + { + conditions: [{ fn: "booleanEquals", argv: [{ ref: "ForcePathStyle" }, true] }] + endpoint: { url: "https://path.example.com" } + type: "endpoint" + } + { + conditions: [ + { fn: "isSet", argv: [{ ref: "Stage" }] } + { fn: "isSet", argv: [{ ref: "Name" }] } + { fn: "isValidHostLabel", argv: [{ ref: "Name" }, false] } + { fn: "isSet", argv: [{ ref: "Kind" }] } + ] + endpoint: { + url: "https://{Name}.{Stage}.example.com" + headers: { "x-kind": ["{Kind}"] } + } + type: "endpoint" + } + { + conditions: [ + { fn: "isSet", argv: [{ ref: "Stage" }] } + { fn: "isSet", argv: [{ ref: "Kind" }] } + ] + endpoint: { url: "https://{Stage}.example.com", properties: { kind: "{Kind}" } } + type: "endpoint" + } + { conditions: [], error: "No stage", type: "error" } + ] +}) +@endpointTests({ + version: "1.0" + testCases: [ + { + documentation: "Stage from config" + params: { Stage: "beta", Kind: "ping" } + expect: { + endpoint: { url: "https://beta.example.com", properties: { kind: "ping" } } + } + operationInputs: [ + { operationName: "Ping", clientParams: { Stage: "beta" } } + ] + } + { + documentation: "Name from input" + params: { Stage: "beta", Name: "thing", Kind: "put" } + expect: { + endpoint: { url: "https://thing.beta.example.com", headers: { "x-kind": ["put"] } } + } + operationInputs: [ + { + operationName: "PutThing" + clientParams: { Stage: "beta" } + operationParams: { + name: "thing" + tag: { key: "k", value: "v" } + plugins: ["p"] + } + } + ] + } + { + documentation: "Invalid name falls back to the stage" + params: { Stage: "beta", Name: "not a label", Kind: "put" } + expect: { + endpoint: { url: "https://beta.example.com", properties: { kind: "put" } } + } + operationInputs: [ + { + operationName: "PutThing" + clientParams: { Stage: "beta" } + operationParams: { name: "not a label" } + } + ] + } + { + documentation: "Path style from config" + params: { ForcePathStyle: true } + expect: { + endpoint: { url: "https://path.example.com" } + } + operationInputs: [ + { operationName: "Ping", clientParams: { ForcePathStyle: true } } + ] + } + { + documentation: "Custom endpoint" + params: { Endpoint: "https://custom.example.com", Stage: "beta" } + expect: { + endpoint: { url: "https://custom.example.com" } + } + operationInputs: [ + { + operationName: "Ping" + builtInParams: { "SDK::Endpoint": "https://custom.example.com" } + clientParams: { Stage: "beta" } + } + ] + } + { + documentation: "Region from the built-in" + params: { Region: "us-west-2" } + expect: { + endpoint: { url: "https://us-west-2.example.com" } + } + operationInputs: [ + { operationName: "Ping", builtInParams: { "AWS::Region": "us-west-2" } } + ] + } + { + documentation: "Missing stage" + params: {} + expect: { error: "No stage" } + operationInputs: [ + { operationName: "Ping" } + ] + } + { + documentation: "Missing stage" + params: { Kind: "put" } + expect: { error: "No stage" } + } + ] +}) +service EndpointService { + version: "2026-11-20" + operations: [Ping, PutThing] +} + +@staticContextParams(Kind: { value: "ping" }) +operation Ping {} + +@staticContextParams(Kind: { value: "put" }) +operation PutThing { + input := { + @required + @contextParam(name: "Name") + name: String + + tag: ThingTag + + plugins: PluginNames + } +} + +structure ThingTag { + key: String + value: String +} + +list PluginNames { + member: String +} diff --git a/scripts/codegen-output-py/pyrightconfig.json b/scripts/codegen-output-py/pyrightconfig.json index bb0672fe9..e72b183fd 100644 --- a/scripts/codegen-output-py/pyrightconfig.json +++ b/scripts/codegen-output-py/pyrightconfig.json @@ -12,6 +12,7 @@ "../../codegen-output-py/aws-json-1-1/src", "../../codegen-output-py/aws-query/src", "../../codegen-output-py/ec2-query/src", + "../../codegen-output-py/endpoint-rules-client/src", "../../codegen-output-py/my-handwritten-json-model/src", "../../codegen-output-py/my-handwritten-model/src", "../../codegen-output-py/non-query-compatible-rpcv2-cbor/src", @@ -19,12 +20,12 @@ "../../codegen-output-py/query-compatible-aws-json-1-0/src", "../../codegen-output-py/query-compatible-rpcv2-cbor/src", "../../codegen-output-py/rest-json-1/src", - "../../codegen-output-py/rest-xml/src", "../../codegen-output-py/rest-xml-with-namespace/src", - "../../codegen-output-py/rpcv2-cbor/src", + "../../codegen-output-py/rest-xml/src", "../../codegen-output-py/rpcv2-cbor-client/src", - "../../codegen-output-py/rpcv2-json/src", + "../../codegen-output-py/rpcv2-cbor/src", "../../codegen-output-py/rpcv2-json-client/src", + "../../codegen-output-py/rpcv2-json/src", "../../codegen-output-py/types/src" ] } diff --git a/scripts/codegen-output-py/tests/test_client_snapshots.py b/scripts/codegen-output-py/tests/test_client_snapshots.py index 105f7a3b9..30194a37d 100644 --- a/scripts/codegen-output-py/tests/test_client_snapshots.py +++ b/scripts/codegen-output-py/tests/test_client_snapshots.py @@ -7,6 +7,8 @@ import asyncio import importlib import json +import os +import subprocess import sys from collections.abc import Iterator from pathlib import Path @@ -133,3 +135,27 @@ def test_snapshot_client_round_trips_through_the_runtime( if asyncio.iscoroutine(body): body = asyncio.run(body) assert loads(body) == {"stringValue": "in", "integerValue": 3} + + +def test_generated_endpoint_tests_pass() -> None: + projection = _ROOT / "codegen-output-py/endpoint-rules-client" + result = subprocess.run( + [ + sys.executable, + "-m", + "pytest", + "tests", + "-q", + "-p", + "no:cacheprovider", + "-o", + "addopts=", + ], + cwd=projection, + env={**os.environ, "PYTHONPATH": str(projection / "src")}, + capture_output=True, + text=True, + check=False, + ) + assert result.returncode == 0, result.stdout + result.stderr + assert "14 passed, 1 skipped" in result.stdout diff --git a/scripts/verifications/import-cost.json b/scripts/verifications/import-cost.json index dc03ea645..4c85d5545 100644 --- a/scripts/verifications/import-cost.json +++ b/scripts/verifications/import-cost.json @@ -16,7 +16,7 @@ "smithy_json": 21, "smithy_json (all public modules)": 21, "smithy_python": 1, - "smithy_python (all public modules)": 25, + "smithy_python (all public modules)": 26, "smithy_test": 44, "smithy_test (all public modules)": 60, "smithy_xml": 20,