From 57e00ab768c93b7737cced164be9bf68cc274091 Mon Sep 17 00:00:00 2001 From: Sean O'Brien <60306702+stobrien89@users.noreply.github.com> Date: Tue, 17 Nov 2026 12:45:28 -0500 Subject: [PATCH] Generate Python RPCv2 JSON clients --- .../.smithy-python-manifest.json | 18 + codegen-output-py/rpcv2-json-client/README.md | 5 + .../rpcv2-json-client/pyproject.toml | 37 + .../src/rpcv2json_client/__init__.py | 25 + .../src/rpcv2json_client/_private/__init__.py | 0 .../src/rpcv2json_client/_private/schemas.py | 1155 +++++++++++ .../src/rpcv2json_client/aio/__init__.py | 19 + .../src/rpcv2json_client/aio/client.py | 549 +++++ .../src/rpcv2json_client/aio/config.py | 91 + .../src/rpcv2json_client/client.py | 549 +++++ .../src/rpcv2json_client/config.py | 90 + .../src/rpcv2json_client/models.py | 206 ++ .../src/rpcv2json_client/models.pyi | 804 ++++++++ .../src/rpcv2json_client/py.typed | 0 designs/codegen/client.md | 24 +- designs/codegen/snapshots.md | 21 +- ...ture-7e91f2b7956248c4aed733e029ac5374.json | 4 + .../src/smithy_python/protocols.py | 34 +- .../tests/unit/test_client_generation.py | 53 +- scripts/api-snapshot/api.json | 1 + .../codegen-output-py/client-projections.json | 7 + .../codegen-output-py/models/provenance.json | 5 +- .../models/vectors/rpcv2-cbor.json | 2 +- .../models/vectors/rpcv2-json.json | 1761 +++++++++++++++++ scripts/codegen-output-py/pyrightconfig.json | 1 + scripts/codegen-output-py/refresh_models.py | 22 +- .../tests/test_client_protocol_vectors.py | 51 +- 27 files changed, 5491 insertions(+), 43 deletions(-) create mode 100644 codegen-output-py/rpcv2-json-client/.smithy-python-manifest.json create mode 100644 codegen-output-py/rpcv2-json-client/README.md create mode 100644 codegen-output-py/rpcv2-json-client/pyproject.toml create mode 100644 codegen-output-py/rpcv2-json-client/src/rpcv2json_client/__init__.py create mode 100644 codegen-output-py/rpcv2-json-client/src/rpcv2json_client/_private/__init__.py create mode 100644 codegen-output-py/rpcv2-json-client/src/rpcv2json_client/_private/schemas.py create mode 100644 codegen-output-py/rpcv2-json-client/src/rpcv2json_client/aio/__init__.py create mode 100644 codegen-output-py/rpcv2-json-client/src/rpcv2json_client/aio/client.py create mode 100644 codegen-output-py/rpcv2-json-client/src/rpcv2json_client/aio/config.py create mode 100644 codegen-output-py/rpcv2-json-client/src/rpcv2json_client/client.py create mode 100644 codegen-output-py/rpcv2-json-client/src/rpcv2json_client/config.py create mode 100644 codegen-output-py/rpcv2-json-client/src/rpcv2json_client/models.py create mode 100644 codegen-output-py/rpcv2-json-client/src/rpcv2json_client/models.pyi create mode 100644 codegen-output-py/rpcv2-json-client/src/rpcv2json_client/py.typed create mode 100644 packages/smithy-python/.changes/next-release/smithy-python-feature-7e91f2b7956248c4aed733e029ac5374.json create mode 100644 scripts/codegen-output-py/models/vectors/rpcv2-json.json diff --git a/codegen-output-py/rpcv2-json-client/.smithy-python-manifest.json b/codegen-output-py/rpcv2-json-client/.smithy-python-manifest.json new file mode 100644 index 000000000..0f1a8c17f --- /dev/null +++ b/codegen-output-py/rpcv2-json-client/.smithy-python-manifest.json @@ -0,0 +1,18 @@ +{ + "files": { + "README.md": "45e418df185f3c97645bb27cde96c23d25862660c4efb7e07daa6f2f4e541833", + "pyproject.toml": "347f20c1040a5efdf94ec4759b126867f8e62b2baa8790b8cec9c3c2a18ee315", + "src/rpcv2json_client/__init__.py": "fa3fa16a23aaa1ad8d7a87a8c5475ac6b82cfeeabb83625ab4d28d3c3f6a0fbe", + "src/rpcv2json_client/_private/__init__.py": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "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/client.py": "64460ff50e711ab7d110b482a4c5d14ae4aa82b3e4938e4909a6b711462ee6bb", + "src/rpcv2json_client/config.py": "f59386780266cbcd806e0e2bb73e4e5bd43f085073f86737e86b30ba8245e2a2", + "src/rpcv2json_client/models.py": "94050bb13fbc2a62b3299790c28b270e6f42fb038f77fdd72f54077269a9c9a0", + "src/rpcv2json_client/models.pyi": "5f129d34dd7fd48915deb1396753bcd848eda16d5f1c043e988c605216cb4a8f", + "src/rpcv2json_client/py.typed": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + }, + "version": 1 +} diff --git a/codegen-output-py/rpcv2-json-client/README.md b/codegen-output-py/rpcv2-json-client/README.md new file mode 100644 index 000000000..f281651f7 --- /dev/null +++ b/codegen-output-py/rpcv2-json-client/README.md @@ -0,0 +1,5 @@ + + +## rpcv2json_client Client Package + +Python client for the rpcv2-json projection diff --git a/codegen-output-py/rpcv2-json-client/pyproject.toml b/codegen-output-py/rpcv2-json-client/pyproject.toml new file mode 100644 index 000000000..abe56a74d --- /dev/null +++ b/codegen-output-py/rpcv2-json-client/pyproject.toml @@ -0,0 +1,37 @@ +# Code generated by smithy-python-codegen DO NOT EDIT. + +[project] +name = "rpcv2json_client" +version = "0.0.1" +description = "Python client for the rpcv2-json projection" +readme = "README.md" +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", +] + +[build-system] +requires = [ + "hatchling", +] +build-backend = "hatchling.build" + +[tool.hatch.build.targets.wheel] +packages = [ + "src/rpcv2json_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/rpcv2-json-client/src/rpcv2json_client/__init__.py b/codegen-output-py/rpcv2-json-client/src/rpcv2json_client/__init__.py new file mode 100644 index 000000000..5e9a0551c --- /dev/null +++ b/codegen-output-py/rpcv2-json-client/src/rpcv2json_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 AsyncRpcV2JsonProtocol + from .aio.config import AsyncConfig + from .client import RpcV2JsonProtocol + from .config import Config + +__all__ = ["AsyncConfig", "AsyncRpcV2JsonProtocol", "Config", "RpcV2JsonProtocol"] + +_EXPORTS = { + "RpcV2JsonProtocol": ".client", + "Config": ".config", + "AsyncRpcV2JsonProtocol": ".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/rpcv2-json-client/src/rpcv2json_client/_private/__init__.py b/codegen-output-py/rpcv2-json-client/src/rpcv2json_client/_private/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/codegen-output-py/rpcv2-json-client/src/rpcv2json_client/_private/schemas.py b/codegen-output-py/rpcv2-json-client/src/rpcv2json_client/_private/schemas.py new file mode 100644 index 000000000..e1a3ea8ca --- /dev/null +++ b/codegen-output-py/rpcv2-json-client/src/rpcv2json_client/_private/schemas.py @@ -0,0 +1,1155 @@ +from types import MappingProxyType + +from smithy_core._schema_compact import StaticOperationSchema, StaticSchema + +n0 = "smithy.framework" +_s0 = "ValidationExceptionField" +_s1 = "path" +_s2 = "message" +_s3 = "ValidationExceptionFieldList" +_s4 = "member" +_s5 = "ValidationException" +_s6 = "smithy.api#error" +_s7 = "client" +_s8 = "fieldList" +n1 = "smithy.protocoltests.rpcv2Json" +_s9 = "ClientOptionalDefaults" +_s10 = "smithy.api#clientOptional" +_s11 = "smithy.api#default" +_s12 = "ComplexNestedErrorData" +_s13 = "Foo" +_s14 = "ComplexError" +_s15 = "TopLevel" +_s16 = "Nested" +_s17 = "TestStringList" +_s18 = "TestStringMap" +_s19 = "key" +_s20 = "value" +_s21 = "TestEnum" +_s22 = "FOO" +_s23 = "smithy.api#enumValue" +_s24 = "BAR" +_s25 = "BAZ" +_s26 = "TestIntEnum" +_s27 = "ONE" +_s28 = "TWO" +_s29 = "Defaults" +_s30 = "defaultString" +_s31 = "hi" +_s32 = "defaultBoolean" +_s33 = "defaultList" +_s34 = "defaultTimestamp" +_s35 = "defaultBlob" +_s36 = "YWJj" +_s37 = "defaultByte" +_s38 = "defaultShort" +_s39 = "defaultInteger" +_s40 = "defaultLong" +_s41 = "defaultFloat" +_s42 = "defaultDouble" +_s43 = "defaultMap" +_s44 = "defaultEnum" +_s45 = "defaultIntEnum" +_s46 = "emptyString" +_s47 = "" +_s48 = "falseBoolean" +_s49 = "emptyBlob" +_s50 = "zeroByte" +_s51 = "zeroShort" +_s52 = "zeroInteger" +_s53 = "zeroLong" +_s54 = "zeroFloat" +_s55 = "zeroDouble" +_s56 = "DenseBooleanMap" +_s57 = "DenseNumberMap" +n2 = "smithy.protocoltests.shared" +_s58 = "StringSet" +_s59 = "DenseSetMap" +_s60 = "DenseStringMap" +_s61 = "GreetingStruct" +_s62 = "DenseStructMap" +_s63 = "FractionalSecondsOutput" +_s64 = "smithy.synthetic#originalShapeId" +_s65 = "smithy.protocoltests.rpcv2Json#FractionalSecondsOutput" +_s66 = "smithy.api#output" +_s67 = "datetime" +_s68 = "GreetingWithErrorsOutput" +_s69 = "smithy.protocoltests.rpcv2Json#GreetingWithErrorsOutput" +_s70 = "greeting" +_s71 = "InvalidGreeting" +_s72 = "Message" +_s73 = "OperationWithDefaultsInput" +_s74 = "smithy.protocoltests.rpcv2Json#OperationWithDefaultsInput" +_s75 = "smithy.api#input" +_s76 = "defaults" +_s77 = "clientOptionalDefaults" +_s78 = "topLevelDefault" +_s79 = "otherTopLevelDefault" +_s80 = "OperationWithDefaultsOutput" +_s81 = "smithy.protocoltests.rpcv2Json#OperationWithDefaultsOutput" +_s82 = "SparseBooleanMap" +_s83 = "SparseNumberMap" +_s84 = "SparseSetMap" +_s85 = "SparseStructMap" +_s86 = "StructureListMember" +_s87 = "a" +_s88 = "b" +_s89 = "StructureList" +_s90 = "BlobList" +_s91 = "BooleanList" +_s92 = "DateTime" +_s93 = "smithy.api#timestampFormat" +_s94 = "date-time" +_s95 = "EpochSeconds" +_s96 = "epoch-seconds" +_s97 = "FooEnum" +_s98 = "Baz" +_s99 = "Bar" +_s100 = "1" +_s101 = "ZERO" +_s102 = "0" +_s103 = "FooEnumList" +_s104 = "HttpDate" +_s105 = "http-date" +_s106 = "IntegerEnum" +_s107 = "A" +_s108 = "B" +_s109 = "C" +_s110 = "IntegerEnumList" +_s111 = "IntegerList" +_s112 = "StringList" +_s113 = "NestedStringList" +_s114 = "SparseStringList" +_s115 = "SparseStringMap" +_s116 = "TimestampList" +_s117 = "BigDecimalOperationInput" +_s118 = "smithy.protocoltests.rpcv2Json#BigDecimalStructure" +_s119 = "BigDecimalOperationOutput" +_s120 = "BigIntegerOperationInput" +_s121 = "smithy.protocoltests.rpcv2Json#BigIntegerStructure" +_s122 = "BigIntegerOperationOutput" +_s123 = "EmptyInputOutputInput" +_s124 = "smithy.protocoltests.rpcv2Json#EmptyStructure" +_s125 = "EmptyInputOutputOutput" +_s126 = "FractionalSecondsInput" +_s127 = "smithy.api#Unit" +_s128 = "GreetingWithErrorsInput" +_s129 = "NoInputOutputInput" +_s130 = "NoInputOutputOutput" +_s131 = "OptionalInputOutputInput" +_s132 = "smithy.protocoltests.rpcv2Json#SimpleStructure" +_s133 = "OptionalInputOutputOutput" +_s134 = "RecursiveShapesInput" +_s135 = "smithy.protocoltests.rpcv2Json#RecursiveShapesInputOutput" +_s136 = "nested" +_s137 = "RecursiveShapesOutput" +_s138 = "RpcV2JsonDenseMapsInput" +_s139 = "smithy.protocoltests.rpcv2Json#RpcV2JsonDenseMapsInputOutput" +_s140 = "denseStructMap" +_s141 = "denseNumberMap" +_s142 = "denseBooleanMap" +_s143 = "denseStringMap" +_s144 = "denseSetMap" +_s145 = "RpcV2JsonDenseMapsOutput" +_s146 = "RpcV2JsonListsInput" +_s147 = "smithy.protocoltests.rpcv2Json#RpcV2JsonListInputOutput" +_s148 = "stringList" +_s149 = "stringSet" +_s150 = "integerList" +_s151 = "booleanList" +_s152 = "timestampList" +_s153 = "enumList" +_s154 = "intEnumList" +_s155 = "nestedStringList" +_s156 = "structureList" +_s157 = "blobList" +_s158 = "RpcV2JsonListsOutput" +_s159 = "RpcV2JsonSparseMapsInput" +_s160 = "smithy.protocoltests.rpcv2Json#RpcV2JsonSparseMapsInputOutput" +_s161 = "sparseStructMap" +_s162 = "sparseNumberMap" +_s163 = "sparseBooleanMap" +_s164 = "sparseStringMap" +_s165 = "sparseSetMap" +_s166 = "RpcV2JsonSparseMapsOutput" +_s167 = "SimpleScalarPropertiesInput" +_s168 = "smithy.protocoltests.rpcv2Json#SimpleScalarStructure" +_s169 = "trueBooleanValue" +_s170 = "falseBooleanValue" +_s171 = "byteValue" +_s172 = "doubleValue" +_s173 = "floatValue" +_s174 = "integerValue" +_s175 = "longValue" +_s176 = "shortValue" +_s177 = "stringValue" +_s178 = "blobValue" +_s179 = "SimpleScalarPropertiesOutput" +_s180 = "SparseNullsOperationInput" +_s181 = "smithy.protocoltests.rpcv2Json#SparseNullsOperationInputOutput" +_s182 = "sparseStringList" +_s183 = "SparseNullsOperationOutput" +_s184 = "TimestampFormatIgnoredInput" +_s185 = "smithy.protocoltests.rpcv2Json#TimestampFormatIgnoredIO" +_s186 = "dateTime" +_s187 = "httpDate" +_s188 = "epochSeconds" +_s189 = "normal" +_s190 = "TimestampFormatIgnoredOutput" +_s191 = "BigDecimalOperation" +_s192 = "BigIntegerOperation" +_s193 = "EmptyInputOutput" +_s194 = "FractionalSeconds" +_s195 = "GreetingWithErrors" +_s196 = "NoInputOutput" +_s197 = "OperationWithDefaults" +_s198 = "OptionalInputOutput" +_s199 = "RecursiveShapes" +_s200 = "RpcV2JsonDenseMaps" +_s201 = "RpcV2JsonLists" +_s202 = "RpcV2JsonSparseMaps" +_s203 = "SimpleScalarProperties" +_s204 = "SparseNullsOperation" +_s205 = "TimestampFormatIgnored" +_s206 = "RpcV2JsonProtocol" +_s207 = "smithy.protocols#rpcv2Json" +_s208 = "RecursiveShapesInputOutputNested1" +_s209 = "foo" +_s210 = "RecursiveShapesInputOutputNested2" +_s211 = "bar" +_s212 = "recursiveMember" + +VALIDATION_EXCEPTION_FIELD: StaticSchema = ( + 18, + n0, + _s0, + 0, + (_s1, _s2), + ((3, 1), (3, 1)), +) + +VALIDATION_EXCEPTION_FIELD_LIST: StaticSchema = ( + 16, + n0, + _s3, + 0, + (_s4,), + ((VALIDATION_EXCEPTION_FIELD, 0),), +) + +VALIDATION_EXCEPTION: StaticSchema = ( + 18, + n0, + _s5, + {_s6: _s7}, + (_s2, _s8), + ((3, 1), (VALIDATION_EXCEPTION_FIELD_LIST, 0)), +) + +CLIENT_OPTIONAL_DEFAULTS: StaticSchema = ( + 18, + n1, + _s9, + 0, + (_s4,), + ((7, {_s10: None, _s11: 0}),), +) + +COMPLEX_NESTED_ERROR_DATA: StaticSchema = ( + 18, + n1, + _s12, + 0, + (_s13,), + ((3, 0),), +) + +COMPLEX_ERROR: StaticSchema = ( + 18, + n1, + _s14, + {_s6: _s7}, + (_s15, _s16), + ((3, 0), (COMPLEX_NESTED_ERROR_DATA, 0)), +) + +TEST_STRING_LIST: StaticSchema = ( + 16, + n1, + _s17, + 0, + (_s4,), + ((3, 0),), +) + +TEST_STRING_MAP: StaticSchema = ( + 17, + n1, + _s18, + 0, + (_s19, _s20), + ((3, 0), (3, 0)), +) + +TEST_ENUM: StaticSchema = ( + 14, + n1, + _s21, + 0, + (_s22, _s24, _s25), + ((-1, {_s23: _s22}), (-1, {_s23: _s24}), (-1, {_s23: _s25})), +) + +TEST_INT_ENUM: StaticSchema = ( + 15, + n1, + _s26, + 0, + (_s27, _s28), + ((-1, {_s23: 1}), (-1, {_s23: 2})), +) + +DEFAULTS: StaticSchema = ( + 18, + n1, + _s29, + 0, + ( + _s30, + _s32, + _s33, + _s34, + _s35, + _s37, + _s38, + _s39, + _s40, + _s41, + _s42, + _s43, + _s44, + _s45, + _s46, + _s48, + _s49, + _s50, + _s51, + _s52, + _s53, + _s54, + _s55, + ), + ( + (3, {_s11: _s31}), + (2, {_s11: True}), + (TEST_STRING_LIST, {_s11: ()}), + (4, {_s11: 0}), + (1, {_s11: _s36}), + (5, {_s11: 1}), + (6, {_s11: 1}), + (7, {_s11: 10}), + (8, {_s11: 100}), + (9, {_s11: 1.0}), + (10, {_s11: 1.0}), + (TEST_STRING_MAP, {_s11: MappingProxyType[str, object]({})}), + (TEST_ENUM, {_s11: _s22}), + (TEST_INT_ENUM, {_s11: 1}), + (3, {_s11: _s47}), + (2, {_s11: False}), + (1, {_s11: _s47}), + (5, {_s11: 0}), + (6, {_s11: 0}), + (7, {_s11: 0}), + (8, {_s11: 0}), + (9, {_s11: 0.0}), + (10, {_s11: 0.0}), + ), +) + +DENSE_BOOLEAN_MAP: StaticSchema = ( + 17, + n1, + _s56, + 0, + (_s19, _s20), + ((3, 0), (2, 0)), +) + +DENSE_NUMBER_MAP: StaticSchema = ( + 17, + n1, + _s57, + 0, + (_s19, _s20), + ((3, 0), (7, 0)), +) + +STRING_SET: StaticSchema = ( + 16, + n2, + _s58, + 0, + (_s4,), + ((3, 0),), +) + +DENSE_SET_MAP: StaticSchema = ( + 17, + n1, + _s59, + 0, + (_s19, _s20), + ((3, 0), (STRING_SET, 0)), +) + +DENSE_STRING_MAP: StaticSchema = ( + 17, + n1, + _s60, + 0, + (_s19, _s20), + ((3, 0), (3, 0)), +) + +GREETING_STRUCT: StaticSchema = ( + 18, + n2, + _s61, + 0, + (_s31,), + ((3, 0),), +) + +DENSE_STRUCT_MAP: StaticSchema = ( + 17, + n1, + _s62, + 0, + (_s19, _s20), + ((3, 0), (GREETING_STRUCT, 0)), +) + +FRACTIONAL_SECONDS_OUTPUT: StaticSchema = ( + 18, + n1, + _s63, + {_s64: _s65, _s66: None}, + (_s67,), + ((4, 0),), +) + +GREETING_WITH_ERRORS_OUTPUT: StaticSchema = ( + 18, + n1, + _s68, + {_s64: _s69, _s66: None}, + (_s70,), + ((3, 0),), +) + +INVALID_GREETING: StaticSchema = ( + 18, + n1, + _s71, + {_s6: _s7}, + (_s72,), + ((3, 0),), +) + +OPERATION_WITH_DEFAULTS_INPUT: StaticSchema = ( + 18, + n1, + _s73, + {_s64: _s74, _s75: None}, + (_s76, _s77, _s78, _s79), + ((DEFAULTS, 0), (CLIENT_OPTIONAL_DEFAULTS, 0), (3, {_s11: _s31}), (7, {_s11: 0})), +) + +OPERATION_WITH_DEFAULTS_OUTPUT: StaticSchema = ( + 18, + n1, + _s80, + {_s64: _s81, _s66: None}, + ( + _s30, + _s32, + _s33, + _s34, + _s35, + _s37, + _s38, + _s39, + _s40, + _s41, + _s42, + _s43, + _s44, + _s45, + _s46, + _s48, + _s49, + _s50, + _s51, + _s52, + _s53, + _s54, + _s55, + ), + ( + (3, {_s11: _s31}), + (2, {_s11: True}), + (TEST_STRING_LIST, {_s11: ()}), + (4, {_s11: 0}), + (1, {_s11: _s36}), + (5, {_s11: 1}), + (6, {_s11: 1}), + (7, {_s11: 10}), + (8, {_s11: 100}), + (9, {_s11: 1.0}), + (10, {_s11: 1.0}), + (TEST_STRING_MAP, {_s11: MappingProxyType[str, object]({})}), + (TEST_ENUM, {_s11: _s22}), + (TEST_INT_ENUM, {_s11: 1}), + (3, {_s11: _s47}), + (2, {_s11: False}), + (1, {_s11: _s47}), + (5, {_s11: 0}), + (6, {_s11: 0}), + (7, {_s11: 0}), + (8, {_s11: 0}), + (9, {_s11: 0.0}), + (10, {_s11: 0.0}), + ), +) + +SPARSE_BOOLEAN_MAP: StaticSchema = ( + 17, + n1, + _s82, + 64, + (_s19, _s20), + ((3, 0), (2, 0)), +) + +SPARSE_NUMBER_MAP: StaticSchema = ( + 17, + n1, + _s83, + 64, + (_s19, _s20), + ((3, 0), (7, 0)), +) + +SPARSE_SET_MAP: StaticSchema = ( + 17, + n1, + _s84, + 64, + (_s19, _s20), + ((3, 0), (STRING_SET, 0)), +) + +SPARSE_STRUCT_MAP: StaticSchema = ( + 17, + n1, + _s85, + 64, + (_s19, _s20), + ((3, 0), (GREETING_STRUCT, 0)), +) + +STRUCTURE_LIST_MEMBER: StaticSchema = ( + 18, + n1, + _s86, + 0, + (_s87, _s88), + ((3, 0), (3, 0)), +) + +STRUCTURE_LIST: StaticSchema = ( + 16, + n1, + _s89, + 0, + (_s4,), + ((STRUCTURE_LIST_MEMBER, 0),), +) + +BLOB_LIST: StaticSchema = ( + 16, + n2, + _s90, + 0, + (_s4,), + ((1, 0),), +) + +BOOLEAN_LIST: StaticSchema = ( + 16, + n2, + _s91, + 0, + (_s4,), + ((2, 0),), +) + +DATE_TIME: StaticSchema = ( + 4, + n2, + _s92, + {_s93: _s94}, +) + +EPOCH_SECONDS: StaticSchema = ( + 4, + n2, + _s95, + {_s93: _s96}, +) + +FOO_ENUM: StaticSchema = ( + 14, + n2, + _s97, + 0, + (_s22, _s25, _s24, _s27, _s101), + ( + (-1, {_s23: _s13}), + (-1, {_s23: _s98}), + (-1, {_s23: _s99}), + (-1, {_s23: _s100}), + (-1, {_s23: _s102}), + ), +) + +FOO_ENUM_LIST: StaticSchema = ( + 16, + n2, + _s103, + 0, + (_s4,), + ((FOO_ENUM, 0),), +) + +HTTP_DATE: StaticSchema = ( + 4, + n2, + _s104, + {_s93: _s105}, +) + +INTEGER_ENUM: StaticSchema = ( + 15, + n2, + _s106, + 0, + (_s107, _s108, _s109), + ((-1, {_s23: 1}), (-1, {_s23: 2}), (-1, {_s23: 3})), +) + +INTEGER_ENUM_LIST: StaticSchema = ( + 16, + n2, + _s110, + 0, + (_s4,), + ((INTEGER_ENUM, 0),), +) + +INTEGER_LIST: StaticSchema = ( + 16, + n2, + _s111, + 0, + (_s4,), + ((7, 0),), +) + +STRING_LIST: StaticSchema = ( + 16, + n2, + _s112, + 0, + (_s4,), + ((3, 0),), +) + +NESTED_STRING_LIST: StaticSchema = ( + 16, + n2, + _s113, + 0, + (_s4,), + ((STRING_LIST, 0),), +) + +SPARSE_STRING_LIST: StaticSchema = ( + 16, + n2, + _s114, + 64, + (_s4,), + ((3, 0),), +) + +SPARSE_STRING_MAP: StaticSchema = ( + 17, + n2, + _s115, + 64, + (_s19, _s20), + ((3, 0), (3, 0)), +) + +TIMESTAMP_LIST: StaticSchema = ( + 16, + n2, + _s116, + 0, + (_s4,), + ((4, 0),), +) + +BIG_DECIMAL_OPERATION_INPUT: StaticSchema = ( + 18, + n1, + _s117, + {_s64: _s118, _s75: None}, + (_s20,), + ((12, 0),), +) + +BIG_DECIMAL_OPERATION_OUTPUT: StaticSchema = ( + 18, + n1, + _s119, + {_s64: _s118, _s66: None}, + (_s20,), + ((12, 0),), +) + +BIG_INTEGER_OPERATION_INPUT: StaticSchema = ( + 18, + n1, + _s120, + {_s64: _s121, _s75: None}, + (_s20,), + ((11, 0),), +) + +BIG_INTEGER_OPERATION_OUTPUT: StaticSchema = ( + 18, + n1, + _s122, + {_s64: _s121, _s66: None}, + (_s20,), + ((11, 0),), +) + +EMPTY_INPUT_OUTPUT_INPUT: StaticSchema = ( + 18, + n1, + _s123, + {_s64: _s124, _s75: None}, +) + +EMPTY_INPUT_OUTPUT_OUTPUT: StaticSchema = ( + 18, + n1, + _s125, + {_s64: _s124, _s66: None}, +) + +FRACTIONAL_SECONDS_INPUT: StaticSchema = ( + 18, + n1, + _s126, + {_s64: _s127, _s75: None}, +) + +GREETING_WITH_ERRORS_INPUT: StaticSchema = ( + 18, + n1, + _s128, + {_s64: _s127, _s75: None}, +) + +NO_INPUT_OUTPUT_INPUT: StaticSchema = ( + 18, + n1, + _s129, + {_s64: _s127, _s75: None}, +) + +NO_INPUT_OUTPUT_OUTPUT: StaticSchema = ( + 18, + n1, + _s130, + {_s64: _s127, _s66: None}, +) + +OPTIONAL_INPUT_OUTPUT_INPUT: StaticSchema = ( + 18, + n1, + _s131, + {_s64: _s132, _s75: None}, + (_s20,), + ((3, 0),), +) + +OPTIONAL_INPUT_OUTPUT_OUTPUT: StaticSchema = ( + 18, + n1, + _s133, + {_s64: _s132, _s66: None}, + (_s20,), + ((3, 0),), +) + +RECURSIVE_SHAPES_INPUT: StaticSchema = ( + 18, + n1, + _s134, + {_s64: _s135, _s75: None}, + (_s136,), + ((lambda: RECURSIVE_SHAPES_INPUT_OUTPUT_NESTED1, 0),), +) + +RECURSIVE_SHAPES_OUTPUT: StaticSchema = ( + 18, + n1, + _s137, + {_s64: _s135, _s66: None}, + (_s136,), + ((lambda: RECURSIVE_SHAPES_INPUT_OUTPUT_NESTED1, 0),), +) + +RPC_V2_JSON_DENSE_MAPS_INPUT: StaticSchema = ( + 18, + n1, + _s138, + {_s64: _s139, _s75: None}, + (_s140, _s141, _s142, _s143, _s144), + ( + (DENSE_STRUCT_MAP, 0), + (DENSE_NUMBER_MAP, 0), + (DENSE_BOOLEAN_MAP, 0), + (DENSE_STRING_MAP, 0), + (DENSE_SET_MAP, 0), + ), +) + +RPC_V2_JSON_DENSE_MAPS_OUTPUT: StaticSchema = ( + 18, + n1, + _s145, + {_s64: _s139, _s66: None}, + (_s140, _s141, _s142, _s143, _s144), + ( + (DENSE_STRUCT_MAP, 0), + (DENSE_NUMBER_MAP, 0), + (DENSE_BOOLEAN_MAP, 0), + (DENSE_STRING_MAP, 0), + (DENSE_SET_MAP, 0), + ), +) + +RPC_V2_JSON_LISTS_INPUT: StaticSchema = ( + 18, + n1, + _s146, + {_s64: _s147, _s75: None}, + (_s148, _s149, _s150, _s151, _s152, _s153, _s154, _s155, _s156, _s157), + ( + (STRING_LIST, 0), + (STRING_SET, 0), + (INTEGER_LIST, 0), + (BOOLEAN_LIST, 0), + (TIMESTAMP_LIST, 0), + (FOO_ENUM_LIST, 0), + (INTEGER_ENUM_LIST, 0), + (NESTED_STRING_LIST, 0), + (STRUCTURE_LIST, 0), + (BLOB_LIST, 0), + ), +) + +RPC_V2_JSON_LISTS_OUTPUT: StaticSchema = ( + 18, + n1, + _s158, + {_s64: _s147, _s66: None}, + (_s148, _s149, _s150, _s151, _s152, _s153, _s154, _s155, _s156, _s157), + ( + (STRING_LIST, 0), + (STRING_SET, 0), + (INTEGER_LIST, 0), + (BOOLEAN_LIST, 0), + (TIMESTAMP_LIST, 0), + (FOO_ENUM_LIST, 0), + (INTEGER_ENUM_LIST, 0), + (NESTED_STRING_LIST, 0), + (STRUCTURE_LIST, 0), + (BLOB_LIST, 0), + ), +) + +RPC_V2_JSON_SPARSE_MAPS_INPUT: StaticSchema = ( + 18, + n1, + _s159, + {_s64: _s160, _s75: None}, + (_s161, _s162, _s163, _s164, _s165), + ( + (SPARSE_STRUCT_MAP, 0), + (SPARSE_NUMBER_MAP, 0), + (SPARSE_BOOLEAN_MAP, 0), + (SPARSE_STRING_MAP, 0), + (SPARSE_SET_MAP, 0), + ), +) + +RPC_V2_JSON_SPARSE_MAPS_OUTPUT: StaticSchema = ( + 18, + n1, + _s166, + {_s64: _s160, _s66: None}, + (_s161, _s162, _s163, _s164, _s165), + ( + (SPARSE_STRUCT_MAP, 0), + (SPARSE_NUMBER_MAP, 0), + (SPARSE_BOOLEAN_MAP, 0), + (SPARSE_STRING_MAP, 0), + (SPARSE_SET_MAP, 0), + ), +) + +SIMPLE_SCALAR_PROPERTIES_INPUT: StaticSchema = ( + 18, + n1, + _s167, + {_s64: _s168, _s75: None}, + (_s169, _s170, _s171, _s172, _s173, _s174, _s175, _s176, _s177, _s178), + ((2, 0), (2, 0), (5, 0), (10, 0), (9, 0), (7, 0), (8, 0), (6, 0), (3, 0), (1, 0)), +) + +SIMPLE_SCALAR_PROPERTIES_OUTPUT: StaticSchema = ( + 18, + n1, + _s179, + {_s64: _s168, _s66: None}, + (_s169, _s170, _s171, _s172, _s173, _s174, _s175, _s176, _s177, _s178), + ((2, 0), (2, 0), (5, 0), (10, 0), (9, 0), (7, 0), (8, 0), (6, 0), (3, 0), (1, 0)), +) + +SPARSE_NULLS_OPERATION_INPUT: StaticSchema = ( + 18, + n1, + _s180, + {_s64: _s181, _s75: None}, + (_s182, _s164), + ((SPARSE_STRING_LIST, 0), (SPARSE_STRING_MAP, 0)), +) + +SPARSE_NULLS_OPERATION_OUTPUT: StaticSchema = ( + 18, + n1, + _s183, + {_s64: _s181, _s66: None}, + (_s182, _s164), + ((SPARSE_STRING_LIST, 0), (SPARSE_STRING_MAP, 0)), +) + +TIMESTAMP_FORMAT_IGNORED_INPUT: StaticSchema = ( + 18, + n1, + _s184, + {_s64: _s185, _s75: None}, + (_s186, _s187, _s188, _s189), + ((DATE_TIME, 0), (HTTP_DATE, 0), (EPOCH_SECONDS, 0), (4, 0)), +) + +TIMESTAMP_FORMAT_IGNORED_OUTPUT: StaticSchema = ( + 18, + n1, + _s190, + {_s64: _s185, _s66: None}, + (_s186, _s187, _s188, _s189), + ((DATE_TIME, 0), (HTTP_DATE, 0), (EPOCH_SECONDS, 0), (4, 0)), +) + +BIG_DECIMAL_OPERATION: StaticOperationSchema = ( + 23, + n1, + _s191, + 0, + BIG_DECIMAL_OPERATION_INPUT, + BIG_DECIMAL_OPERATION_OUTPUT, + (), +) + +BIG_INTEGER_OPERATION: StaticOperationSchema = ( + 23, + n1, + _s192, + 0, + BIG_INTEGER_OPERATION_INPUT, + BIG_INTEGER_OPERATION_OUTPUT, + (), +) + +EMPTY_INPUT_OUTPUT: StaticOperationSchema = ( + 23, + n1, + _s193, + 0, + EMPTY_INPUT_OUTPUT_INPUT, + EMPTY_INPUT_OUTPUT_OUTPUT, + (), +) + +FRACTIONAL_SECONDS: StaticOperationSchema = ( + 23, + n1, + _s194, + 0, + FRACTIONAL_SECONDS_INPUT, + FRACTIONAL_SECONDS_OUTPUT, + (), +) + +GREETING_WITH_ERRORS: StaticOperationSchema = ( + 23, + n1, + _s195, + 0, + GREETING_WITH_ERRORS_INPUT, + GREETING_WITH_ERRORS_OUTPUT, + (COMPLEX_ERROR, INVALID_GREETING), +) + +NO_INPUT_OUTPUT: StaticOperationSchema = ( + 23, + n1, + _s196, + 0, + NO_INPUT_OUTPUT_INPUT, + NO_INPUT_OUTPUT_OUTPUT, + (), +) + +OPERATION_WITH_DEFAULTS: StaticOperationSchema = ( + 23, + n1, + _s197, + 0, + OPERATION_WITH_DEFAULTS_INPUT, + OPERATION_WITH_DEFAULTS_OUTPUT, + (VALIDATION_EXCEPTION,), +) + +OPTIONAL_INPUT_OUTPUT: StaticOperationSchema = ( + 23, + n1, + _s198, + 0, + OPTIONAL_INPUT_OUTPUT_INPUT, + OPTIONAL_INPUT_OUTPUT_OUTPUT, + (), +) + +RECURSIVE_SHAPES: StaticOperationSchema = ( + 23, + n1, + _s199, + 0, + RECURSIVE_SHAPES_INPUT, + RECURSIVE_SHAPES_OUTPUT, + (), +) + +RPC_V2_JSON_DENSE_MAPS: StaticOperationSchema = ( + 23, + n1, + _s200, + 0, + RPC_V2_JSON_DENSE_MAPS_INPUT, + RPC_V2_JSON_DENSE_MAPS_OUTPUT, + (VALIDATION_EXCEPTION,), +) + +RPC_V2_JSON_LISTS: StaticOperationSchema = ( + 23, + n1, + _s201, + 0, + RPC_V2_JSON_LISTS_INPUT, + RPC_V2_JSON_LISTS_OUTPUT, + (VALIDATION_EXCEPTION,), +) + +RPC_V2_JSON_SPARSE_MAPS: StaticOperationSchema = ( + 23, + n1, + _s202, + 0, + RPC_V2_JSON_SPARSE_MAPS_INPUT, + RPC_V2_JSON_SPARSE_MAPS_OUTPUT, + (VALIDATION_EXCEPTION,), +) + +SIMPLE_SCALAR_PROPERTIES: StaticOperationSchema = ( + 23, + n1, + _s203, + 0, + SIMPLE_SCALAR_PROPERTIES_INPUT, + SIMPLE_SCALAR_PROPERTIES_OUTPUT, + (), +) + +SPARSE_NULLS_OPERATION: StaticOperationSchema = ( + 23, + n1, + _s204, + 0, + SPARSE_NULLS_OPERATION_INPUT, + SPARSE_NULLS_OPERATION_OUTPUT, + (), +) + +TIMESTAMP_FORMAT_IGNORED: StaticOperationSchema = ( + 23, + n1, + _s205, + 0, + TIMESTAMP_FORMAT_IGNORED_INPUT, + TIMESTAMP_FORMAT_IGNORED_OUTPUT, + (), +) + +RPC_V2_JSON_PROTOCOL: StaticSchema = ( + 21, + n1, + _s206, + {_s207: None}, +) + +RECURSIVE_SHAPES_INPUT_OUTPUT_NESTED1: StaticSchema = ( + 18, + n1, + _s208, + 0, + (_s209, _s136), + ((3, 0), (lambda: RECURSIVE_SHAPES_INPUT_OUTPUT_NESTED2, 0)), +) + +RECURSIVE_SHAPES_INPUT_OUTPUT_NESTED2: StaticSchema = ( + 18, + n1, + _s210, + 0, + (_s211, _s212), + ((3, 0), (RECURSIVE_SHAPES_INPUT_OUTPUT_NESTED1, 0)), +) diff --git a/codegen-output-py/rpcv2-json-client/src/rpcv2json_client/aio/__init__.py b/codegen-output-py/rpcv2-json-client/src/rpcv2json_client/aio/__init__.py new file mode 100644 index 000000000..7b362c726 --- /dev/null +++ b/codegen-output-py/rpcv2-json-client/src/rpcv2json_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 AsyncRpcV2JsonProtocol + from .config import AsyncConfig + +__all__ = ["AsyncConfig", "AsyncRpcV2JsonProtocol"] + +_EXPORTS = { + "AsyncRpcV2JsonProtocol": ".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/rpcv2-json-client/src/rpcv2json_client/aio/client.py b/codegen-output-py/rpcv2-json-client/src/rpcv2json_client/aio/client.py new file mode 100644 index 000000000..8569e15c9 --- /dev/null +++ b/codegen-output-py/rpcv2-json-client/src/rpcv2json_client/aio/client.py @@ -0,0 +1,549 @@ +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 rpcv2json_client import models +from rpcv2json_client.aio.config import AsyncConfig, Plugin + + +class AsyncRpcV2JsonProtocol(AsyncClient[AsyncConfig]): + "Client for RpcV2JsonProtocol." + + _client_plugins = (user_agent_plugin,) + + @overload + async def big_decimal_operation( + self, + request: models.BigDecimalOperationInput | models.BigDecimalOperationInputDict, + /, + *, + plugins: list[Plugin] | None = None, + ) -> models.BigDecimalOperationOutput: ... + + @overload + async def big_decimal_operation( + self, + /, + *, + plugins: list[Plugin] | None = None, + **kwargs: Unpack[models.BigDecimalOperationInputDict], + ) -> models.BigDecimalOperationOutput: + """ + Invokes the BigDecimalOperation operation. + + :param plugins: Callables that change the configuration for this call + only. + """ + + async def big_decimal_operation( + self, /, *args: object, plugins: list[Plugin] | None = None, **kwargs: object + ) -> models.BigDecimalOperationOutput: + return await self._invoke( + self._select_input(models.BIG_DECIMAL_OPERATION, args, kwargs), + models.BIG_DECIMAL_OPERATION, + [], + plugins, + ) + + @overload + async def big_integer_operation( + self, + request: models.BigIntegerOperationInput | models.BigIntegerOperationInputDict, + /, + *, + plugins: list[Plugin] | None = None, + ) -> models.BigIntegerOperationOutput: ... + + @overload + async def big_integer_operation( + self, + /, + *, + plugins: list[Plugin] | None = None, + **kwargs: Unpack[models.BigIntegerOperationInputDict], + ) -> models.BigIntegerOperationOutput: + """ + Invokes the BigIntegerOperation operation. + + :param plugins: Callables that change the configuration for this call + only. + """ + + async def big_integer_operation( + self, /, *args: object, plugins: list[Plugin] | None = None, **kwargs: object + ) -> models.BigIntegerOperationOutput: + return await self._invoke( + self._select_input(models.BIG_INTEGER_OPERATION, args, kwargs), + models.BIG_INTEGER_OPERATION, + [], + plugins, + ) + + @overload + async def empty_input_output( + self, + request: models.EmptyInputOutputInput | models.EmptyInputOutputInputDict, + /, + *, + plugins: list[Plugin] | None = None, + ) -> models.EmptyInputOutputOutput: ... + + @overload + async def empty_input_output( + self, + /, + *, + plugins: list[Plugin] | None = None, + **kwargs: Unpack[models.EmptyInputOutputInputDict], + ) -> models.EmptyInputOutputOutput: + """ + Invokes the EmptyInputOutput operation. + + :param plugins: Callables that change the configuration for this call + only. + """ + + async def empty_input_output( + self, /, *args: object, plugins: list[Plugin] | None = None, **kwargs: object + ) -> models.EmptyInputOutputOutput: + return await self._invoke( + self._select_input(models.EMPTY_INPUT_OUTPUT, args, kwargs), + models.EMPTY_INPUT_OUTPUT, + [], + plugins, + ) + + @overload + async def fractional_seconds( + self, + request: models.FractionalSecondsInput | models.FractionalSecondsInputDict, + /, + *, + plugins: list[Plugin] | None = None, + ) -> models.FractionalSecondsOutput: ... + + @overload + async def fractional_seconds( + self, + /, + *, + plugins: list[Plugin] | None = None, + **kwargs: Unpack[models.FractionalSecondsInputDict], + ) -> models.FractionalSecondsOutput: + """ + Invokes the FractionalSeconds operation. + + :param plugins: Callables that change the configuration for this call + only. + """ + + async def fractional_seconds( + self, /, *args: object, plugins: list[Plugin] | None = None, **kwargs: object + ) -> models.FractionalSecondsOutput: + return await self._invoke( + self._select_input(models.FRACTIONAL_SECONDS, args, kwargs), + models.FRACTIONAL_SECONDS, + [], + plugins, + ) + + @overload + async def greeting_with_errors( + self, + request: models.GreetingWithErrorsInput | models.GreetingWithErrorsInputDict, + /, + *, + plugins: list[Plugin] | None = None, + ) -> models.GreetingWithErrorsOutput: ... + + @overload + async def greeting_with_errors( + self, + /, + *, + plugins: list[Plugin] | None = None, + **kwargs: Unpack[models.GreetingWithErrorsInputDict], + ) -> models.GreetingWithErrorsOutput: + """ + This operation has three possible return values: + + 1. A successful response in the form of GreetingWithErrorsOutput + 2. An InvalidGreeting error. + 3. A ComplexError error. + + Implementations must be able to successfully take a response and + properly deserialize successful and error responses. + + :param plugins: Callables that change the configuration for this call + only. + """ + + async def greeting_with_errors( + self, /, *args: object, plugins: list[Plugin] | None = None, **kwargs: object + ) -> models.GreetingWithErrorsOutput: + return await self._invoke( + self._select_input(models.GREETING_WITH_ERRORS, args, kwargs), + models.GREETING_WITH_ERRORS, + [], + plugins, + ) + + @overload + async def no_input_output( + self, + request: models.NoInputOutputInput | models.NoInputOutputInputDict, + /, + *, + plugins: list[Plugin] | None = None, + ) -> models.NoInputOutputOutput: ... + + @overload + async def no_input_output( + self, + /, + *, + plugins: list[Plugin] | None = None, + **kwargs: Unpack[models.NoInputOutputInputDict], + ) -> models.NoInputOutputOutput: + """ + Invokes the NoInputOutput operation. + + :param plugins: Callables that change the configuration for this call + only. + """ + + async def no_input_output( + self, /, *args: object, plugins: list[Plugin] | None = None, **kwargs: object + ) -> models.NoInputOutputOutput: + return await self._invoke( + self._select_input(models.NO_INPUT_OUTPUT, args, kwargs), + models.NO_INPUT_OUTPUT, + [], + plugins, + ) + + @overload + async def operation_with_defaults( + self, + request: models.OperationWithDefaultsInput + | models.OperationWithDefaultsInputDict, + /, + *, + plugins: list[Plugin] | None = None, + ) -> models.OperationWithDefaultsOutput: ... + + @overload + async def operation_with_defaults( + self, + /, + *, + plugins: list[Plugin] | None = None, + **kwargs: Unpack[models.OperationWithDefaultsInputDict], + ) -> models.OperationWithDefaultsOutput: + """ + Invokes the OperationWithDefaults operation. + + :param plugins: Callables that change the configuration for this call + only. + """ + + async def operation_with_defaults( + self, /, *args: object, plugins: list[Plugin] | None = None, **kwargs: object + ) -> models.OperationWithDefaultsOutput: + return await self._invoke( + self._select_input(models.OPERATION_WITH_DEFAULTS, args, kwargs), + models.OPERATION_WITH_DEFAULTS, + [], + plugins, + ) + + @overload + async def optional_input_output( + self, + request: models.OptionalInputOutputInput | models.OptionalInputOutputInputDict, + /, + *, + plugins: list[Plugin] | None = None, + ) -> models.OptionalInputOutputOutput: ... + + @overload + async def optional_input_output( + self, + /, + *, + plugins: list[Plugin] | None = None, + **kwargs: Unpack[models.OptionalInputOutputInputDict], + ) -> models.OptionalInputOutputOutput: + """ + Invokes the OptionalInputOutput operation. + + :param plugins: Callables that change the configuration for this call + only. + """ + + async def optional_input_output( + self, /, *args: object, plugins: list[Plugin] | None = None, **kwargs: object + ) -> models.OptionalInputOutputOutput: + return await self._invoke( + self._select_input(models.OPTIONAL_INPUT_OUTPUT, args, kwargs), + models.OPTIONAL_INPUT_OUTPUT, + [], + plugins, + ) + + @overload + async def recursive_shapes( + self, + request: models.RecursiveShapesInput | models.RecursiveShapesInputDict, + /, + *, + plugins: list[Plugin] | None = None, + ) -> models.RecursiveShapesOutput: ... + + @overload + async def recursive_shapes( + self, + /, + *, + plugins: list[Plugin] | None = None, + **kwargs: Unpack[models.RecursiveShapesInputDict], + ) -> models.RecursiveShapesOutput: + """ + Invokes the RecursiveShapes operation. + + :param plugins: Callables that change the configuration for this call + only. + """ + + async def recursive_shapes( + self, /, *args: object, plugins: list[Plugin] | None = None, **kwargs: object + ) -> models.RecursiveShapesOutput: + return await self._invoke( + self._select_input(models.RECURSIVE_SHAPES, args, kwargs), + models.RECURSIVE_SHAPES, + [], + plugins, + ) + + @overload + async def rpc_v2_json_dense_maps( + self, + request: models.RpcV2JsonDenseMapsInput | models.RpcV2JsonDenseMapsInputDict, + /, + *, + plugins: list[Plugin] | None = None, + ) -> models.RpcV2JsonDenseMapsOutput: ... + + @overload + async def rpc_v2_json_dense_maps( + self, + /, + *, + plugins: list[Plugin] | None = None, + **kwargs: Unpack[models.RpcV2JsonDenseMapsInputDict], + ) -> models.RpcV2JsonDenseMapsOutput: + """ + The example tests basic map serialization. + + :param plugins: Callables that change the configuration for this call + only. + """ + + async def rpc_v2_json_dense_maps( + self, /, *args: object, plugins: list[Plugin] | None = None, **kwargs: object + ) -> models.RpcV2JsonDenseMapsOutput: + return await self._invoke( + self._select_input(models.RPC_V2_JSON_DENSE_MAPS, args, kwargs), + models.RPC_V2_JSON_DENSE_MAPS, + [], + plugins, + ) + + @overload + async def rpc_v2_json_lists( + self, + request: models.RpcV2JsonListsInput | models.RpcV2JsonListsInputDict, + /, + *, + plugins: list[Plugin] | None = None, + ) -> models.RpcV2JsonListsOutput: ... + + @overload + async def rpc_v2_json_lists( + self, + /, + *, + plugins: list[Plugin] | None = None, + **kwargs: Unpack[models.RpcV2JsonListsInputDict], + ) -> models.RpcV2JsonListsOutput: + """ + This test case serializes JSON lists for the following cases for both + input and output: + + 1. Normal lists. + 2. Normal sets. + 3. Lists of lists. + 4. Lists of structures. + + :param plugins: Callables that change the configuration for this call + only. + """ + + async def rpc_v2_json_lists( + self, /, *args: object, plugins: list[Plugin] | None = None, **kwargs: object + ) -> models.RpcV2JsonListsOutput: + return await self._invoke( + self._select_input(models.RPC_V2_JSON_LISTS, args, kwargs), + models.RPC_V2_JSON_LISTS, + [], + plugins, + ) + + @overload + async def rpc_v2_json_sparse_maps( + self, + request: models.RpcV2JsonSparseMapsInput | models.RpcV2JsonSparseMapsInputDict, + /, + *, + plugins: list[Plugin] | None = None, + ) -> models.RpcV2JsonSparseMapsOutput: ... + + @overload + async def rpc_v2_json_sparse_maps( + self, + /, + *, + plugins: list[Plugin] | None = None, + **kwargs: Unpack[models.RpcV2JsonSparseMapsInputDict], + ) -> models.RpcV2JsonSparseMapsOutput: + """ + Invokes the RpcV2JsonSparseMaps operation. + + :param plugins: Callables that change the configuration for this call + only. + """ + + async def rpc_v2_json_sparse_maps( + self, /, *args: object, plugins: list[Plugin] | None = None, **kwargs: object + ) -> models.RpcV2JsonSparseMapsOutput: + return await self._invoke( + self._select_input(models.RPC_V2_JSON_SPARSE_MAPS, args, kwargs), + models.RPC_V2_JSON_SPARSE_MAPS, + [], + plugins, + ) + + @overload + async def simple_scalar_properties( + self, + request: models.SimpleScalarPropertiesInput + | models.SimpleScalarPropertiesInputDict, + /, + *, + plugins: list[Plugin] | None = None, + ) -> models.SimpleScalarPropertiesOutput: ... + + @overload + async def simple_scalar_properties( + self, + /, + *, + plugins: list[Plugin] | None = None, + **kwargs: Unpack[models.SimpleScalarPropertiesInputDict], + ) -> models.SimpleScalarPropertiesOutput: + """ + Invokes the SimpleScalarProperties operation. + + :param plugins: Callables that change the configuration for this call + only. + """ + + async def simple_scalar_properties( + self, /, *args: object, plugins: list[Plugin] | None = None, **kwargs: object + ) -> models.SimpleScalarPropertiesOutput: + return await self._invoke( + self._select_input(models.SIMPLE_SCALAR_PROPERTIES, args, kwargs), + models.SIMPLE_SCALAR_PROPERTIES, + [], + plugins, + ) + + @overload + async def sparse_nulls_operation( + self, + request: models.SparseNullsOperationInput + | models.SparseNullsOperationInputDict, + /, + *, + plugins: list[Plugin] | None = None, + ) -> models.SparseNullsOperationOutput: ... + + @overload + async def sparse_nulls_operation( + self, + /, + *, + plugins: list[Plugin] | None = None, + **kwargs: Unpack[models.SparseNullsOperationInputDict], + ) -> models.SparseNullsOperationOutput: + """ + Invokes the SparseNullsOperation operation. + + :param plugins: Callables that change the configuration for this call + only. + """ + + async def sparse_nulls_operation( + self, /, *args: object, plugins: list[Plugin] | None = None, **kwargs: object + ) -> models.SparseNullsOperationOutput: + return await self._invoke( + self._select_input(models.SPARSE_NULLS_OPERATION, args, kwargs), + models.SPARSE_NULLS_OPERATION, + [], + plugins, + ) + + @overload + async def timestamp_format_ignored( + self, + request: models.TimestampFormatIgnoredInput + | models.TimestampFormatIgnoredInputDict, + /, + *, + plugins: list[Plugin] | None = None, + ) -> models.TimestampFormatIgnoredOutput: ... + + @overload + async def timestamp_format_ignored( + self, + /, + *, + plugins: list[Plugin] | None = None, + **kwargs: Unpack[models.TimestampFormatIgnoredInputDict], + ) -> models.TimestampFormatIgnoredOutput: + """ + This operation tests that the rpcv2Json protocol always uses + epoch-seconds + for timestamp serialization, regardless of the `timestampFormat` trait. + Members targeting `DateTime` (date-time), `HttpDate` (http-date), and + `EpochSeconds` (epoch-seconds) must all serialize as JSON numbers. + + :param plugins: Callables that change the configuration for this call + only. + """ + + async def timestamp_format_ignored( + self, /, *args: object, plugins: list[Plugin] | None = None, **kwargs: object + ) -> models.TimestampFormatIgnoredOutput: + return await self._invoke( + self._select_input(models.TIMESTAMP_FORMAT_IGNORED, args, kwargs), + models.TIMESTAMP_FORMAT_IGNORED, + [], + plugins, + ) + + def _new_config(self) -> AsyncConfig: + return AsyncConfig() 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 new file mode 100644 index 000000000..852ffc4c6 --- /dev/null +++ b/codegen-output-py/rpcv2-json-client/src/rpcv2json_client/aio/config.py @@ -0,0 +1,91 @@ +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 StaticEndpointResolver +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 AsyncRpcV2JsonClientProtocol + +from rpcv2json_client._private.schemas import RPC_V2_JSON_PROTOCOL + +_PROTOCOL_SETTINGS = ProtocolSettings( + namespace="smithy.protocoltests.rpcv2Json", + service_target="RpcV2JsonProtocol", + version="2020-07-14", + service_schema=RPC_V2_JSON_PROTOCOL, +) + + +@dataclass(init=False) +class AsyncConfig: + "Configuration for AsyncRpcV2JsonProtocol." + + 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 static URI requests are sent to." + + 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." + + 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, + ) -> 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_uri = endpoint_uri + self.interceptors = interceptors or [] + if isinstance(protocol, type): + protocol = protocol(_PROTOCOL_SETTINGS) + self.protocol = cast( + ClientProtocol[Any, Any], protocol + ) or AsyncRpcV2JsonClientProtocol(_PROTOCOL_SETTINGS) + self.retry_strategy = retry_strategy + self.transport = transport or AIOHTTPClient() + + +type Plugin = Callable[[AsyncConfig], None] +"A callable that customizes the client configuration." diff --git a/codegen-output-py/rpcv2-json-client/src/rpcv2json_client/client.py b/codegen-output-py/rpcv2-json-client/src/rpcv2json_client/client.py new file mode 100644 index 000000000..f0477cbcd --- /dev/null +++ b/codegen-output-py/rpcv2-json-client/src/rpcv2json_client/client.py @@ -0,0 +1,549 @@ +from __future__ import annotations + +from typing import Unpack, overload + +from smithy_core.client import Client +from smithy_http.plugins import user_agent_plugin + +from rpcv2json_client import models +from rpcv2json_client.config import Config, Plugin + + +class RpcV2JsonProtocol(Client[Config]): + "Client for RpcV2JsonProtocol." + + _client_plugins = (user_agent_plugin,) + + @overload + def big_decimal_operation( + self, + request: models.BigDecimalOperationInput | models.BigDecimalOperationInputDict, + /, + *, + plugins: list[Plugin] | None = None, + ) -> models.BigDecimalOperationOutput: ... + + @overload + def big_decimal_operation( + self, + /, + *, + plugins: list[Plugin] | None = None, + **kwargs: Unpack[models.BigDecimalOperationInputDict], + ) -> models.BigDecimalOperationOutput: + """ + Invokes the BigDecimalOperation operation. + + :param plugins: Callables that change the configuration for this call + only. + """ + + def big_decimal_operation( + self, /, *args: object, plugins: list[Plugin] | None = None, **kwargs: object + ) -> models.BigDecimalOperationOutput: + return self._invoke( + self._select_input(models.BIG_DECIMAL_OPERATION, args, kwargs), + models.BIG_DECIMAL_OPERATION, + [], + plugins, + ) + + @overload + def big_integer_operation( + self, + request: models.BigIntegerOperationInput | models.BigIntegerOperationInputDict, + /, + *, + plugins: list[Plugin] | None = None, + ) -> models.BigIntegerOperationOutput: ... + + @overload + def big_integer_operation( + self, + /, + *, + plugins: list[Plugin] | None = None, + **kwargs: Unpack[models.BigIntegerOperationInputDict], + ) -> models.BigIntegerOperationOutput: + """ + Invokes the BigIntegerOperation operation. + + :param plugins: Callables that change the configuration for this call + only. + """ + + def big_integer_operation( + self, /, *args: object, plugins: list[Plugin] | None = None, **kwargs: object + ) -> models.BigIntegerOperationOutput: + return self._invoke( + self._select_input(models.BIG_INTEGER_OPERATION, args, kwargs), + models.BIG_INTEGER_OPERATION, + [], + plugins, + ) + + @overload + def empty_input_output( + self, + request: models.EmptyInputOutputInput | models.EmptyInputOutputInputDict, + /, + *, + plugins: list[Plugin] | None = None, + ) -> models.EmptyInputOutputOutput: ... + + @overload + def empty_input_output( + self, + /, + *, + plugins: list[Plugin] | None = None, + **kwargs: Unpack[models.EmptyInputOutputInputDict], + ) -> models.EmptyInputOutputOutput: + """ + Invokes the EmptyInputOutput operation. + + :param plugins: Callables that change the configuration for this call + only. + """ + + def empty_input_output( + self, /, *args: object, plugins: list[Plugin] | None = None, **kwargs: object + ) -> models.EmptyInputOutputOutput: + return self._invoke( + self._select_input(models.EMPTY_INPUT_OUTPUT, args, kwargs), + models.EMPTY_INPUT_OUTPUT, + [], + plugins, + ) + + @overload + def fractional_seconds( + self, + request: models.FractionalSecondsInput | models.FractionalSecondsInputDict, + /, + *, + plugins: list[Plugin] | None = None, + ) -> models.FractionalSecondsOutput: ... + + @overload + def fractional_seconds( + self, + /, + *, + plugins: list[Plugin] | None = None, + **kwargs: Unpack[models.FractionalSecondsInputDict], + ) -> models.FractionalSecondsOutput: + """ + Invokes the FractionalSeconds operation. + + :param plugins: Callables that change the configuration for this call + only. + """ + + def fractional_seconds( + self, /, *args: object, plugins: list[Plugin] | None = None, **kwargs: object + ) -> models.FractionalSecondsOutput: + return self._invoke( + self._select_input(models.FRACTIONAL_SECONDS, args, kwargs), + models.FRACTIONAL_SECONDS, + [], + plugins, + ) + + @overload + def greeting_with_errors( + self, + request: models.GreetingWithErrorsInput | models.GreetingWithErrorsInputDict, + /, + *, + plugins: list[Plugin] | None = None, + ) -> models.GreetingWithErrorsOutput: ... + + @overload + def greeting_with_errors( + self, + /, + *, + plugins: list[Plugin] | None = None, + **kwargs: Unpack[models.GreetingWithErrorsInputDict], + ) -> models.GreetingWithErrorsOutput: + """ + This operation has three possible return values: + + 1. A successful response in the form of GreetingWithErrorsOutput + 2. An InvalidGreeting error. + 3. A ComplexError error. + + Implementations must be able to successfully take a response and + properly deserialize successful and error responses. + + :param plugins: Callables that change the configuration for this call + only. + """ + + def greeting_with_errors( + self, /, *args: object, plugins: list[Plugin] | None = None, **kwargs: object + ) -> models.GreetingWithErrorsOutput: + return self._invoke( + self._select_input(models.GREETING_WITH_ERRORS, args, kwargs), + models.GREETING_WITH_ERRORS, + [], + plugins, + ) + + @overload + def no_input_output( + self, + request: models.NoInputOutputInput | models.NoInputOutputInputDict, + /, + *, + plugins: list[Plugin] | None = None, + ) -> models.NoInputOutputOutput: ... + + @overload + def no_input_output( + self, + /, + *, + plugins: list[Plugin] | None = None, + **kwargs: Unpack[models.NoInputOutputInputDict], + ) -> models.NoInputOutputOutput: + """ + Invokes the NoInputOutput operation. + + :param plugins: Callables that change the configuration for this call + only. + """ + + def no_input_output( + self, /, *args: object, plugins: list[Plugin] | None = None, **kwargs: object + ) -> models.NoInputOutputOutput: + return self._invoke( + self._select_input(models.NO_INPUT_OUTPUT, args, kwargs), + models.NO_INPUT_OUTPUT, + [], + plugins, + ) + + @overload + def operation_with_defaults( + self, + request: models.OperationWithDefaultsInput + | models.OperationWithDefaultsInputDict, + /, + *, + plugins: list[Plugin] | None = None, + ) -> models.OperationWithDefaultsOutput: ... + + @overload + def operation_with_defaults( + self, + /, + *, + plugins: list[Plugin] | None = None, + **kwargs: Unpack[models.OperationWithDefaultsInputDict], + ) -> models.OperationWithDefaultsOutput: + """ + Invokes the OperationWithDefaults operation. + + :param plugins: Callables that change the configuration for this call + only. + """ + + def operation_with_defaults( + self, /, *args: object, plugins: list[Plugin] | None = None, **kwargs: object + ) -> models.OperationWithDefaultsOutput: + return self._invoke( + self._select_input(models.OPERATION_WITH_DEFAULTS, args, kwargs), + models.OPERATION_WITH_DEFAULTS, + [], + plugins, + ) + + @overload + def optional_input_output( + self, + request: models.OptionalInputOutputInput | models.OptionalInputOutputInputDict, + /, + *, + plugins: list[Plugin] | None = None, + ) -> models.OptionalInputOutputOutput: ... + + @overload + def optional_input_output( + self, + /, + *, + plugins: list[Plugin] | None = None, + **kwargs: Unpack[models.OptionalInputOutputInputDict], + ) -> models.OptionalInputOutputOutput: + """ + Invokes the OptionalInputOutput operation. + + :param plugins: Callables that change the configuration for this call + only. + """ + + def optional_input_output( + self, /, *args: object, plugins: list[Plugin] | None = None, **kwargs: object + ) -> models.OptionalInputOutputOutput: + return self._invoke( + self._select_input(models.OPTIONAL_INPUT_OUTPUT, args, kwargs), + models.OPTIONAL_INPUT_OUTPUT, + [], + plugins, + ) + + @overload + def recursive_shapes( + self, + request: models.RecursiveShapesInput | models.RecursiveShapesInputDict, + /, + *, + plugins: list[Plugin] | None = None, + ) -> models.RecursiveShapesOutput: ... + + @overload + def recursive_shapes( + self, + /, + *, + plugins: list[Plugin] | None = None, + **kwargs: Unpack[models.RecursiveShapesInputDict], + ) -> models.RecursiveShapesOutput: + """ + Invokes the RecursiveShapes operation. + + :param plugins: Callables that change the configuration for this call + only. + """ + + def recursive_shapes( + self, /, *args: object, plugins: list[Plugin] | None = None, **kwargs: object + ) -> models.RecursiveShapesOutput: + return self._invoke( + self._select_input(models.RECURSIVE_SHAPES, args, kwargs), + models.RECURSIVE_SHAPES, + [], + plugins, + ) + + @overload + def rpc_v2_json_dense_maps( + self, + request: models.RpcV2JsonDenseMapsInput | models.RpcV2JsonDenseMapsInputDict, + /, + *, + plugins: list[Plugin] | None = None, + ) -> models.RpcV2JsonDenseMapsOutput: ... + + @overload + def rpc_v2_json_dense_maps( + self, + /, + *, + plugins: list[Plugin] | None = None, + **kwargs: Unpack[models.RpcV2JsonDenseMapsInputDict], + ) -> models.RpcV2JsonDenseMapsOutput: + """ + The example tests basic map serialization. + + :param plugins: Callables that change the configuration for this call + only. + """ + + def rpc_v2_json_dense_maps( + self, /, *args: object, plugins: list[Plugin] | None = None, **kwargs: object + ) -> models.RpcV2JsonDenseMapsOutput: + return self._invoke( + self._select_input(models.RPC_V2_JSON_DENSE_MAPS, args, kwargs), + models.RPC_V2_JSON_DENSE_MAPS, + [], + plugins, + ) + + @overload + def rpc_v2_json_lists( + self, + request: models.RpcV2JsonListsInput | models.RpcV2JsonListsInputDict, + /, + *, + plugins: list[Plugin] | None = None, + ) -> models.RpcV2JsonListsOutput: ... + + @overload + def rpc_v2_json_lists( + self, + /, + *, + plugins: list[Plugin] | None = None, + **kwargs: Unpack[models.RpcV2JsonListsInputDict], + ) -> models.RpcV2JsonListsOutput: + """ + This test case serializes JSON lists for the following cases for both + input and output: + + 1. Normal lists. + 2. Normal sets. + 3. Lists of lists. + 4. Lists of structures. + + :param plugins: Callables that change the configuration for this call + only. + """ + + def rpc_v2_json_lists( + self, /, *args: object, plugins: list[Plugin] | None = None, **kwargs: object + ) -> models.RpcV2JsonListsOutput: + return self._invoke( + self._select_input(models.RPC_V2_JSON_LISTS, args, kwargs), + models.RPC_V2_JSON_LISTS, + [], + plugins, + ) + + @overload + def rpc_v2_json_sparse_maps( + self, + request: models.RpcV2JsonSparseMapsInput | models.RpcV2JsonSparseMapsInputDict, + /, + *, + plugins: list[Plugin] | None = None, + ) -> models.RpcV2JsonSparseMapsOutput: ... + + @overload + def rpc_v2_json_sparse_maps( + self, + /, + *, + plugins: list[Plugin] | None = None, + **kwargs: Unpack[models.RpcV2JsonSparseMapsInputDict], + ) -> models.RpcV2JsonSparseMapsOutput: + """ + Invokes the RpcV2JsonSparseMaps operation. + + :param plugins: Callables that change the configuration for this call + only. + """ + + def rpc_v2_json_sparse_maps( + self, /, *args: object, plugins: list[Plugin] | None = None, **kwargs: object + ) -> models.RpcV2JsonSparseMapsOutput: + return self._invoke( + self._select_input(models.RPC_V2_JSON_SPARSE_MAPS, args, kwargs), + models.RPC_V2_JSON_SPARSE_MAPS, + [], + plugins, + ) + + @overload + def simple_scalar_properties( + self, + request: models.SimpleScalarPropertiesInput + | models.SimpleScalarPropertiesInputDict, + /, + *, + plugins: list[Plugin] | None = None, + ) -> models.SimpleScalarPropertiesOutput: ... + + @overload + def simple_scalar_properties( + self, + /, + *, + plugins: list[Plugin] | None = None, + **kwargs: Unpack[models.SimpleScalarPropertiesInputDict], + ) -> models.SimpleScalarPropertiesOutput: + """ + Invokes the SimpleScalarProperties operation. + + :param plugins: Callables that change the configuration for this call + only. + """ + + def simple_scalar_properties( + self, /, *args: object, plugins: list[Plugin] | None = None, **kwargs: object + ) -> models.SimpleScalarPropertiesOutput: + return self._invoke( + self._select_input(models.SIMPLE_SCALAR_PROPERTIES, args, kwargs), + models.SIMPLE_SCALAR_PROPERTIES, + [], + plugins, + ) + + @overload + def sparse_nulls_operation( + self, + request: models.SparseNullsOperationInput + | models.SparseNullsOperationInputDict, + /, + *, + plugins: list[Plugin] | None = None, + ) -> models.SparseNullsOperationOutput: ... + + @overload + def sparse_nulls_operation( + self, + /, + *, + plugins: list[Plugin] | None = None, + **kwargs: Unpack[models.SparseNullsOperationInputDict], + ) -> models.SparseNullsOperationOutput: + """ + Invokes the SparseNullsOperation operation. + + :param plugins: Callables that change the configuration for this call + only. + """ + + def sparse_nulls_operation( + self, /, *args: object, plugins: list[Plugin] | None = None, **kwargs: object + ) -> models.SparseNullsOperationOutput: + return self._invoke( + self._select_input(models.SPARSE_NULLS_OPERATION, args, kwargs), + models.SPARSE_NULLS_OPERATION, + [], + plugins, + ) + + @overload + def timestamp_format_ignored( + self, + request: models.TimestampFormatIgnoredInput + | models.TimestampFormatIgnoredInputDict, + /, + *, + plugins: list[Plugin] | None = None, + ) -> models.TimestampFormatIgnoredOutput: ... + + @overload + def timestamp_format_ignored( + self, + /, + *, + plugins: list[Plugin] | None = None, + **kwargs: Unpack[models.TimestampFormatIgnoredInputDict], + ) -> models.TimestampFormatIgnoredOutput: + """ + This operation tests that the rpcv2Json protocol always uses + epoch-seconds + for timestamp serialization, regardless of the `timestampFormat` trait. + Members targeting `DateTime` (date-time), `HttpDate` (http-date), and + `EpochSeconds` (epoch-seconds) must all serialize as JSON numbers. + + :param plugins: Callables that change the configuration for this call + only. + """ + + def timestamp_format_ignored( + self, /, *args: object, plugins: list[Plugin] | None = None, **kwargs: object + ) -> models.TimestampFormatIgnoredOutput: + return self._invoke( + self._select_input(models.TIMESTAMP_FORMAT_IGNORED, args, kwargs), + models.TIMESTAMP_FORMAT_IGNORED, + [], + plugins, + ) + + def _new_config(self) -> Config: + return Config() 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 new file mode 100644 index 000000000..503f13b56 --- /dev/null +++ b/codegen-output-py/rpcv2-json-client/src/rpcv2json_client/config.py @@ -0,0 +1,90 @@ +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 StaticEndpointResolver +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 RpcV2JsonClientProtocol +from smithy_http.urllib3 import Urllib3HTTPClient + +from rpcv2json_client._private.schemas import RPC_V2_JSON_PROTOCOL + +_PROTOCOL_SETTINGS = ProtocolSettings( + namespace="smithy.protocoltests.rpcv2Json", + service_target="RpcV2JsonProtocol", + version="2020-07-14", + service_schema=RPC_V2_JSON_PROTOCOL, +) + + +@dataclass(init=False) +class Config: + "Configuration for RpcV2JsonProtocol." + + 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 static URI requests are sent to." + + 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." + + 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, + ) -> 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_uri = endpoint_uri + self.interceptors = interceptors or [] + if isinstance(protocol, type): + protocol = protocol(_PROTOCOL_SETTINGS) + self.protocol = cast( + ClientProtocol[Any, Any], protocol + ) or RpcV2JsonClientProtocol(_PROTOCOL_SETTINGS) + self.retry_strategy = retry_strategy + self.transport = transport or Urllib3HTTPClient() + + +type Plugin = Callable[[Config], None] +"A callable that customizes the client configuration." diff --git a/codegen-output-py/rpcv2-json-client/src/rpcv2json_client/models.py b/codegen-output-py/rpcv2-json-client/src/rpcv2json_client/models.py new file mode 100644 index 000000000..027b7523a --- /dev/null +++ b/codegen-output-py/rpcv2-json-client/src/rpcv2json_client/models.py @@ -0,0 +1,206 @@ +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 = { + "ValidationException": "VALIDATION_EXCEPTION", + "ValidationExceptionField": "VALIDATION_EXCEPTION_FIELD", + "ClientOptionalDefaults": "CLIENT_OPTIONAL_DEFAULTS", + "ComplexError": "COMPLEX_ERROR", + "ComplexNestedErrorData": "COMPLEX_NESTED_ERROR_DATA", + "Defaults": "DEFAULTS", + "FractionalSecondsOutput": "FRACTIONAL_SECONDS_OUTPUT", + "GreetingWithErrorsOutput": "GREETING_WITH_ERRORS_OUTPUT", + "InvalidGreeting": "INVALID_GREETING", + "OperationWithDefaultsInput": "OPERATION_WITH_DEFAULTS_INPUT", + "OperationWithDefaultsOutput": "OPERATION_WITH_DEFAULTS_OUTPUT", + "RecursiveShapesInputOutputNested1": "RECURSIVE_SHAPES_INPUT_OUTPUT_NESTED1", + "RecursiveShapesInputOutputNested2": "RECURSIVE_SHAPES_INPUT_OUTPUT_NESTED2", + "StructureListMember": "STRUCTURE_LIST_MEMBER", + "TestEnum": "TEST_ENUM", + "TestIntEnum": "TEST_INT_ENUM", + "FooEnum": "FOO_ENUM", + "GreetingStruct": "GREETING_STRUCT", + "IntegerEnum": "INTEGER_ENUM", + "BigDecimalOperationInput": "BIG_DECIMAL_OPERATION_INPUT", + "BigDecimalOperationOutput": "BIG_DECIMAL_OPERATION_OUTPUT", + "BigIntegerOperationInput": "BIG_INTEGER_OPERATION_INPUT", + "BigIntegerOperationOutput": "BIG_INTEGER_OPERATION_OUTPUT", + "EmptyInputOutputInput": "EMPTY_INPUT_OUTPUT_INPUT", + "EmptyInputOutputOutput": "EMPTY_INPUT_OUTPUT_OUTPUT", + "FractionalSecondsInput": "FRACTIONAL_SECONDS_INPUT", + "GreetingWithErrorsInput": "GREETING_WITH_ERRORS_INPUT", + "NoInputOutputInput": "NO_INPUT_OUTPUT_INPUT", + "NoInputOutputOutput": "NO_INPUT_OUTPUT_OUTPUT", + "OptionalInputOutputInput": "OPTIONAL_INPUT_OUTPUT_INPUT", + "OptionalInputOutputOutput": "OPTIONAL_INPUT_OUTPUT_OUTPUT", + "RecursiveShapesInput": "RECURSIVE_SHAPES_INPUT", + "RecursiveShapesOutput": "RECURSIVE_SHAPES_OUTPUT", + "RpcV2JsonDenseMapsInput": "RPC_V2_JSON_DENSE_MAPS_INPUT", + "RpcV2JsonDenseMapsOutput": "RPC_V2_JSON_DENSE_MAPS_OUTPUT", + "RpcV2JsonListsInput": "RPC_V2_JSON_LISTS_INPUT", + "RpcV2JsonListsOutput": "RPC_V2_JSON_LISTS_OUTPUT", + "RpcV2JsonSparseMapsInput": "RPC_V2_JSON_SPARSE_MAPS_INPUT", + "RpcV2JsonSparseMapsOutput": "RPC_V2_JSON_SPARSE_MAPS_OUTPUT", + "SimpleScalarPropertiesInput": "SIMPLE_SCALAR_PROPERTIES_INPUT", + "SimpleScalarPropertiesOutput": "SIMPLE_SCALAR_PROPERTIES_OUTPUT", + "SparseNullsOperationInput": "SPARSE_NULLS_OPERATION_INPUT", + "SparseNullsOperationOutput": "SPARSE_NULLS_OPERATION_OUTPUT", + "TimestampFormatIgnoredInput": "TIMESTAMP_FORMAT_IGNORED_INPUT", + "TimestampFormatIgnoredOutput": "TIMESTAMP_FORMAT_IGNORED_OUTPUT", +} + +_RENAMES: dict[str, str] = {} + +_TARGET_NAMES: dict[str, str] = {} + +_OPERATIONS: dict[str, tuple[tuple[str, ...], tuple[str, ...]]] = { + "BIG_DECIMAL_OPERATION": ( + (), + ("smithy.api#noAuth",), + ), + "BIG_INTEGER_OPERATION": ( + (), + ("smithy.api#noAuth",), + ), + "EMPTY_INPUT_OUTPUT": ( + (), + ("smithy.api#noAuth",), + ), + "FRACTIONAL_SECONDS": ( + (), + ("smithy.api#noAuth",), + ), + "GREETING_WITH_ERRORS": ( + ( + "smithy.protocoltests.rpcv2Json#ComplexError", + "smithy.protocoltests.rpcv2Json#InvalidGreeting", + ), + ("smithy.api#noAuth",), + ), + "NO_INPUT_OUTPUT": ( + (), + ("smithy.api#noAuth",), + ), + "OPERATION_WITH_DEFAULTS": ( + ("smithy.framework#ValidationException",), + ("smithy.api#noAuth",), + ), + "OPTIONAL_INPUT_OUTPUT": ( + (), + ("smithy.api#noAuth",), + ), + "RECURSIVE_SHAPES": ( + (), + ("smithy.api#noAuth",), + ), + "RPC_V2_JSON_DENSE_MAPS": ( + ("smithy.framework#ValidationException",), + ("smithy.api#noAuth",), + ), + "RPC_V2_JSON_LISTS": ( + ("smithy.framework#ValidationException",), + ("smithy.api#noAuth",), + ), + "RPC_V2_JSON_SPARSE_MAPS": ( + ("smithy.framework#ValidationException",), + ("smithy.api#noAuth",), + ), + "SIMPLE_SCALAR_PROPERTIES": ( + (), + ("smithy.api#noAuth",), + ), + "SPARSE_NULLS_OPERATION": ( + (), + ("smithy.api#noAuth",), + ), + "TIMESTAMP_FORMAT_IGNORED": ( + (), + ("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( + { + "BigDecimalOperationInput", + "BigDecimalOperationOutput", + "BigIntegerOperationInput", + "BigIntegerOperationOutput", + "ClientOptionalDefaults", + "ComplexError", + "ComplexNestedErrorData", + "Defaults", + "EmptyInputOutputInput", + "EmptyInputOutputOutput", + "FooEnum", + "FractionalSecondsInput", + "FractionalSecondsOutput", + "GreetingStruct", + "GreetingWithErrorsInput", + "GreetingWithErrorsOutput", + "IntegerEnum", + "InvalidGreeting", + "NoInputOutputInput", + "NoInputOutputOutput", + "OperationWithDefaultsInput", + "OperationWithDefaultsOutput", + "OptionalInputOutputInput", + "OptionalInputOutputOutput", + "RecursiveShapesInput", + "RecursiveShapesInputOutputNested1", + "RecursiveShapesInputOutputNested2", + "RecursiveShapesOutput", + "RpcV2JsonDenseMapsInput", + "RpcV2JsonDenseMapsOutput", + "RpcV2JsonListsInput", + "RpcV2JsonListsOutput", + "RpcV2JsonSparseMapsInput", + "RpcV2JsonSparseMapsOutput", + "SimpleScalarPropertiesInput", + "SimpleScalarPropertiesOutput", + "SparseNullsOperationInput", + "SparseNullsOperationOutput", + "StructureListMember", + "TestEnum", + "TestIntEnum", + "TimestampFormatIgnoredInput", + "TimestampFormatIgnoredOutput", + "ValidationException", + "ValidationExceptionField", + } + ), + 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/rpcv2-json-client/src/rpcv2json_client/models.pyi b/codegen-output-py/rpcv2-json-client/src/rpcv2json_client/models.pyi new file mode 100644 index 000000000..354b379af --- /dev/null +++ b/codegen-output-py/rpcv2-json-client/src/rpcv2json_client/models.pyi @@ -0,0 +1,804 @@ +from collections.abc import Mapping, Sequence +from dataclasses import dataclass +from datetime import datetime +from decimal import Decimal +from enum import IntEnum, StrEnum +from typing import 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 +from smithy_core.types import UnknownEnumMixin + +__all__ = [ + "BIG_DECIMAL_OPERATION", + "BIG_INTEGER_OPERATION", + "EMPTY_INPUT_OUTPUT", + "FRACTIONAL_SECONDS", + "GREETING_WITH_ERRORS", + "NO_INPUT_OUTPUT", + "OPERATION_WITH_DEFAULTS", + "OPTIONAL_INPUT_OUTPUT", + "RECURSIVE_SHAPES", + "RPC_V2_JSON_DENSE_MAPS", + "RPC_V2_JSON_LISTS", + "RPC_V2_JSON_SPARSE_MAPS", + "SIMPLE_SCALAR_PROPERTIES", + "SPARSE_NULLS_OPERATION", + "TIMESTAMP_FORMAT_IGNORED", + "BigDecimalOperationInput", + "BigDecimalOperationOutput", + "BigIntegerOperationInput", + "BigIntegerOperationOutput", + "ClientOptionalDefaults", + "ComplexError", + "ComplexNestedErrorData", + "Defaults", + "EmptyInputOutputInput", + "EmptyInputOutputOutput", + "FooEnum", + "FractionalSecondsInput", + "FractionalSecondsOutput", + "GreetingStruct", + "GreetingWithErrorsInput", + "GreetingWithErrorsOutput", + "IntegerEnum", + "InvalidGreeting", + "NoInputOutputInput", + "NoInputOutputOutput", + "OperationWithDefaultsInput", + "OperationWithDefaultsOutput", + "OptionalInputOutputInput", + "OptionalInputOutputOutput", + "RecursiveShapesInput", + "RecursiveShapesInputOutputNested1", + "RecursiveShapesInputOutputNested2", + "RecursiveShapesOutput", + "RpcV2JsonDenseMapsInput", + "RpcV2JsonDenseMapsOutput", + "RpcV2JsonListsInput", + "RpcV2JsonListsOutput", + "RpcV2JsonSparseMapsInput", + "RpcV2JsonSparseMapsOutput", + "ServiceError", + "SimpleScalarPropertiesInput", + "SimpleScalarPropertiesOutput", + "SparseNullsOperationInput", + "SparseNullsOperationOutput", + "StructureListMember", + "TestEnum", + "TestIntEnum", + "TimestampFormatIgnoredInput", + "TimestampFormatIgnoredOutput", + "ValidationException", + "ValidationExceptionField", +] + +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 ValidationException(ServiceError, _SerdeShape): + """ + A standard error for input validation failures. + This should be thrown by services when a member of the input structure + falls outside of the modeled or documented constraints. + """ + + field_list: list[ValidationExceptionField] | None = ... + """ + A list of specific failures encountered while validating the input. + A member can appear in this list more than once if it failed to satisfy + multiple constraints. + """ + 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 ValidationExceptionField(_SerdeShape): + "Describes one specific validation failure for an input member." + + path: str + """ + A JSONPointer expression to the structure member whose value failed to + satisfy the modeled constraints. + """ + message: str + "A detailed description of the validation failure." + +@dataclass(kw_only=True) +class ClientOptionalDefaults(_SerdeShape): + "Dataclass for ClientOptionalDefaults structure." + + member: int | None = ... + +class ClientOptionalDefaultsDict(TypedDict, total=False): + "Dictionary form of `ClientOptionalDefaults`." + + member: int | None + +@dataclass(kw_only=True) +class ComplexError(ServiceError, _SerdeShape): + "This error is thrown when a request is invalid." + + top_level: str | None = ... + nested: ComplexNestedErrorData | None = ... + 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 ComplexNestedErrorData(_SerdeShape): + "Dataclass for ComplexNestedErrorData structure." + + foo: str | None = ... + +@dataclass(kw_only=True) +class Defaults(_SerdeShape): + "Dataclass for Defaults structure." + + default_string: str | None = ... + default_boolean: bool | None = ... + default_list: list[str] | None = ... + default_timestamp: datetime | None = ... + default_blob: bytes | None = ... + default_byte: int | None = ... + default_short: int | None = ... + default_integer: int | None = ... + default_long: int | None = ... + default_float: float | None = ... + default_double: float | None = ... + default_map: dict[str, str] | None = ... + default_enum: str | None = ... + default_int_enum: int | None = ... + empty_string: str | None = ... + false_boolean: bool | None = ... + empty_blob: bytes | None = ... + zero_byte: int | None = ... + zero_short: int | None = ... + zero_integer: int | None = ... + zero_long: int | None = ... + zero_float: float | None = ... + zero_double: float | None = ... + +class DefaultsDict(TypedDict, total=False): + "Dictionary form of `Defaults`." + + default_string: str | None + default_boolean: bool | None + default_list: Sequence[str] | None + default_timestamp: datetime | None + default_blob: bytes | None + default_byte: int | None + default_short: int | None + default_integer: int | None + default_long: int | None + default_float: float | None + default_double: float | None + default_map: Mapping[str, str] | None + default_enum: str | None + default_int_enum: int | None + empty_string: str | None + false_boolean: bool | None + empty_blob: bytes | None + zero_byte: int | None + zero_short: int | None + zero_integer: int | None + zero_long: int | None + zero_float: float | None + zero_double: float | None + +@dataclass(kw_only=True) +class FractionalSecondsOutput(_SerdeShape): + "Dataclass for FractionalSecondsOutput structure." + + datetime_: datetime | None = ... + 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 GreetingWithErrorsOutput(_SerdeShape): + "Dataclass for GreetingWithErrorsOutput structure." + + greeting: str | None = ... + 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 InvalidGreeting(ServiceError, _SerdeShape): + "This error is thrown when an invalid greeting value is provided." + + 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 OperationWithDefaultsInput(_SerdeShape): + "Dataclass for OperationWithDefaultsInput structure." + + defaults: Defaults | None = ... + client_optional_defaults: ClientOptionalDefaults | None = ... + top_level_default: str | None = ... + other_top_level_default: int | None = ... + +class OperationWithDefaultsInputDict(TypedDict, total=False): + "Dictionary form of `OperationWithDefaultsInput`." + + defaults: Defaults | DefaultsDict | None + client_optional_defaults: ClientOptionalDefaults | ClientOptionalDefaultsDict | None + top_level_default: str | None + other_top_level_default: int | None + +@dataclass(kw_only=True) +class OperationWithDefaultsOutput(_SerdeShape): + "Dataclass for OperationWithDefaultsOutput structure." + + default_string: str | None = ... + default_boolean: bool | None = ... + default_list: list[str] | None = ... + default_timestamp: datetime | None = ... + default_blob: bytes | None = ... + default_byte: int | None = ... + default_short: int | None = ... + default_integer: int | None = ... + default_long: int | None = ... + default_float: float | None = ... + default_double: float | None = ... + default_map: dict[str, str] | None = ... + default_enum: str | None = ... + default_int_enum: int | None = ... + empty_string: str | None = ... + false_boolean: bool | None = ... + empty_blob: bytes | None = ... + zero_byte: int | None = ... + zero_short: int | None = ... + zero_integer: int | None = ... + zero_long: int | None = ... + zero_float: float | None = ... + zero_double: float | None = ... + 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 RecursiveShapesInputOutputNested1(_SerdeShape): + "Dataclass for RecursiveShapesInputOutputNested1 structure." + + foo: str | None = ... + nested: RecursiveShapesInputOutputNested2 | None = ... + +class RecursiveShapesInputOutputNested1Dict(TypedDict, total=False): + "Dictionary form of `RecursiveShapesInputOutputNested1`." + + foo: str | None + nested: ( + RecursiveShapesInputOutputNested2 | RecursiveShapesInputOutputNested2Dict | None + ) + +@dataclass(kw_only=True) +class RecursiveShapesInputOutputNested2(_SerdeShape): + "Dataclass for RecursiveShapesInputOutputNested2 structure." + + bar: str | None = ... + recursive_member: RecursiveShapesInputOutputNested1 | None = ... + +class RecursiveShapesInputOutputNested2Dict(TypedDict, total=False): + "Dictionary form of `RecursiveShapesInputOutputNested2`." + + bar: str | None + recursive_member: ( + RecursiveShapesInputOutputNested1 | RecursiveShapesInputOutputNested1Dict | None + ) + +@dataclass(kw_only=True) +class StructureListMember(_SerdeShape): + "Dataclass for StructureListMember structure." + + a: str | None = ... + b: str | None = ... + +class StructureListMemberDict(TypedDict, total=False): + "Dictionary form of `StructureListMember`." + + a: str | None + b: str | None + +class TestEnum(UnknownEnumMixin, StrEnum): + FOO = "FOO" + BAR = "BAR" + BAZ = "BAZ" + +class TestIntEnum(UnknownEnumMixin, IntEnum): + ONE = 1 + TWO = 2 + +class FooEnum(UnknownEnumMixin, StrEnum): + FOO = "Foo" + BAZ = "Baz" + BAR = "Bar" + ONE = "1" + ZERO = "0" + +@dataclass(kw_only=True) +class GreetingStruct(_SerdeShape): + "Dataclass for GreetingStruct structure." + + hi: str | None = ... + +class GreetingStructDict(TypedDict, total=False): + "Dictionary form of `GreetingStruct`." + + hi: str | None + +class IntegerEnum(UnknownEnumMixin, IntEnum): + A = 1 + B = 2 + C = 3 + +@dataclass(kw_only=True) +class BigDecimalOperationInput(_SerdeShape): + "Dataclass for BigDecimalOperationInput structure." + + value: Decimal | None = ... + +class BigDecimalOperationInputDict(TypedDict, total=False): + "Dictionary form of `BigDecimalOperationInput`." + + value: Decimal | None + +@dataclass(kw_only=True) +class BigDecimalOperationOutput(_SerdeShape): + "Dataclass for BigDecimalOperationOutput structure." + + value: Decimal | None = ... + 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 BigIntegerOperationInput(_SerdeShape): + "Dataclass for BigIntegerOperationInput structure." + + value: int | None = ... + +class BigIntegerOperationInputDict(TypedDict, total=False): + "Dictionary form of `BigIntegerOperationInput`." + + value: int | None + +@dataclass(kw_only=True) +class BigIntegerOperationOutput(_SerdeShape): + "Dataclass for BigIntegerOperationOutput structure." + + value: int | None = ... + 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 EmptyInputOutputInput(_SerdeShape): + "Dataclass for EmptyInputOutputInput structure." + +class EmptyInputOutputInputDict(TypedDict, total=False): + "Dictionary form of `EmptyInputOutputInput`." + +@dataclass(kw_only=True) +class EmptyInputOutputOutput(_SerdeShape): + "Dataclass for EmptyInputOutputOutput 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 FractionalSecondsInput(_SerdeShape): + "Dataclass for FractionalSecondsInput structure." + +class FractionalSecondsInputDict(TypedDict, total=False): + "Dictionary form of `FractionalSecondsInput`." + +@dataclass(kw_only=True) +class GreetingWithErrorsInput(_SerdeShape): + "Dataclass for GreetingWithErrorsInput structure." + +class GreetingWithErrorsInputDict(TypedDict, total=False): + "Dictionary form of `GreetingWithErrorsInput`." + +@dataclass(kw_only=True) +class NoInputOutputInput(_SerdeShape): + "Dataclass for NoInputOutputInput structure." + +class NoInputOutputInputDict(TypedDict, total=False): + "Dictionary form of `NoInputOutputInput`." + +@dataclass(kw_only=True) +class NoInputOutputOutput(_SerdeShape): + "Dataclass for NoInputOutputOutput 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 OptionalInputOutputInput(_SerdeShape): + "Dataclass for OptionalInputOutputInput structure." + + value: str | None = ... + +class OptionalInputOutputInputDict(TypedDict, total=False): + "Dictionary form of `OptionalInputOutputInput`." + + value: str | None + +@dataclass(kw_only=True) +class OptionalInputOutputOutput(_SerdeShape): + "Dataclass for OptionalInputOutputOutput structure." + + value: str | None = ... + 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 RecursiveShapesInput(_SerdeShape): + "Dataclass for RecursiveShapesInput structure." + + nested: RecursiveShapesInputOutputNested1 | None = ... + +class RecursiveShapesInputDict(TypedDict, total=False): + "Dictionary form of `RecursiveShapesInput`." + + nested: ( + RecursiveShapesInputOutputNested1 | RecursiveShapesInputOutputNested1Dict | None + ) + +@dataclass(kw_only=True) +class RecursiveShapesOutput(_SerdeShape): + "Dataclass for RecursiveShapesOutput structure." + + nested: RecursiveShapesInputOutputNested1 | None = ... + 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 RpcV2JsonDenseMapsInput(_SerdeShape): + "Dataclass for RpcV2JsonDenseMapsInput structure." + + dense_struct_map: dict[str, GreetingStruct] | None = ... + dense_number_map: dict[str, int] | None = ... + dense_boolean_map: dict[str, bool] | None = ... + dense_string_map: dict[str, str] | None = ... + dense_set_map: dict[str, list[str]] | None = ... + +class RpcV2JsonDenseMapsInputDict(TypedDict, total=False): + "Dictionary form of `RpcV2JsonDenseMapsInput`." + + dense_struct_map: Mapping[str, GreetingStruct | GreetingStructDict] | None + dense_number_map: Mapping[str, int] | None + dense_boolean_map: Mapping[str, bool] | None + dense_string_map: Mapping[str, str] | None + dense_set_map: Mapping[str, Sequence[str]] | None + +@dataclass(kw_only=True) +class RpcV2JsonDenseMapsOutput(_SerdeShape): + "Dataclass for RpcV2JsonDenseMapsOutput structure." + + dense_struct_map: dict[str, GreetingStruct] | None = ... + dense_number_map: dict[str, int] | None = ... + dense_boolean_map: dict[str, bool] | None = ... + dense_string_map: dict[str, str] | None = ... + dense_set_map: dict[str, list[str]] | None = ... + 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 RpcV2JsonListsInput(_SerdeShape): + "Dataclass for RpcV2JsonListsInput structure." + + string_list: list[str] | None = ... + string_set: list[str] | None = ... + integer_list: list[int] | None = ... + boolean_list: list[bool] | None = ... + timestamp_list: list[datetime] | None = ... + enum_list: list[str] | None = ... + int_enum_list: list[int] | None = ... + nested_string_list: list[list[str]] | None = ... + structure_list: list[StructureListMember] | None = ... + blob_list: list[bytes] | None = ... + +class RpcV2JsonListsInputDict(TypedDict, total=False): + "Dictionary form of `RpcV2JsonListsInput`." + + string_list: Sequence[str] | None + string_set: Sequence[str] | None + integer_list: Sequence[int] | None + boolean_list: Sequence[bool] | None + timestamp_list: Sequence[datetime] | None + enum_list: Sequence[str] | None + int_enum_list: Sequence[int] | None + nested_string_list: Sequence[Sequence[str]] | None + structure_list: Sequence[StructureListMember | StructureListMemberDict] | None + blob_list: Sequence[bytes] | None + +@dataclass(kw_only=True) +class RpcV2JsonListsOutput(_SerdeShape): + "Dataclass for RpcV2JsonListsOutput structure." + + string_list: list[str] | None = ... + string_set: list[str] | None = ... + integer_list: list[int] | None = ... + boolean_list: list[bool] | None = ... + timestamp_list: list[datetime] | None = ... + enum_list: list[str] | None = ... + int_enum_list: list[int] | None = ... + nested_string_list: list[list[str]] | None = ... + structure_list: list[StructureListMember] | None = ... + blob_list: list[bytes] | None = ... + 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 RpcV2JsonSparseMapsInput(_SerdeShape): + "Dataclass for RpcV2JsonSparseMapsInput structure." + + sparse_struct_map: dict[str, GreetingStruct | None] | None = ... + sparse_number_map: dict[str, int | None] | None = ... + sparse_boolean_map: dict[str, bool | None] | None = ... + sparse_string_map: dict[str, str | None] | None = ... + sparse_set_map: dict[str, list[str] | None] | None = ... + +class RpcV2JsonSparseMapsInputDict(TypedDict, total=False): + "Dictionary form of `RpcV2JsonSparseMapsInput`." + + sparse_struct_map: Mapping[str, GreetingStruct | GreetingStructDict | None] | None + sparse_number_map: Mapping[str, int | None] | None + sparse_boolean_map: Mapping[str, bool | None] | None + sparse_string_map: Mapping[str, str | None] | None + sparse_set_map: Mapping[str, Sequence[str] | None] | None + +@dataclass(kw_only=True) +class RpcV2JsonSparseMapsOutput(_SerdeShape): + "Dataclass for RpcV2JsonSparseMapsOutput structure." + + sparse_struct_map: dict[str, GreetingStruct | None] | None = ... + sparse_number_map: dict[str, int | None] | None = ... + sparse_boolean_map: dict[str, bool | None] | None = ... + sparse_string_map: dict[str, str | None] | None = ... + sparse_set_map: dict[str, list[str] | None] | None = ... + 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 SimpleScalarPropertiesInput(_SerdeShape): + "Dataclass for SimpleScalarPropertiesInput structure." + + true_boolean_value: bool | None = ... + false_boolean_value: bool | None = ... + byte_value: int | None = ... + double_value: float | None = ... + float_value: float | None = ... + integer_value: int | None = ... + long_value: int | None = ... + short_value: int | None = ... + string_value: str | None = ... + blob_value: bytes | None = ... + +class SimpleScalarPropertiesInputDict(TypedDict, total=False): + "Dictionary form of `SimpleScalarPropertiesInput`." + + true_boolean_value: bool | None + false_boolean_value: bool | None + byte_value: int | None + double_value: float | None + float_value: float | None + integer_value: int | None + long_value: int | None + short_value: int | None + string_value: str | None + blob_value: bytes | None + +@dataclass(kw_only=True) +class SimpleScalarPropertiesOutput(_SerdeShape): + "Dataclass for SimpleScalarPropertiesOutput structure." + + true_boolean_value: bool | None = ... + false_boolean_value: bool | None = ... + byte_value: int | None = ... + double_value: float | None = ... + float_value: float | None = ... + integer_value: int | None = ... + long_value: int | None = ... + short_value: int | None = ... + string_value: str | None = ... + blob_value: bytes | None = ... + 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 SparseNullsOperationInput(_SerdeShape): + "Dataclass for SparseNullsOperationInput structure." + + sparse_string_list: list[str | None] | None = ... + sparse_string_map: dict[str, str | None] | None = ... + +class SparseNullsOperationInputDict(TypedDict, total=False): + "Dictionary form of `SparseNullsOperationInput`." + + sparse_string_list: Sequence[str | None] | None + sparse_string_map: Mapping[str, str | None] | None + +@dataclass(kw_only=True) +class SparseNullsOperationOutput(_SerdeShape): + "Dataclass for SparseNullsOperationOutput structure." + + sparse_string_list: list[str | None] | None = ... + sparse_string_map: dict[str, str | None] | None = ... + 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 TimestampFormatIgnoredInput(_SerdeShape): + "Dataclass for TimestampFormatIgnoredInput structure." + + date_time: datetime | None = ... + http_date: datetime | None = ... + epoch_seconds: datetime | None = ... + normal: datetime | None = ... + +class TimestampFormatIgnoredInputDict(TypedDict, total=False): + "Dictionary form of `TimestampFormatIgnoredInput`." + + date_time: datetime | None + http_date: datetime | None + epoch_seconds: datetime | None + normal: datetime | None + +@dataclass(kw_only=True) +class TimestampFormatIgnoredOutput(_SerdeShape): + "Dataclass for TimestampFormatIgnoredOutput structure." + + date_time: datetime | None = ... + http_date: datetime | None = ... + epoch_seconds: datetime | None = ... + normal: datetime | None = ... + 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. + """ + +BIG_DECIMAL_OPERATION: APIOperation[BigDecimalOperationInput, BigDecimalOperationOutput] +BIG_INTEGER_OPERATION: APIOperation[BigIntegerOperationInput, BigIntegerOperationOutput] +EMPTY_INPUT_OUTPUT: APIOperation[EmptyInputOutputInput, EmptyInputOutputOutput] +FRACTIONAL_SECONDS: APIOperation[FractionalSecondsInput, FractionalSecondsOutput] +GREETING_WITH_ERRORS: APIOperation[GreetingWithErrorsInput, GreetingWithErrorsOutput] +NO_INPUT_OUTPUT: APIOperation[NoInputOutputInput, NoInputOutputOutput] +OPERATION_WITH_DEFAULTS: APIOperation[ + OperationWithDefaultsInput, OperationWithDefaultsOutput +] +OPTIONAL_INPUT_OUTPUT: APIOperation[OptionalInputOutputInput, OptionalInputOutputOutput] +RECURSIVE_SHAPES: APIOperation[RecursiveShapesInput, RecursiveShapesOutput] +RPC_V2_JSON_DENSE_MAPS: APIOperation[RpcV2JsonDenseMapsInput, RpcV2JsonDenseMapsOutput] +RPC_V2_JSON_LISTS: APIOperation[RpcV2JsonListsInput, RpcV2JsonListsOutput] +RPC_V2_JSON_SPARSE_MAPS: APIOperation[ + RpcV2JsonSparseMapsInput, RpcV2JsonSparseMapsOutput +] +SIMPLE_SCALAR_PROPERTIES: APIOperation[ + SimpleScalarPropertiesInput, SimpleScalarPropertiesOutput +] +SPARSE_NULLS_OPERATION: APIOperation[ + SparseNullsOperationInput, SparseNullsOperationOutput +] +TIMESTAMP_FORMAT_IGNORED: APIOperation[ + TimestampFormatIgnoredInput, TimestampFormatIgnoredOutput +] diff --git a/codegen-output-py/rpcv2-json-client/src/rpcv2json_client/py.typed b/codegen-output-py/rpcv2-json-client/src/rpcv2json_client/py.typed new file mode 100644 index 000000000..e69de29bb diff --git a/designs/codegen/client.md b/designs/codegen/client.md index c913530d4..a57c1f745 100644 --- a/designs/codegen/client.md +++ b/designs/codegen/client.md @@ -167,26 +167,32 @@ the operation has `optionalAuth`. A protocol registry maps modeled protocol IDs to protocol contributions. A contribution provides sync/async protocol and transport references and their -dependencies. RPCv2 CBOR is built in. Tests can inject a registry. +dependencies. RPCv2 CBOR and RPCv2 JSON are built in. Tests can inject a registry. An explicit protocol selection must be modeled on the service and present in the registry. Without one, the generator selects the sole supported modeled protocol. Ambiguous or unsupported selections fail before publication. Selection is independent of hash and discovery order. -The RPCv2 CBOR contribution uses: +The built-in contributions use these runtime protocols: + +| Protocol | Sync | Async | `smithy-http` extra | +| --- | --- | --- | --- | +| `smithy.protocols#rpcv2Cbor` | `RpcV2CborClientProtocol` | `AsyncRpcV2CborClientProtocol` | `cbor` | +| `smithy.protocols#rpcv2Json` | `RpcV2JsonClientProtocol` | `AsyncRpcV2JsonClientProtocol` | `json` | + +Both also use: -* `smithy_http.protocols.RpcV2CborClientProtocol`. -* `smithy_http.aio.protocols.AsyncRpcV2CborClientProtocol`. * `ProtocolSettings` with the service namespace, target, version, and schema. -* `Urllib3HTTPClient` and `AIOHTTPClient` as default sync/async transports. +* `Urllib3HTTPClient` and `AIOHTTPClient` as default sync/async transports, + which add the `urllib3` and `aiohttp` extras. * `StaticEndpointResolver` with a configured endpoint URI. ## Clients and Configuration Service classes are thin subclasses of `Client[Config]` and `AsyncClient[AsyncConfig]`. Their methods invoke the runtime pipeline, which -owns retries, interceptors, HTTP framing, and CBOR serde. +owns retries, interceptors, HTTP framing, and serde. Generated packages use this layout: @@ -236,8 +242,8 @@ runtime metadata. It covers `self`, `plugins`, defaults, and idempotency tokens. ## Supported Features -The generator supports unsigned, non-streaming RPCv2 CBOR operations with a -static endpoint. Models that require auth schemes, event or data streams, or +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. @@ -253,7 +259,7 @@ fake sync/async transports. They assert the request method, URI, headers, decoded CBOR payload, response models, and error types. Client snapshots sit alongside the types snapshots and cover the -provider-neutral RPCv2 CBOR projection. Checks cover deterministic +provider-neutral RPCv2 CBOR and RPCv2 JSON projections. Checks cover deterministic regeneration, Ruff, strict Pyright consumer usage, lazy imports, plugins/interceptors, retries, response metadata, and transport lifecycle. diff --git a/designs/codegen/snapshots.md b/designs/codegen/snapshots.md index 4dd5e176a..7f08b957a 100644 --- a/designs/codegen/snapshots.md +++ b/designs/codegen/snapshots.md @@ -60,16 +60,17 @@ implementation, user agent, or generated protocol tests. `scripts/codegen-output-py/client-projections.json` declares client projections, generated with the public `client` command. -| Projection | Import package | Operations | -| --- | --- | ---: | -| `rpcv2-cbor-client` | `rpcv2cbor_client` | 14 | - -It reuses the `rpcv2-cbor` model input. Its import package differs from the -types snapshot's, so both resolve in one Pyright project. Each client snapshot -adds `client.py`, `config.py`, and their `aio` counterparts to the types files, -plus service and operation schemas and lazy operation exports. Tests compare its -operation methods with the Java client and send one call through fake sync and -async transports. +| Projection | Import package | Operations | Protocol vectors | +| --- | --- | ---: | ---: | +| `rpcv2-cbor-client` | `rpcv2cbor_client` | 14 | 72 | +| `rpcv2-json-client` | `rpcv2json_client` | 15 | 73 | + +Each reuses the model input of the types projection with the same base name. Its +import package differs from the types snapshot's, so both resolve in one Pyright +project. Each client snapshot adds `client.py`, `config.py`, and their `aio` +counterparts to the types files, plus service and operation schemas and lazy +operation exports. Tests compare the RPCv2 CBOR client's operation methods with +the Java client and send one call through fake sync and async transports. ## Inputs and maintenance diff --git a/packages/smithy-python/.changes/next-release/smithy-python-feature-7e91f2b7956248c4aed733e029ac5374.json b/packages/smithy-python/.changes/next-release/smithy-python-feature-7e91f2b7956248c4aed733e029ac5374.json new file mode 100644 index 000000000..2378a3f33 --- /dev/null +++ b/packages/smithy-python/.changes/next-release/smithy-python-feature-7e91f2b7956248c4aed733e029ac5374.json @@ -0,0 +1,4 @@ +{ + "type": "feature", + "description": "`smithy-python generate client` also generates RPCv2 JSON clients." +} \ No newline at end of file diff --git a/packages/smithy-python/src/smithy_python/protocols.py b/packages/smithy-python/src/smithy_python/protocols.py index 515a182be..c9642e4c7 100644 --- a/packages/smithy-python/src/smithy_python/protocols.py +++ b/packages/smithy-python/src/smithy_python/protocols.py @@ -17,6 +17,7 @@ __all__ = [ "DEFAULT_PROTOCOLS", "RPCV2_CBOR", + "RPCV2_JSON", "ProtocolContribution", "select_protocol", ] @@ -33,7 +34,7 @@ class ProtocolContribution: async_transport: _symbols.TypeReference -def _http(name: str, module: str) -> _symbols.TypeReference: +def _http(name: str, module: str, extra: str) -> _symbols.TypeReference: return _symbols.TypeReference( name, f"smithy_http.{module}", @@ -42,23 +43,42 @@ def _http(name: str, module: str) -> _symbols.TypeReference: package=_dependencies.SMITHY_HTTP.package, specifier=_dependencies.SMITHY_HTTP.specifier, group="runtime", - extras=("aiohttp", "cbor", "urllib3"), + extras=(extra,), ), ), ) +# Each reference records the smithy-http extra it needs, so a client's package +# requires its protocol's codec extra and both default transports' extras. +_URLLIB3: Final = _http("Urllib3HTTPClient", "urllib3", "urllib3") +_AIOHTTP: Final = _http("AIOHTTPClient", "aio.aiohttp", "aiohttp") + RPCV2_CBOR: Final = ProtocolContribution( protocol_id=_model.ShapeId("smithy.protocols", "rpcv2Cbor"), - protocol=_http("RpcV2CborClientProtocol", "protocols"), - async_protocol=_http("AsyncRpcV2CborClientProtocol", "aio.protocols"), - transport=_http("Urllib3HTTPClient", "urllib3"), - async_transport=_http("AIOHTTPClient", "aio.aiohttp"), + protocol=_http("RpcV2CborClientProtocol", "protocols", "cbor"), + async_protocol=_http("AsyncRpcV2CborClientProtocol", "aio.protocols", "cbor"), + transport=_URLLIB3, + async_transport=_AIOHTTP, ) """The built-in ``smithy.protocols#rpcv2Cbor`` contribution.""" +RPCV2_JSON: Final = ProtocolContribution( + protocol_id=_model.ShapeId("smithy.protocols", "rpcv2Json"), + protocol=_http("RpcV2JsonClientProtocol", "protocols", "json"), + async_protocol=_http("AsyncRpcV2JsonClientProtocol", "aio.protocols", "json"), + transport=_URLLIB3, + async_transport=_AIOHTTP, +) +"""The built-in ``smithy.protocols#rpcv2Json`` contribution.""" + DEFAULT_PROTOCOLS: Final[Mapping[_model.ShapeId, ProtocolContribution]] = ( - MappingProxyType({RPCV2_CBOR.protocol_id: RPCV2_CBOR}) + MappingProxyType( + { + contribution.protocol_id: contribution + for contribution in (RPCV2_CBOR, RPCV2_JSON) + } + ) ) """Protocols supported by client generation.""" diff --git a/packages/smithy-python/tests/unit/test_client_generation.py b/packages/smithy-python/tests/unit/test_client_generation.py index 083a8dd3b..20adddb6a 100644 --- a/packages/smithy-python/tests/unit/test_client_generation.py +++ b/packages/smithy-python/tests/unit/test_client_generation.py @@ -3,6 +3,7 @@ import asyncio import importlib +import json import subprocess import sys from collections.abc import Callable @@ -111,9 +112,15 @@ def _cbor_map(values: dict[str, str]) -> bytes: class _Transport: TIMEOUT_EXCEPTIONS = () - def __init__(self, status: int = 200, body: bytes = b"") -> None: + def __init__( + self, + status: int = 200, + body: bytes = b"", + headers: list[tuple[str, str]] = _HEADERS, + ) -> None: self.status = status self.body = body + self.headers = headers self.requests: list[HTTPRequest] = [] def __deepcopy__(self, memo: dict[int, Any]) -> "_Transport": @@ -123,7 +130,7 @@ def __deepcopy__(self, memo: dict[int, Any]) -> "_Transport": def _respond(self, request: HTTPRequest, body: Any) -> HTTPResponse: self.requests.append(request) return HTTPResponse( - status=self.status, fields=tuples_to_fields(_HEADERS), body=body + status=self.status, fields=tuples_to_fields(self.headers), body=body ) def send( @@ -355,3 +362,45 @@ def test_client_optional_input_members_may_be_omitted( package.Greeter(_config(package, transport, aio=False)).greet() (request,) = transport.requests assert loads(_body(request)) == {} + + +def test_rpcv2_json_service_sends_json_and_requires_the_json_extra( + tmp_path: Path, monkeypatch: pytest.MonkeyPatch +) -> None: + shapes = _shapes() + shapes["example#Greeter"]["traits"] = {"smithy.protocols#rpcv2Json": {}} + _generate(tmp_path, "greeter_json", shapes) + project = (tmp_path / "pyproject.toml").read_text() + assert '"smithy-http[aiohttp,json,urllib3]~=' in project + assert "cbor" not in project + + monkeypatch.syspath_prepend( # pyright: ignore[reportUnknownMemberType] + str(tmp_path / "src") + ) + package = importlib.import_module("greeter_json") + transport = _Transport( + body=b'{"greeting": "Hello, Ana"}', + headers=[ + ("Content-Type", "application/json"), + ("smithy-protocol", "rpc-v2-json"), + ], + ) + output = package.Greeter(_config(package, transport, aio=False)).greet(name="Ana") + assert output.greeting == "Hello, Ana" + (request,) = transport.requests + assert request.fields["smithy-protocol"].values == ["rpc-v2-json"] + assert json.loads(_body(request)) == {"name": "Ana"} + + +def test_a_service_with_both_protocols_needs_a_protocol_selection() -> None: + shapes = _shapes() + shapes["example#Greeter"]["traits"]["smithy.protocols#rpcv2Json"] = {} + with pytest.raises(CodegenError, match="more than one supported protocol"): + generator = ClientGenerator(_plan(shapes)) + generator.generate(generator.context()) + settings = ClientSettings( + "greeter", "1.0.0", None, protocol=ShapeId("smithy.protocols", "rpcv2Json") + ) + model = load_model({"smithy": "2.0", "shapes": shapes}) + generator = ClientGenerator(ClientPlan.from_model(model, settings)) + generator.generate(generator.context()) diff --git a/scripts/api-snapshot/api.json b/scripts/api-snapshot/api.json index 193b943ae..98ce3b812 100644 --- a/scripts/api-snapshot/api.json +++ b/scripts/api-snapshot/api.json @@ -886,6 +886,7 @@ "DEFAULT_PROTOCOLS": "mappingproxy", "ProtocolContribution": "class", "RPCV2_CBOR": "ProtocolContribution", + "RPCV2_JSON": "ProtocolContribution", "select_protocol": "function" }, "smithy_python.schemas": { diff --git a/scripts/codegen-output-py/client-projections.json b/scripts/codegen-output-py/client-projections.json index 173f9eaae..9a8941d49 100644 --- a/scripts/codegen-output-py/client-projections.json +++ b/scripts/codegen-output-py/client-projections.json @@ -5,5 +5,12 @@ "package": "rpcv2cbor_client", "service": "smithy.protocoltests.rpcv2Cbor#RpcV2Protocol", "version": "0.0.1" + }, + "rpcv2-json-client": { + "description": "Python client for the rpcv2-json projection", + "model": "models/rpcv2-json.json", + "package": "rpcv2json_client", + "service": "smithy.protocoltests.rpcv2Json#RpcV2JsonProtocol", + "version": "0.0.1" } } diff --git a/scripts/codegen-output-py/models/provenance.json b/scripts/codegen-output-py/models/provenance.json index c5197a53c..e11145a66 100644 --- a/scripts/codegen-output-py/models/provenance.json +++ b/scripts/codegen-output-py/models/provenance.json @@ -50,10 +50,11 @@ "rpcv2-cbor": { "assembled_sha256": "68d4c622bfa0ac01065fb563cbfa6c232668ac8ba09bbbb7dae71c1c4475d529", "fixture_sha256": "04f97ce5fbed181e811a5210ae18005b5d9e3175bedf7ef53f03356dcbe47a38", - "vectors_sha256": "ca533bf1ff4a736bd295b23be1c319b98d6e09a6238e60bd1a0be44876e382cb" + "vectors_sha256": "87dd1af15d6d624a836a7bc45fca44d5d3cdd6a776e86cbdcb1b1111fbd9c6f5" }, "rpcv2-json": { "assembled_sha256": "39446e1f8b195e069632f5e95f6d4b44605f0e99a9df5a2d30b9f94321d3cb1c", - "fixture_sha256": "698c563eece76205e384984e4ea4a4cbe0ce0415d7663b2dbb2e20f6892e09e5" + "fixture_sha256": "698c563eece76205e384984e4ea4a4cbe0ce0415d7663b2dbb2e20f6892e09e5", + "vectors_sha256": "7d3c938768f3dccab0978855990f5708ad124e1eaf1634f090b6f1987ebf590b" } } diff --git a/scripts/codegen-output-py/models/vectors/rpcv2-cbor.json b/scripts/codegen-output-py/models/vectors/rpcv2-cbor.json index e08fe283d..05ee79813 100644 --- a/scripts/codegen-output-py/models/vectors/rpcv2-cbor.json +++ b/scripts/codegen-output-py/models/vectors/rpcv2-cbor.json @@ -161,7 +161,7 @@ }, "id": "RpcV2CborFloat16Subnormal", "params": { - "value": 4.76837158203125e-06 + "value": 0.00000476837158203125 }, "protocol": "smithy.protocols#rpcv2Cbor" } diff --git a/scripts/codegen-output-py/models/vectors/rpcv2-json.json b/scripts/codegen-output-py/models/vectors/rpcv2-json.json new file mode 100644 index 000000000..ec0f51cfa --- /dev/null +++ b/scripts/codegen-output-py/models/vectors/rpcv2-json.json @@ -0,0 +1,1761 @@ +{ + "smithy.protocoltests.rpcv2Json#BigDecimalOperation": { + "requests": [ + { + "body": "{\n \"value\": \"1.5\"\n}", + "bodyMediaType": "application/json", + "documentation": "Serializes a simple big decimal value as a JSON string to preserve precision.", + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonRequestBigDecimalSimpleValue", + "method": "POST", + "params": { + "value": 1.5 + }, + "protocol": "smithy.protocols#rpcv2Json", + "requireHeaders": [ + "Content-Length" + ], + "tags": [ + "arbitrary-precision" + ], + "uri": "/service/RpcV2JsonProtocol/operation/BigDecimalOperation" + }, + { + "body": "{\n \"value\": \"0.100000000000000000000001\"\n}", + "bodyMediaType": "application/json", + "documentation": "Serializes a big decimal value that exceeds double precision in the decimal\nportion. Implementations use JSON strings to preserve this precision.", + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonRequestBigDecimalHighPrecision", + "method": "POST", + "params": { + "value": 0.100000000000000000000001 + }, + "protocol": "smithy.protocols#rpcv2Json", + "requireHeaders": [ + "Content-Length" + ], + "tags": [ + "arbitrary-precision" + ], + "uri": "/service/RpcV2JsonProtocol/operation/BigDecimalOperation" + }, + { + "body": "{\n \"value\": \"-0.100000000000000000000001\"\n}", + "bodyMediaType": "application/json", + "documentation": "Serializes a negative big decimal value that exceeds double precision in\nthe decimal portion. Implementations use JSON strings to preserve this\nprecision.", + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonRequestBigDecimalNegativeHighPrecision", + "method": "POST", + "params": { + "value": -0.100000000000000000000001 + }, + "protocol": "smithy.protocols#rpcv2Json", + "requireHeaders": [ + "Content-Length" + ], + "tags": [ + "arbitrary-precision" + ], + "uri": "/service/RpcV2JsonProtocol/operation/BigDecimalOperation" + }, + { + "body": "{\n \"value\": \"100000000000000000000001.0\"\n}", + "bodyMediaType": "application/json", + "documentation": "Serializes a big decimal value that exceeds double precision in the integer\nportion. Implementations use JSON strings to preserve this precision.", + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonRequestBigDecimalLargeWithFraction", + "method": "POST", + "params": { + "value": 100000000000000000000001.0 + }, + "protocol": "smithy.protocols#rpcv2Json", + "requireHeaders": [ + "Content-Length" + ], + "tags": [ + "arbitrary-precision" + ], + "uri": "/service/RpcV2JsonProtocol/operation/BigDecimalOperation" + } + ], + "responses": [ + { + "body": "{\n \"value\": \"1.5\"\n}", + "bodyMediaType": "application/json", + "code": 200, + "documentation": "Serializes a simple big decimal value as a JSON string to preserve precision.", + "headers": { + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonResponseBigDecimalSimpleValue", + "params": { + "value": 1.5 + }, + "protocol": "smithy.protocols#rpcv2Json", + "tags": [ + "arbitrary-precision" + ] + }, + { + "body": "{\n \"value\": \"0.100000000000000000000001\"\n}", + "bodyMediaType": "application/json", + "code": 200, + "documentation": "Serializes a big decimal value that exceeds double precision in the decimal\nportion. Implementations use JSON strings to preserve this precision.", + "headers": { + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonResponseBigDecimalHighPrecision", + "params": { + "value": 0.100000000000000000000001 + }, + "protocol": "smithy.protocols#rpcv2Json", + "tags": [ + "arbitrary-precision" + ] + }, + { + "body": "{\n \"value\": \"-0.100000000000000000000001\"\n}", + "bodyMediaType": "application/json", + "code": 200, + "documentation": "Serializes a negative big decimal value that exceeds double precision in\nthe decimal portion. Implementations use JSON strings to preserve this\nprecision.", + "headers": { + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonResponseBigDecimalNegativeHighPrecision", + "params": { + "value": -0.100000000000000000000001 + }, + "protocol": "smithy.protocols#rpcv2Json", + "tags": [ + "arbitrary-precision" + ] + }, + { + "body": "{\n \"value\": \"100000000000000000000001.0\"\n}", + "bodyMediaType": "application/json", + "code": 200, + "documentation": "Serializes a big decimal value that exceeds double precision in the integer\nportion. Implementations use JSON strings to preserve this precision.", + "headers": { + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonResponseBigDecimalLargeWithFraction", + "params": { + "value": 100000000000000000000001.0 + }, + "protocol": "smithy.protocols#rpcv2Json", + "tags": [ + "arbitrary-precision" + ] + } + ] + }, + "smithy.protocoltests.rpcv2Json#BigIntegerOperation": { + "requests": [ + { + "body": "{\n \"value\": \"42\"\n}", + "bodyMediaType": "application/json", + "documentation": "Serializes a simple big integer value as a JSON string to preserve precision.", + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonRequestBigIntegerSimpleValue", + "method": "POST", + "params": { + "value": 42 + }, + "protocol": "smithy.protocols#rpcv2Json", + "requireHeaders": [ + "Content-Length" + ], + "tags": [ + "arbitrary-precision" + ], + "uri": "/service/RpcV2JsonProtocol/operation/BigIntegerOperation" + }, + { + "body": "{\n \"value\": \"9223372036854775808\"\n}", + "bodyMediaType": "application/json", + "documentation": "Serializes a big integer value that exceeds the precision of a long.\nImplementations use JSON strings to preserve this precision.", + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonRequestBigIntegerExceedingLongRange", + "method": "POST", + "params": { + "value": 9223372036854775808 + }, + "protocol": "smithy.protocols#rpcv2Json", + "requireHeaders": [ + "Content-Length" + ], + "tags": [ + "arbitrary-precision" + ], + "uri": "/service/RpcV2JsonProtocol/operation/BigIntegerOperation" + }, + { + "body": "{\n \"value\": \"-9223372036854775809\"\n}", + "bodyMediaType": "application/json", + "documentation": "Serializes a negative big integer value that exceeds the precision of a long.\nImplementations use JSON strings to preserve this precision.", + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonRequestBigIntegerNegativeLargeValue", + "method": "POST", + "params": { + "value": -9223372036854775809 + }, + "protocol": "smithy.protocols#rpcv2Json", + "requireHeaders": [ + "Content-Length" + ], + "tags": [ + "arbitrary-precision" + ], + "uri": "/service/RpcV2JsonProtocol/operation/BigIntegerOperation" + } + ], + "responses": [ + { + "body": "{\n \"value\": \"42\"\n}", + "bodyMediaType": "application/json", + "code": 200, + "documentation": "Serializes a simple big integer value as a JSON string to preserve precision.", + "headers": { + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonResponseBigIntegerSimpleValue", + "params": { + "value": 42 + }, + "protocol": "smithy.protocols#rpcv2Json", + "tags": [ + "arbitrary-precision" + ] + }, + { + "body": "{\n \"value\": \"9223372036854775808\"\n}", + "bodyMediaType": "application/json", + "code": 200, + "documentation": "Serializes a big integer value that exceeds the precision of a long.\nImplementations use JSON strings to preserve this precision.", + "headers": { + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonResponseBigIntegerExceedingLongRange", + "params": { + "value": 9223372036854775808 + }, + "protocol": "smithy.protocols#rpcv2Json", + "tags": [ + "arbitrary-precision" + ] + }, + { + "body": "{\n \"value\": \"-9223372036854775809\"\n}", + "bodyMediaType": "application/json", + "code": 200, + "documentation": "Serializes a negative big integer value that exceeds the precision of a long.\nImplementations use JSON strings to preserve this precision.", + "headers": { + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonResponseBigIntegerNegativeLargeValue", + "params": { + "value": -9223372036854775809 + }, + "protocol": "smithy.protocols#rpcv2Json", + "tags": [ + "arbitrary-precision" + ] + } + ] + }, + "smithy.protocoltests.rpcv2Json#ComplexError": { + "responses": [ + { + "body": "{\n \"__type\": \"smithy.protocoltests.rpcv2Json#ComplexError\",\n \"TopLevel\": \"Top level\",\n \"Nested\": {\n \"Foo\": \"bar\"\n }\n}", + "bodyMediaType": "application/json", + "code": 400, + "documentation": "Parses a complex error with no message member", + "headers": { + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonResponseComplexError", + "params": { + "Nested": { + "Foo": "bar" + }, + "TopLevel": "Top level" + }, + "protocol": "smithy.protocols#rpcv2Json" + }, + { + "body": "{\n \"__type\": \"smithy.protocoltests.rpcv2Json#ComplexError\"\n}", + "bodyMediaType": "application/json", + "code": 400, + "headers": { + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonResponseEmptyComplexError", + "protocol": "smithy.protocols#rpcv2Json" + } + ] + }, + "smithy.protocoltests.rpcv2Json#EmptyInputOutput": { + "requests": [ + { + "body": "{}", + "bodyMediaType": "application/json", + "documentation": "When Input structure is empty we write an empty JSON object", + "forbidHeaders": [ + "X-Amz-Target" + ], + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonRequestEmptyInput", + "method": "POST", + "protocol": "smithy.protocols#rpcv2Json", + "requireHeaders": [ + "Content-Length" + ], + "uri": "/service/RpcV2JsonProtocol/operation/EmptyInputOutput" + } + ], + "responses": [ + { + "body": "{}", + "bodyMediaType": "application/json", + "code": 200, + "documentation": "When output structure is empty we write an empty JSON object", + "headers": { + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonResponseEmptyOutput", + "protocol": "smithy.protocols#rpcv2Json" + }, + { + "appliesTo": "client", + "body": "", + "bodyMediaType": "application/json", + "code": 200, + "documentation": "When output structure is empty the client should accept an empty body", + "headers": { + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonResponseEmptyOutputNoBody", + "protocol": "smithy.protocols#rpcv2Json" + } + ] + }, + "smithy.protocoltests.rpcv2Json#FractionalSeconds": { + "responses": [ + { + "appliesTo": "client", + "body": "{\n \"datetime\": 946845296.123\n}", + "bodyMediaType": "application/json", + "code": 200, + "documentation": "Ensures that clients can correctly parse timestamps with fractional seconds", + "headers": { + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonResponseDateTimeWithFractionalSeconds", + "params": { + "datetime": 946845296.123 + }, + "protocol": "smithy.protocols#rpcv2Json" + } + ] + }, + "smithy.protocoltests.rpcv2Json#InvalidGreeting": { + "responses": [ + { + "body": "{\n \"__type\": \"smithy.protocoltests.rpcv2Json#InvalidGreeting\",\n \"Message\": \"Hi\"\n}", + "bodyMediaType": "application/json", + "code": 400, + "documentation": "Parses simple RpcV2 JSON errors", + "headers": { + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonResponseInvalidGreetingError", + "params": { + "Message": "Hi" + }, + "protocol": "smithy.protocols#rpcv2Json" + } + ] + }, + "smithy.protocoltests.rpcv2Json#NoInputOutput": { + "requests": [ + { + "body": "", + "documentation": "Body is empty and no Content-Type header if no input", + "forbidHeaders": [ + "Content-Type", + "X-Amz-Target" + ], + "headers": { + "Accept": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonRequestNoInput", + "method": "POST", + "protocol": "smithy.protocols#rpcv2Json", + "uri": "/service/RpcV2JsonProtocol/operation/NoInputOutput" + } + ], + "responses": [ + { + "body": "", + "bodyMediaType": "application/json", + "code": 200, + "documentation": "A `Content-Type` header should not be set if the response body is empty.", + "forbidHeaders": [ + "Content-Type" + ], + "headers": { + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonResponseNoOutput", + "protocol": "smithy.protocols#rpcv2Json" + }, + { + "appliesTo": "client", + "body": "{}", + "bodyMediaType": "application/json", + "code": 200, + "documentation": "Clients should accept a JSON empty object if there is no output.", + "headers": { + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonResponseNoOutputClientAllowsEmptyJsonObject", + "protocol": "smithy.protocols#rpcv2Json" + }, + { + "appliesTo": "client", + "body": "", + "bodyMediaType": "application/json", + "code": 200, + "documentation": "Clients should accept an empty body if there is no output and\nshould not raise an error if the `Content-Type` header is set.", + "headers": { + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonResponseNoOutputClientAllowsEmptyBody", + "protocol": "smithy.protocols#rpcv2Json" + } + ] + }, + "smithy.protocoltests.rpcv2Json#OperationWithDefaults": { + "requests": [ + { + "appliesTo": "client", + "body": "{\n \"defaults\": {\n \"defaultString\": \"hi\",\n \"defaultBoolean\": true,\n \"defaultList\": [],\n \"defaultTimestamp\": 0,\n \"defaultBlob\": \"YWJj\",\n \"defaultByte\": 1,\n \"defaultShort\": 1,\n \"defaultInteger\": 10,\n \"defaultLong\": 100,\n \"defaultFloat\": 1.0,\n \"defaultDouble\": 1.0,\n \"defaultMap\": {},\n \"defaultEnum\": \"FOO\",\n \"defaultIntEnum\": 1,\n \"emptyString\": \"\",\n \"falseBoolean\": false,\n \"emptyBlob\": \"\",\n \"zeroByte\": 0,\n \"zeroShort\": 0,\n \"zeroInteger\": 0,\n \"zeroLong\": 0,\n \"zeroFloat\": 0.0,\n \"zeroDouble\": 0.0\n }\n}", + "bodyMediaType": "application/json", + "documentation": "Client populates default values in input.", + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonRequestClientPopulatesDefaultValuesInInput", + "method": "POST", + "params": { + "defaults": {} + }, + "protocol": "smithy.protocols#rpcv2Json", + "requireHeaders": [ + "Content-Length" + ], + "tags": [ + "defaults" + ], + "uri": "/service/RpcV2JsonProtocol/operation/OperationWithDefaults" + }, + { + "appliesTo": "client", + "body": "{}", + "bodyMediaType": "application/json", + "documentation": "Client skips top level default values in input.", + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonRequestClientSkipsTopLevelDefaultValuesInInput", + "method": "POST", + "params": {}, + "protocol": "smithy.protocols#rpcv2Json", + "requireHeaders": [ + "Content-Length" + ], + "tags": [ + "defaults" + ], + "uri": "/service/RpcV2JsonProtocol/operation/OperationWithDefaults" + }, + { + "appliesTo": "client", + "body": "{\n \"defaults\": {\n \"defaultString\": \"bye\",\n \"defaultBoolean\": true,\n \"defaultList\": [\"a\"],\n \"defaultTimestamp\": 1,\n \"defaultBlob\": \"aGk=\",\n \"defaultByte\": 2,\n \"defaultShort\": 2,\n \"defaultInteger\": 20,\n \"defaultLong\": 200,\n \"defaultFloat\": 2.0,\n \"defaultDouble\": 2.0,\n \"defaultMap\": {\"name\": \"Jack\"},\n \"defaultEnum\": \"BAR\",\n \"defaultIntEnum\": 2,\n \"emptyString\": \"foo\",\n \"falseBoolean\": true,\n \"emptyBlob\": \"aGk=\",\n \"zeroByte\": 1,\n \"zeroShort\": 1,\n \"zeroInteger\": 1,\n \"zeroLong\": 1,\n \"zeroFloat\": 1.0,\n \"zeroDouble\": 1.0\n }\n}", + "bodyMediaType": "application/json", + "documentation": "Client uses explicitly provided member values over defaults", + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonRequestClientUsesExplicitlyProvidedMemberValuesOverDefaults", + "method": "POST", + "params": { + "defaults": { + "defaultBlob": "hi", + "defaultBoolean": true, + "defaultByte": 2, + "defaultDouble": 2.0, + "defaultEnum": "BAR", + "defaultFloat": 2.0, + "defaultIntEnum": 2, + "defaultInteger": 20, + "defaultList": [ + "a" + ], + "defaultLong": 200, + "defaultMap": { + "name": "Jack" + }, + "defaultShort": 2, + "defaultString": "bye", + "defaultTimestamp": 1, + "emptyBlob": "hi", + "emptyString": "foo", + "falseBoolean": true, + "zeroByte": 1, + "zeroDouble": 1.0, + "zeroFloat": 1.0, + "zeroInteger": 1, + "zeroLong": 1, + "zeroShort": 1 + } + }, + "protocol": "smithy.protocols#rpcv2Json", + "requireHeaders": [ + "Content-Length" + ], + "tags": [ + "defaults" + ], + "uri": "/service/RpcV2JsonProtocol/operation/OperationWithDefaults" + }, + { + "appliesTo": "client", + "body": "{\n \"topLevelDefault\": \"hi\",\n \"otherTopLevelDefault\": 0\n}", + "bodyMediaType": "application/json", + "documentation": "Any time a value is provided for a member in the top level of input, it is used, regardless of if its the default.", + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonRequestClientUsesExplicitlyProvidedValuesInTopLevel", + "method": "POST", + "params": { + "otherTopLevelDefault": 0, + "topLevelDefault": "hi" + }, + "protocol": "smithy.protocols#rpcv2Json", + "requireHeaders": [ + "Content-Length" + ], + "tags": [ + "defaults" + ], + "uri": "/service/RpcV2JsonProtocol/operation/OperationWithDefaults" + }, + { + "appliesTo": "client", + "body": "{\n \"clientOptionalDefaults\": {}\n}", + "bodyMediaType": "application/json", + "documentation": "Typically, non top-level members would have defaults filled in, but if they have the clientOptional trait, the defaults should be ignored.", + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonRequestClientIgnoresNonTopLevelDefaultsOnMembersWithClientOptional", + "method": "POST", + "params": { + "clientOptionalDefaults": {} + }, + "protocol": "smithy.protocols#rpcv2Json", + "requireHeaders": [ + "Content-Length" + ], + "tags": [ + "defaults" + ], + "uri": "/service/RpcV2JsonProtocol/operation/OperationWithDefaults" + } + ], + "responses": [ + { + "appliesTo": "client", + "body": "{}", + "bodyMediaType": "application/json", + "code": 200, + "documentation": "Client populates default values when missing in response.", + "headers": { + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonResponseClientPopulatesDefaultsValuesWhenMissingInResponse", + "params": { + "defaultBlob": "abc", + "defaultBoolean": true, + "defaultByte": 1, + "defaultDouble": 1.0, + "defaultEnum": "FOO", + "defaultFloat": 1.0, + "defaultIntEnum": 1, + "defaultInteger": 10, + "defaultList": [], + "defaultLong": 100, + "defaultMap": {}, + "defaultShort": 1, + "defaultString": "hi", + "defaultTimestamp": 0, + "emptyBlob": "", + "emptyString": "", + "falseBoolean": false, + "zeroByte": 0, + "zeroDouble": 0.0, + "zeroFloat": 0.0, + "zeroInteger": 0, + "zeroLong": 0, + "zeroShort": 0 + }, + "protocol": "smithy.protocols#rpcv2Json", + "tags": [ + "defaults" + ] + }, + { + "appliesTo": "client", + "body": "{\n \"defaultString\": \"bye\",\n \"defaultBoolean\": false,\n \"defaultList\": [\"a\"],\n \"defaultTimestamp\": 2,\n \"defaultBlob\": \"aGk=\",\n \"defaultByte\": 2,\n \"defaultShort\": 2,\n \"defaultInteger\": 20,\n \"defaultLong\": 200,\n \"defaultFloat\": 2.0,\n \"defaultDouble\": 2.0,\n \"defaultMap\": {\"name\": \"Jack\"},\n \"defaultEnum\": \"BAR\",\n \"defaultIntEnum\": 2,\n \"emptyString\": \"foo\",\n \"falseBoolean\": true,\n \"emptyBlob\": \"aGk=\",\n \"zeroByte\": 1,\n \"zeroShort\": 1,\n \"zeroInteger\": 1,\n \"zeroLong\": 1,\n \"zeroFloat\": 1.0,\n \"zeroDouble\": 1.0\n}", + "bodyMediaType": "application/json", + "code": 200, + "documentation": "Client ignores default values if member values are present in the response.", + "headers": { + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonResponseClientIgnoresDefaultValuesIfMemberValuesArePresentInResponse", + "params": { + "defaultBlob": "hi", + "defaultBoolean": false, + "defaultByte": 2, + "defaultDouble": 2.0, + "defaultEnum": "BAR", + "defaultFloat": 2.0, + "defaultIntEnum": 2, + "defaultInteger": 20, + "defaultList": [ + "a" + ], + "defaultLong": 200, + "defaultMap": { + "name": "Jack" + }, + "defaultShort": 2, + "defaultString": "bye", + "defaultTimestamp": 2, + "emptyBlob": "hi", + "emptyString": "foo", + "falseBoolean": true, + "zeroByte": 1, + "zeroDouble": 1.0, + "zeroFloat": 1.0, + "zeroInteger": 1, + "zeroLong": 1, + "zeroShort": 1 + }, + "protocol": "smithy.protocols#rpcv2Json", + "tags": [ + "defaults" + ] + } + ] + }, + "smithy.protocoltests.rpcv2Json#OptionalInputOutput": { + "requests": [ + { + "body": "{}", + "bodyMediaType": "application/json", + "documentation": "When input is empty we write an empty JSON object", + "forbidHeaders": [ + "X-Amz-Target" + ], + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonRequestOptionalInput", + "method": "POST", + "protocol": "smithy.protocols#rpcv2Json", + "uri": "/service/RpcV2JsonProtocol/operation/OptionalInputOutput" + } + ], + "responses": [ + { + "body": "{}", + "bodyMediaType": "application/json", + "code": 200, + "documentation": "When output is empty we write an empty JSON object", + "headers": { + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonResponseOptionalOutput", + "protocol": "smithy.protocols#rpcv2Json" + } + ] + }, + "smithy.protocoltests.rpcv2Json#RecursiveShapes": { + "requests": [ + { + "body": "{\n \"nested\": {\n \"foo\": \"Foo1\",\n \"nested\": {\n \"bar\": \"Bar1\",\n \"recursiveMember\": {\n \"foo\": \"Foo2\",\n \"nested\": {\n \"bar\": \"Bar2\"\n }\n }\n }\n }\n}", + "bodyMediaType": "application/json", + "documentation": "Serializes recursive structures", + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonRequestRecursiveShapes", + "method": "POST", + "params": { + "nested": { + "foo": "Foo1", + "nested": { + "bar": "Bar1", + "recursiveMember": { + "foo": "Foo2", + "nested": { + "bar": "Bar2" + } + } + } + } + }, + "protocol": "smithy.protocols#rpcv2Json", + "requireHeaders": [ + "Content-Length" + ], + "uri": "/service/RpcV2JsonProtocol/operation/RecursiveShapes" + } + ], + "responses": [ + { + "body": "{\n \"nested\": {\n \"foo\": \"Foo1\",\n \"nested\": {\n \"bar\": \"Bar1\",\n \"recursiveMember\": {\n \"foo\": \"Foo2\",\n \"nested\": {\n \"bar\": \"Bar2\"\n }\n }\n }\n }\n}", + "bodyMediaType": "application/json", + "code": 200, + "documentation": "Serializes recursive structures", + "headers": { + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonResponseRecursiveShapes", + "params": { + "nested": { + "foo": "Foo1", + "nested": { + "bar": "Bar1", + "recursiveMember": { + "foo": "Foo2", + "nested": { + "bar": "Bar2" + } + } + } + } + }, + "protocol": "smithy.protocols#rpcv2Json" + } + ] + }, + "smithy.protocoltests.rpcv2Json#RpcV2JsonDenseMaps": { + "requests": [ + { + "body": "{\n \"denseStructMap\": {\n \"foo\": {\n \"hi\": \"there\"\n },\n \"baz\": {\n \"hi\": \"bye\"\n }\n }\n}", + "bodyMediaType": "application/json", + "documentation": "Serializes maps", + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonRequestMaps", + "method": "POST", + "params": { + "denseStructMap": { + "baz": { + "hi": "bye" + }, + "foo": { + "hi": "there" + } + } + }, + "protocol": "smithy.protocols#rpcv2Json", + "requireHeaders": [ + "Content-Length" + ], + "uri": "/service/RpcV2JsonProtocol/operation/RpcV2JsonDenseMaps" + }, + { + "body": "{\n \"denseNumberMap\": {\n \"x\": 0\n },\n \"denseBooleanMap\": {\n \"x\": false\n }\n}", + "bodyMediaType": "application/json", + "documentation": "Ensure that 0 and false are sent over the wire in all maps and lists", + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonRequestSerializesZeroValuesInMaps", + "method": "POST", + "params": { + "denseBooleanMap": { + "x": false + }, + "denseNumberMap": { + "x": 0 + } + }, + "protocol": "smithy.protocols#rpcv2Json", + "requireHeaders": [ + "Content-Length" + ], + "uri": "/service/RpcV2JsonProtocol/operation/RpcV2JsonDenseMaps" + }, + { + "body": "{\n \"denseSetMap\": {\n \"x\": [],\n \"y\": [\"a\", \"b\"]\n }\n}", + "bodyMediaType": "application/json", + "documentation": "A request that contains a dense map of sets.", + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonRequestSerializesDenseSetMap", + "method": "POST", + "params": { + "denseSetMap": { + "x": [], + "y": [ + "a", + "b" + ] + } + }, + "protocol": "smithy.protocols#rpcv2Json", + "requireHeaders": [ + "Content-Length" + ], + "uri": "/service/RpcV2JsonProtocol/operation/RpcV2JsonDenseMaps" + } + ], + "responses": [ + { + "body": "{\n \"denseStructMap\": {\n \"foo\": {\n \"hi\": \"there\"\n },\n \"baz\": {\n \"hi\": \"bye\"\n }\n }\n}", + "bodyMediaType": "application/json", + "code": 200, + "documentation": "Deserializes maps", + "headers": { + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonResponseMaps", + "params": { + "denseStructMap": { + "baz": { + "hi": "bye" + }, + "foo": { + "hi": "there" + } + } + }, + "protocol": "smithy.protocols#rpcv2Json" + }, + { + "body": "{\n \"denseNumberMap\": {\n \"x\": 0\n },\n \"denseBooleanMap\": {\n \"x\": false\n }\n}", + "bodyMediaType": "application/json", + "code": 200, + "documentation": "Ensure that 0 and false are sent over the wire in all maps and lists", + "headers": { + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonResponseDeserializesZeroValuesInMaps", + "params": { + "denseBooleanMap": { + "x": false + }, + "denseNumberMap": { + "x": 0 + } + }, + "protocol": "smithy.protocols#rpcv2Json" + }, + { + "body": "{\n \"denseSetMap\": {\n \"x\": [],\n \"y\": [\"a\", \"b\"]\n }\n}", + "bodyMediaType": "application/json", + "code": 200, + "documentation": "A response that contains a dense map of sets", + "headers": { + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonResponseDeserializesDenseSetMap", + "params": { + "denseSetMap": { + "x": [], + "y": [ + "a", + "b" + ] + } + }, + "protocol": "smithy.protocols#rpcv2Json" + } + ] + }, + "smithy.protocoltests.rpcv2Json#RpcV2JsonLists": { + "requests": [ + { + "body": "{\n \"stringList\": [\n \"foo\",\n \"bar\"\n ],\n \"stringSet\": [\n \"foo\",\n \"bar\"\n ],\n \"integerList\": [\n 1,\n 2\n ],\n \"booleanList\": [\n true,\n false\n ],\n \"timestampList\": [\n 1398796238,\n 1398796238\n ],\n \"enumList\": [\n \"Foo\",\n \"0\"\n ],\n \"intEnumList\": [\n 1,\n 2\n ],\n \"nestedStringList\": [\n [\n \"foo\",\n \"bar\"\n ],\n [\n \"baz\",\n \"qux\"\n ]\n ],\n \"structureList\": [\n {\n \"a\": \"1\",\n \"b\": \"2\"\n },\n {\n \"a\": \"3\",\n \"b\": \"4\"\n }\n ],\n \"blobList\": [\n \"Zm9v\",\n \"YmFy\"\n ]\n}", + "bodyMediaType": "application/json", + "documentation": "Serializes RpcV2 JSON lists", + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonRequestLists", + "method": "POST", + "params": { + "blobList": [ + "foo", + "bar" + ], + "booleanList": [ + true, + false + ], + "enumList": [ + "Foo", + "0" + ], + "intEnumList": [ + 1, + 2 + ], + "integerList": [ + 1, + 2 + ], + "nestedStringList": [ + [ + "foo", + "bar" + ], + [ + "baz", + "qux" + ] + ], + "stringList": [ + "foo", + "bar" + ], + "stringSet": [ + "foo", + "bar" + ], + "structureList": [ + { + "a": "1", + "b": "2" + }, + { + "a": "3", + "b": "4" + } + ], + "timestampList": [ + 1398796238, + 1398796238 + ] + }, + "protocol": "smithy.protocols#rpcv2Json", + "requireHeaders": [ + "Content-Length" + ], + "uri": "/service/RpcV2JsonProtocol/operation/RpcV2JsonLists" + }, + { + "body": "{\n \"stringList\": []\n}", + "bodyMediaType": "application/json", + "documentation": "Serializes empty JSON lists", + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonRequestListsEmpty", + "method": "POST", + "params": { + "stringList": [] + }, + "protocol": "smithy.protocols#rpcv2Json", + "requireHeaders": [ + "Content-Length" + ], + "uri": "/service/RpcV2JsonProtocol/operation/RpcV2JsonLists" + } + ], + "responses": [ + { + "body": "{\n \"stringList\": [\n \"foo\",\n \"bar\"\n ],\n \"stringSet\": [\n \"foo\",\n \"bar\"\n ],\n \"integerList\": [\n 1,\n 2\n ],\n \"booleanList\": [\n true,\n false\n ],\n \"timestampList\": [\n 1398796238,\n 1398796238\n ],\n \"enumList\": [\n \"Foo\",\n \"0\"\n ],\n \"intEnumList\": [\n 1,\n 2\n ],\n \"nestedStringList\": [\n [\n \"foo\",\n \"bar\"\n ],\n [\n \"baz\",\n \"qux\"\n ]\n ],\n \"structureList\": [\n {\n \"a\": \"1\",\n \"b\": \"2\"\n },\n {\n \"a\": \"3\",\n \"b\": \"4\"\n }\n ],\n \"blobList\": [\n \"Zm9v\",\n \"YmFy\"\n ]\n}", + "bodyMediaType": "application/json", + "code": 200, + "documentation": "Serializes RpcV2 JSON lists", + "headers": { + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonResponseLists", + "params": { + "blobList": [ + "foo", + "bar" + ], + "booleanList": [ + true, + false + ], + "enumList": [ + "Foo", + "0" + ], + "intEnumList": [ + 1, + 2 + ], + "integerList": [ + 1, + 2 + ], + "nestedStringList": [ + [ + "foo", + "bar" + ], + [ + "baz", + "qux" + ] + ], + "stringList": [ + "foo", + "bar" + ], + "stringSet": [ + "foo", + "bar" + ], + "structureList": [ + { + "a": "1", + "b": "2" + }, + { + "a": "3", + "b": "4" + } + ], + "timestampList": [ + 1398796238, + 1398796238 + ] + }, + "protocol": "smithy.protocols#rpcv2Json" + }, + { + "body": "{\n \"stringList\": []\n}", + "bodyMediaType": "application/json", + "code": 200, + "documentation": "Serializes empty RpcV2 JSON lists", + "headers": { + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonResponseListsEmpty", + "params": { + "stringList": [] + }, + "protocol": "smithy.protocols#rpcv2Json" + } + ] + }, + "smithy.protocoltests.rpcv2Json#RpcV2JsonSparseMaps": { + "requests": [ + { + "body": "{\n \"sparseStructMap\": {\n \"foo\": {\n \"hi\": \"there\"\n },\n \"baz\": {\n \"hi\": \"bye\"\n }\n }\n}", + "bodyMediaType": "application/json", + "documentation": "Serializes sparse maps", + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonRequestSparseMaps", + "method": "POST", + "params": { + "sparseStructMap": { + "baz": { + "hi": "bye" + }, + "foo": { + "hi": "there" + } + } + }, + "protocol": "smithy.protocols#rpcv2Json", + "requireHeaders": [ + "Content-Length" + ], + "uri": "/service/RpcV2JsonProtocol/operation/RpcV2JsonSparseMaps" + }, + { + "body": "{\n \"sparseBooleanMap\": {\n \"x\": null\n },\n \"sparseNumberMap\": {\n \"x\": null\n },\n \"sparseStringMap\": {\n \"x\": null\n },\n \"sparseStructMap\": {\n \"x\": null\n }\n}", + "bodyMediaType": "application/json", + "documentation": "Serializes null map values in sparse maps", + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonRequestSerializesNullMapValues", + "method": "POST", + "params": { + "sparseBooleanMap": { + "x": null + }, + "sparseNumberMap": { + "x": null + }, + "sparseStringMap": { + "x": null + }, + "sparseStructMap": { + "x": null + } + }, + "protocol": "smithy.protocols#rpcv2Json", + "requireHeaders": [ + "Content-Length" + ], + "uri": "/service/RpcV2JsonProtocol/operation/RpcV2JsonSparseMaps" + }, + { + "body": "{\n \"sparseSetMap\": {\n \"x\": [],\n \"y\": [\"a\", \"b\"]\n }\n}", + "bodyMediaType": "application/json", + "documentation": "A request that contains a sparse map of sets", + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonRequestSerializesSparseSetMap", + "method": "POST", + "params": { + "sparseSetMap": { + "x": [], + "y": [ + "a", + "b" + ] + } + }, + "protocol": "smithy.protocols#rpcv2Json", + "requireHeaders": [ + "Content-Length" + ], + "uri": "/service/RpcV2JsonProtocol/operation/RpcV2JsonSparseMaps" + }, + { + "body": "{\n \"sparseSetMap\": {\n \"x\": [],\n \"y\": [\"a\", \"b\"],\n \"z\": null\n }\n}", + "bodyMediaType": "application/json", + "documentation": "A request that contains a sparse map of sets.", + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonRequestSerializesSparseSetMapAndRetainsNull", + "method": "POST", + "params": { + "sparseSetMap": { + "x": [], + "y": [ + "a", + "b" + ], + "z": null + } + }, + "protocol": "smithy.protocols#rpcv2Json", + "requireHeaders": [ + "Content-Length" + ], + "uri": "/service/RpcV2JsonProtocol/operation/RpcV2JsonSparseMaps" + }, + { + "body": "{\n \"sparseNumberMap\": {\n \"x\": 0\n },\n \"sparseBooleanMap\": {\n \"x\": false\n }\n}", + "bodyMediaType": "application/json", + "documentation": "Ensure that 0 and false are sent over the wire in all maps and lists", + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonRequestSerializesZeroValuesInSparseMaps", + "method": "POST", + "params": { + "sparseBooleanMap": { + "x": false + }, + "sparseNumberMap": { + "x": 0 + } + }, + "protocol": "smithy.protocols#rpcv2Json", + "requireHeaders": [ + "Content-Length" + ], + "uri": "/service/RpcV2JsonProtocol/operation/RpcV2JsonSparseMaps" + } + ], + "responses": [ + { + "body": "{\n \"sparseStructMap\": {\n \"foo\": {\n \"hi\": \"there\"\n },\n \"baz\": {\n \"hi\": \"bye\"\n }\n }\n}", + "bodyMediaType": "application/json", + "code": 200, + "documentation": "Deserializes sparse maps", + "headers": { + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonResponseSparseJsonMaps", + "params": { + "sparseStructMap": { + "baz": { + "hi": "bye" + }, + "foo": { + "hi": "there" + } + } + }, + "protocol": "smithy.protocols#rpcv2Json" + }, + { + "body": "{\n \"sparseBooleanMap\": {\n \"x\": null\n },\n \"sparseNumberMap\": {\n \"x\": null\n },\n \"sparseStringMap\": {\n \"x\": null\n },\n \"sparseStructMap\": {\n \"x\": null\n }\n}", + "bodyMediaType": "application/json", + "code": 200, + "documentation": "Deserializes null map values", + "headers": { + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonResponseDeserializesNullMapValues", + "params": { + "sparseBooleanMap": { + "x": null + }, + "sparseNumberMap": { + "x": null + }, + "sparseStringMap": { + "x": null + }, + "sparseStructMap": { + "x": null + } + }, + "protocol": "smithy.protocols#rpcv2Json" + }, + { + "body": "{\n \"sparseSetMap\": {\n \"x\": [],\n \"y\": [\"a\", \"b\"]\n }\n}", + "bodyMediaType": "application/json", + "code": 200, + "documentation": "A response that contains a sparse map of sets", + "headers": { + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonResponseDeserializesSparseSetMap", + "params": { + "sparseSetMap": { + "x": [], + "y": [ + "a", + "b" + ] + } + }, + "protocol": "smithy.protocols#rpcv2Json" + }, + { + "body": "{\n \"sparseSetMap\": {\n \"x\": [],\n \"y\": [\"a\", \"b\"],\n \"z\": null\n }\n}", + "bodyMediaType": "application/json", + "code": 200, + "documentation": "A response that contains a sparse map of sets with a null", + "headers": { + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonResponseDeserializesSparseSetMapAndRetainsNull", + "params": { + "sparseSetMap": { + "x": [], + "y": [ + "a", + "b" + ], + "z": null + } + }, + "protocol": "smithy.protocols#rpcv2Json" + }, + { + "body": "{\n \"sparseNumberMap\": {\n \"x\": 0\n },\n \"sparseBooleanMap\": {\n \"x\": false\n }\n}", + "bodyMediaType": "application/json", + "code": 200, + "documentation": "Ensure that 0 and false are sent over the wire in all maps and lists", + "headers": { + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonResponseDeserializesZeroValuesInSparseMaps", + "params": { + "sparseBooleanMap": { + "x": false + }, + "sparseNumberMap": { + "x": 0 + } + }, + "protocol": "smithy.protocols#rpcv2Json" + } + ] + }, + "smithy.protocoltests.rpcv2Json#SimpleScalarProperties": { + "requests": [ + { + "body": "{\n \"byteValue\": 5,\n \"doubleValue\": 1.889,\n \"falseBooleanValue\": false,\n \"floatValue\": 7.625,\n \"integerValue\": 256,\n \"longValue\": 9873,\n \"shortValue\": 9898,\n \"stringValue\": \"simple\",\n \"trueBooleanValue\": true,\n \"blobValue\": \"Zm9v\"\n}", + "bodyMediaType": "application/json", + "documentation": "Serializes simple scalar properties", + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonRequestSimpleScalarProperties", + "method": "POST", + "params": { + "blobValue": "foo", + "byteValue": 5, + "doubleValue": 1.889, + "falseBooleanValue": false, + "floatValue": 7.625, + "integerValue": 256, + "longValue": 9873, + "shortValue": 9898, + "stringValue": "simple", + "trueBooleanValue": true + }, + "protocol": "smithy.protocols#rpcv2Json", + "requireHeaders": [ + "Content-Length" + ], + "uri": "/service/RpcV2JsonProtocol/operation/SimpleScalarProperties" + }, + { + "appliesTo": "client", + "body": "{}", + "bodyMediaType": "application/json", + "documentation": "RpcV2 JSON should not serialize null structure values", + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonRequestClientDoesntSerializeNullStructureValues", + "method": "POST", + "params": { + "stringValue": null + }, + "protocol": "smithy.protocols#rpcv2Json", + "requireHeaders": [ + "Content-Length" + ], + "uri": "/service/RpcV2JsonProtocol/operation/SimpleScalarProperties" + }, + { + "body": "{\n \"doubleValue\": \"NaN\",\n \"floatValue\": \"NaN\"\n}", + "bodyMediaType": "application/json", + "documentation": "Supports handling NaN float values.", + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonRequestSupportsNaNFloatInputs", + "method": "POST", + "params": { + "doubleValue": "NaN", + "floatValue": "NaN" + }, + "protocol": "smithy.protocols#rpcv2Json", + "requireHeaders": [ + "Content-Length" + ], + "uri": "/service/RpcV2JsonProtocol/operation/SimpleScalarProperties" + }, + { + "body": "{\n \"doubleValue\": \"Infinity\",\n \"floatValue\": \"Infinity\"\n}", + "bodyMediaType": "application/json", + "documentation": "Supports handling Infinity float values.", + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonRequestSupportsInfinityFloatInputs", + "method": "POST", + "params": { + "doubleValue": "Infinity", + "floatValue": "Infinity" + }, + "protocol": "smithy.protocols#rpcv2Json", + "requireHeaders": [ + "Content-Length" + ], + "uri": "/service/RpcV2JsonProtocol/operation/SimpleScalarProperties" + }, + { + "body": "{\n \"doubleValue\": \"-Infinity\",\n \"floatValue\": \"-Infinity\"\n}", + "bodyMediaType": "application/json", + "documentation": "Supports handling -Infinity float values.", + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonRequestSupportsNegativeInfinityFloatInputs", + "method": "POST", + "params": { + "doubleValue": "-Infinity", + "floatValue": "-Infinity" + }, + "protocol": "smithy.protocols#rpcv2Json", + "requireHeaders": [ + "Content-Length" + ], + "uri": "/service/RpcV2JsonProtocol/operation/SimpleScalarProperties" + } + ], + "responses": [ + { + "body": "{\n \"trueBooleanValue\": true,\n \"falseBooleanValue\": false,\n \"byteValue\": 5,\n \"doubleValue\": 1.889,\n \"floatValue\": 7.625,\n \"integerValue\": 256,\n \"shortValue\": 9898,\n \"stringValue\": \"simple\",\n \"blobValue\": \"Zm9v\"\n}", + "bodyMediaType": "application/json", + "code": 200, + "documentation": "Serializes simple scalar properties", + "headers": { + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonResponseSimpleScalarProperties", + "params": { + "blobValue": "foo", + "byteValue": 5, + "doubleValue": 1.889, + "falseBooleanValue": false, + "floatValue": 7.625, + "integerValue": 256, + "shortValue": 9898, + "stringValue": "simple", + "trueBooleanValue": true + }, + "protocol": "smithy.protocols#rpcv2Json" + }, + { + "appliesTo": "client", + "body": "{\n \"stringValue\": null\n}", + "bodyMediaType": "application/json", + "code": 200, + "documentation": "RpcV2 JSON should not deserialize null structure values", + "headers": { + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonResponseClientDoesntDeserializeNullStructureValues", + "params": {}, + "protocol": "smithy.protocols#rpcv2Json" + }, + { + "body": "{\n \"doubleValue\": \"NaN\",\n \"floatValue\": \"NaN\"\n}", + "bodyMediaType": "application/json", + "code": 200, + "documentation": "Supports handling NaN float values.", + "headers": { + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonResponseSupportsNaNFloatOutputs", + "params": { + "doubleValue": "NaN", + "floatValue": "NaN" + }, + "protocol": "smithy.protocols#rpcv2Json" + }, + { + "body": "{\n \"doubleValue\": \"Infinity\",\n \"floatValue\": \"Infinity\"\n}", + "bodyMediaType": "application/json", + "code": 200, + "documentation": "Supports handling Infinity float values.", + "headers": { + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonResponseSupportsInfinityFloatOutputs", + "params": { + "doubleValue": "Infinity", + "floatValue": "Infinity" + }, + "protocol": "smithy.protocols#rpcv2Json" + }, + { + "body": "{\n \"doubleValue\": \"-Infinity\",\n \"floatValue\": \"-Infinity\"\n}", + "bodyMediaType": "application/json", + "code": 200, + "documentation": "Supports handling Negative Infinity float values.", + "headers": { + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonResponseSupportsNegativeInfinityFloatOutputs", + "params": { + "doubleValue": "-Infinity", + "floatValue": "-Infinity" + }, + "protocol": "smithy.protocols#rpcv2Json" + }, + { + "appliesTo": "client", + "body": "{\n \"byteValue\": 5,\n \"doubleValue\": 1.889,\n \"falseBooleanValue\": false,\n \"floatValue\": 7.625,\n \"extraObject\": {\n \"normalString\": \"foo\",\n \"withAnArray\": [1, 2, 3]\n },\n \"integerValue\": 256,\n \"longValue\": 9873,\n \"shortValue\": 9898,\n \"stringValue\": \"simple\",\n \"someOtherField\": \"this should be skipped\",\n \"trueBooleanValue\": true,\n \"blobValue\": \"Zm9v\"\n}", + "bodyMediaType": "application/json", + "code": 200, + "documentation": "The client should skip over additional fields that are not part of the structure. This allows a\nclient generated against an older Smithy model to be able to communicate with a server that is\ngenerated against a newer Smithy model.", + "headers": { + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonResponseExtraFieldsInTheBodyShouldBeSkippedByClients", + "params": { + "blobValue": "foo", + "byteValue": 5, + "doubleValue": 1.889, + "falseBooleanValue": false, + "floatValue": 7.625, + "integerValue": 256, + "longValue": 9873, + "shortValue": 9898, + "stringValue": "simple", + "trueBooleanValue": true + }, + "protocol": "smithy.protocols#rpcv2Json" + } + ] + }, + "smithy.protocoltests.rpcv2Json#SparseNullsOperation": { + "requests": [ + { + "body": "{\n \"sparseStringMap\": {\n \"foo\": null\n }\n}", + "bodyMediaType": "application/json", + "documentation": "Serializes null values in maps", + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonRequestSparseMapsSerializeNullValues", + "method": "POST", + "params": { + "sparseStringMap": { + "foo": null + } + }, + "protocol": "smithy.protocols#rpcv2Json", + "requireHeaders": [ + "Content-Length" + ], + "uri": "/service/RpcV2JsonProtocol/operation/SparseNullsOperation" + }, + { + "body": "{\n \"sparseStringList\": [\n null\n ]\n}", + "bodyMediaType": "application/json", + "documentation": "Serializes null values in lists", + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonRequestSparseListsSerializeNull", + "method": "POST", + "params": { + "sparseStringList": [ + null + ] + }, + "protocol": "smithy.protocols#rpcv2Json", + "requireHeaders": [ + "Content-Length" + ], + "uri": "/service/RpcV2JsonProtocol/operation/SparseNullsOperation" + } + ], + "responses": [ + { + "body": "{\n \"sparseStringMap\": {\n \"foo\": null\n }\n}", + "bodyMediaType": "application/json", + "code": 200, + "documentation": "Deserializes null values in maps", + "headers": { + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonResponseSparseMapsDeserializeNullValues", + "params": { + "sparseStringMap": { + "foo": null + } + }, + "protocol": "smithy.protocols#rpcv2Json" + }, + { + "body": "{\n \"sparseStringList\": [\n null\n ]\n}", + "bodyMediaType": "application/json", + "code": 200, + "documentation": "Deserializes null values in lists", + "headers": { + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonResponseSparseListsDeserializeNull", + "params": { + "sparseStringList": [ + null + ] + }, + "protocol": "smithy.protocols#rpcv2Json" + } + ] + }, + "smithy.protocoltests.rpcv2Json#TimestampFormatIgnored": { + "requests": [ + { + "body": "{\n \"dateTime\": 946845296,\n \"httpDate\": 946845296,\n \"epochSeconds\": 946845296,\n \"normal\": 946845296\n}", + "bodyMediaType": "application/json", + "documentation": "The rpcv2Json protocol always serializes timestamps as epoch-seconds JSON numbers.\nThe timestampFormat trait MUST NOT be respected.", + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonRequestTimestampFormatIgnored", + "method": "POST", + "params": { + "dateTime": 946845296, + "epochSeconds": 946845296, + "httpDate": 946845296, + "normal": 946845296 + }, + "protocol": "smithy.protocols#rpcv2Json", + "requireHeaders": [ + "Content-Length" + ], + "uri": "/service/RpcV2JsonProtocol/operation/TimestampFormatIgnored" + } + ], + "responses": [ + { + "body": "{\n \"dateTime\": 946845296,\n \"httpDate\": 946845296,\n \"epochSeconds\": 946845296,\n \"normal\": 946845296\n}", + "bodyMediaType": "application/json", + "code": 200, + "documentation": "The rpcv2Json protocol always serializes timestamps as epoch-seconds JSON numbers.\nThe timestampFormat trait MUST NOT be respected.", + "headers": { + "Content-Type": "application/json", + "smithy-protocol": "rpc-v2-json" + }, + "id": "RpcV2JsonResponseTimestampFormatIgnored", + "params": { + "dateTime": 946845296, + "epochSeconds": 946845296, + "httpDate": 946845296, + "normal": 946845296 + }, + "protocol": "smithy.protocols#rpcv2Json" + } + ] + } +} diff --git a/scripts/codegen-output-py/pyrightconfig.json b/scripts/codegen-output-py/pyrightconfig.json index 9e9999ff4..bb0672fe9 100644 --- a/scripts/codegen-output-py/pyrightconfig.json +++ b/scripts/codegen-output-py/pyrightconfig.json @@ -24,6 +24,7 @@ "../../codegen-output-py/rpcv2-cbor/src", "../../codegen-output-py/rpcv2-cbor-client/src", "../../codegen-output-py/rpcv2-json/src", + "../../codegen-output-py/rpcv2-json-client/src", "../../codegen-output-py/types/src" ] } diff --git a/scripts/codegen-output-py/refresh_models.py b/scripts/codegen-output-py/refresh_models.py index 8ec32d261..efd7a09d1 100644 --- a/scripts/codegen-output-py/refresh_models.py +++ b/scripts/codegen-output-py/refresh_models.py @@ -9,6 +9,8 @@ import argparse import hashlib import json +import re +from decimal import Decimal from pathlib import Path from typing import Any @@ -53,9 +55,10 @@ def main() -> None: model = json.loads(source) vector_content: str | None = None if name in vector_models: - vectors = _protocol_vectors(model) + # Decimal keeps vector numbers exact, such as big decimal params. + vectors = _protocol_vectors(json.loads(source, parse_float=Decimal)) (destination / "vectors").mkdir(exist_ok=True) - vector_content = json.dumps(vectors, indent=2, sort_keys=True) + "\n" + vector_content = _dumps_exact(vectors) (destination / f"vectors/{name}.json").write_text(vector_content) # Protocol vectors exercise the client artifact; model traits, documentation, # operation references, and member order remain intact. @@ -103,6 +106,21 @@ def _protocol_vectors(model: dict[str, Any]) -> dict[str, Any]: return vectors +_DECIMAL = re.compile(r'"\\u0000decimal:([^"]*)"') + + +def _dumps_exact(value: object) -> str: + """JSON with each Decimal written as the number literal it was parsed from.""" + + def default(item: object) -> str: + if isinstance(item, Decimal): + return f"\u0000decimal:{item}" + raise TypeError(f"Cannot encode {type(item).__name__}") + + text = json.dumps(value, indent=2, sort_keys=True, default=default) + return _DECIMAL.sub(r"\1", text) + "\n" + + def _remove_protocol_vectors(model: dict[str, Any]) -> None: shapes: dict[str, dict[str, Any]] = model["shapes"] for trait in _VECTOR_TRAITS: diff --git a/scripts/codegen-output-py/tests/test_client_protocol_vectors.py b/scripts/codegen-output-py/tests/test_client_protocol_vectors.py index 2b95d0084..5843ee3ec 100644 --- a/scripts/codegen-output-py/tests/test_client_protocol_vectors.py +++ b/scripts/codegen-output-py/tests/test_client_protocol_vectors.py @@ -20,12 +20,13 @@ from collections.abc import Iterator from dataclasses import dataclass from datetime import UTC, datetime +from decimal import Decimal from pathlib import Path from types import ModuleType from typing import Any, cast import pytest -from smithy_cbor import loads +from smithy_cbor import loads as cbor_loads from smithy_core.aio.types import AsyncBytesReader from smithy_core.retries import SimpleRetryStrategy from smithy_core.schemas import Schema @@ -52,9 +53,28 @@ "RpcV2CborClientSkipsTopLevelDefaultValuesInInput", "RpcV2CborClientUsesExplicitlyProvidedMemberValuesOverDefaults", "RpcV2CborClientIgnoresNonTopLevelDefaultsOnMembersWithClientOptional", + "RpcV2JsonRequestClientPopulatesDefaultValuesInInput", + "RpcV2JsonRequestClientSkipsTopLevelDefaultValuesInInput", + "RpcV2JsonRequestClientUsesExplicitlyProvidedMemberValuesOverDefaults", + "RpcV2JsonRequestClientIgnoresNonTopLevelDefaultsOnMembersWithClientOptional", } ) +# How each protocol's request bodies are decoded for comparison. JSON numbers are +# read as Decimal, so big numbers compare exactly. +_BODY_DECODERS: dict[str, Any] = { + "smithy.protocols#rpcv2Cbor": cbor_loads, + "smithy.protocols#rpcv2Json": lambda body: json.loads(body, parse_float=Decimal), +} + + +def _vector_body(case: dict[str, Any]) -> bytes: + """A vector's body as bytes. Binary media types are written in base64.""" + body = case.get("body", "") + if case.get("bodyMediaType") == "application/cbor": + return base64.b64decode(body) + return body.encode() + @dataclass(frozen=True) class _Vector: @@ -69,7 +89,8 @@ def _vectors() -> Iterator[Any]: path = _INPUTS / "models/vectors" / Path(settings["model"]).name if not path.exists(): continue - for shape_id, kinds in json.loads(path.read_text()).items(): + vectors = json.loads(path.read_text(), parse_float=Decimal) + for shape_id, kinds in vectors.items(): for kind, cases in sorted(kinds.items()): for case in cases: marks = ( @@ -203,9 +224,15 @@ def _scalar(schema: Schema, value: Any) -> Any: case ShapeType.BLOB: return value.encode() if isinstance(value, str) else value case ShapeType.TIMESTAMP: - return datetime.fromtimestamp(value, UTC) + # Split exactly, so fractional seconds don't round through a float. + seconds = Decimal(value) + whole = int(seconds) + micros = int((seconds - whole) * 1_000_000) + return datetime.fromtimestamp(whole, UTC).replace(microsecond=micros) case ShapeType.FLOAT | ShapeType.DOUBLE: return float(value) + case ShapeType.BIG_DECIMAL: + return Decimal(value) case _: return value @@ -282,8 +309,8 @@ def _body(request: HTTPRequest) -> bytes: return asyncio.run(data) if asyncio.iscoroutine(data) else data -def _decoded(body: bytes) -> Any: - return loads(body) if body else {} +def _decoded(protocol: str, body: bytes) -> Any: + return _BODY_DECODERS[protocol](body) if body else {} @pytest.mark.parametrize("aio", [False, True], ids=["sync-client", "async-client"]) @@ -321,14 +348,17 @@ def _check_request( for key in case.get("requireHeaders", ()): assert actual.fields[key].values if "body" in case: - expected = base64.b64decode(case["body"]) - assert deep_equal(_decoded(_body(actual)), _decoded(expected)) + expected = _vector_body(case) + protocol = case["protocol"] + assert deep_equal( + _decoded(protocol, _body(actual)), _decoded(protocol, expected) + ) def _check_response( client: _Client, shape_id: str, case: dict[str, Any], *, aio: bool ) -> None: - body = base64.b64decode(case["body"]) if case.get("body") else b"" + body = _vector_body(case) response = HTTPResponse( status=case["code"], fields=tuples_to_fields(list(case.get("headers", {}).items())), @@ -368,5 +398,6 @@ def test_vectors_match_their_provenance() -> None: def test_every_client_vector_is_collected() -> None: - # 29 request and 43 response vectors; the Java client runs the same 72. - assert len(list(_vectors())) == 72 + # The Java clients run the same vectors: rpcv2Cbor has 29 request and 43 + # response vectors, and rpcv2Json has 34 and 39. + assert len(list(_vectors())) == 72 + 73