Skip to content

Support empty restJson1 trait #500

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/smithy-aws-core/src/smithy_aws_core/traits.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ class RestJson1Trait(Trait, id=ShapeID("aws.protocols#restJson1")):

def __init__(self, value: DocumentValue | DynamicTrait = None):
super().__init__(value)
assert isinstance(self.document_value, Mapping)
document_value = value or {}
assert isinstance(document_value, Mapping)

http_versions = self.document_value["http"]
http_versions = document_value.get("http", ["http/1.1"])
assert isinstance(http_versions, Sequence)
for val in http_versions:
assert isinstance(val, str)
object.__setattr__(self, "http", tuple(http_versions))
event_stream_http_versions = self.document_value.get("eventStreamHttp")
event_stream_http_versions = document_value.get("eventStreamHttp")
if not event_stream_http_versions:
object.__setattr__(self, "event_stream_http", self.http)
else:
Expand Down
9 changes: 9 additions & 0 deletions packages/smithy-aws-core/tests/unit/test_traits.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

from smithy_aws_core.traits import RestJson1Trait


def test_allows_empty_restjson1_value() -> None:
trait = RestJson1Trait(None)
assert trait.http == ("http/1.1",)