Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "bugfix",
"description": "Fixed the registered Smithy IDs for `DefaultTrait`, `IdempotencyTokenTrait`, and `UnitTypeTrait` so schemas resolve these traits correctly."
}
6 changes: 3 additions & 3 deletions packages/smithy-core/src/smithy_core/traits.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def new(id: ShapeID, value: "DocumentValue" = None) -> "Trait | DynamicTrait":


@dataclass(init=False, frozen=True)
class DefaultTrait(Trait, id=ShapeID("smithy.appi#default")):
class DefaultTrait(Trait, id=ShapeID("smithy.api#default")):
@property
def value(self) -> "DocumentValue":
return self.document_value
Expand Down Expand Up @@ -161,7 +161,7 @@ def __post_init__(self):


@dataclass(init=False, frozen=True)
class UnitTypeTrait(Trait, id=ShapeID("smithy.api#UnitTypeTrait")):
class UnitTypeTrait(Trait, id=ShapeID("smithy.api#unitType")):
def __post_init__(self):
assert self.document_value is None

Expand Down Expand Up @@ -203,7 +203,7 @@ def value(self) -> str:


@dataclass(init=False, frozen=True)
class IdempotencyTokenTrait(Trait, id=ShapeID("smithy.api#IdempotencyToken")):
class IdempotencyTokenTrait(Trait, id=ShapeID("smithy.api#idempotencyToken")):
def __post_init__(self):
assert self.document_value is None

Expand Down
30 changes: 29 additions & 1 deletion packages/smithy-core/tests/unit/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
from typing import Any

import pytest
from smithy_core.documents import TypeRegistry
from smithy_core.exceptions import ExpectationNotMetError
from smithy_core.schemas import Schema
from smithy_core.schemas import APIOperation, Schema
from smithy_core.shapes import ShapeID, ShapeType
from smithy_core.traits import (
DynamicTrait,
InternalTrait,
SensitiveTrait,
Trait,
)

ID: ShapeID = ShapeID("ns.foo#bar")
Expand Down Expand Up @@ -171,3 +173,29 @@ def test_contains(item: Any, contains: bool):
)

assert (item in schema) == contains


def test_operation_idempotency_token_member():
input_schema = Schema.collection(
id=ShapeID("com.example#OperationInput"),
members={
"other": {"target": STRING},
"token": {
"target": STRING,
"traits": [Trait.new(id=ShapeID("smithy.api#idempotencyToken"))],
},
},
)
operation = APIOperation[Any, Any](
input=object,
output=object,
schema=Schema(
id=ShapeID("com.example#Operation"), shape_type=ShapeType.OPERATION
),
input_schema=input_schema,
output_schema=input_schema,
error_registry=TypeRegistry({}),
effective_auth_schemes=[],
error_schemas=[],
)
assert operation.idempotency_token_member is input_schema.members["token"]
14 changes: 14 additions & 0 deletions packages/smithy-core/tests/unit/test_traits.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
from dataclasses import dataclass

import pytest
from smithy_core.prelude import UNIT
from smithy_core.shapes import ShapeID
from smithy_core.traits import (
DefaultTrait,
DynamicTrait,
ErrorFault,
ErrorTrait,
JSONNameTrait,
Trait,
UnitTypeTrait,
)


Expand Down Expand Up @@ -40,6 +43,17 @@ class NewTrait(Trait, id=trait_id):
assert NewTrait.id is trait_id


def test_trait_factory_constructs_default_trait():
trait = Trait.new(ShapeID("smithy.api#default"), 0)
assert isinstance(trait, DefaultTrait)
assert trait.value == 0


def test_unit_schema_uses_canonical_trait_id():
trait = UNIT.get_trait(ShapeID("smithy.api#unitType"))
assert isinstance(trait, UnitTypeTrait)


def test_cant_construct_base_trait():
with pytest.raises(TypeError):
Trait("foo")
Expand Down
Loading