Skip to content

Commit 60ed63f

Browse files
authored
smithy-core: add xml binding traits (smithy-lang#664)
1 parent 9da92ea commit 60ed63f

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "enhancement",
3+
"description": "Added XML binding traits: `XMLNameTrait`, `XMLNamespaceTrait`, `XMLFlattenedTrait`, and `XMLAttributeTrait`."
4+
}

packages/smithy-core/src/smithy_core/traits.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,3 +350,43 @@ def name(self) -> str:
350350
@property
351351
def scheme(self) -> str | None:
352352
return self.document_value.get("scheme") # type: ignore
353+
354+
355+
@dataclass(init=False, frozen=True)
356+
class XMLNameTrait(Trait, id=ShapeID("smithy.api#xmlName")):
357+
document_value: str | None = None
358+
359+
def __post_init__(self):
360+
assert isinstance(self.document_value, str)
361+
362+
@property
363+
def value(self) -> str:
364+
return self.document_value # type: ignore
365+
366+
367+
@dataclass(init=False, frozen=True)
368+
class XMLNamespaceTrait(Trait, id=ShapeID("smithy.api#xmlNamespace")):
369+
def __post_init__(self):
370+
assert isinstance(self.document_value, Mapping)
371+
assert isinstance(self.document_value["uri"], str)
372+
assert isinstance(self.document_value.get("prefix"), str | None)
373+
374+
@property
375+
def uri(self) -> str:
376+
return self.document_value["uri"] # type: ignore
377+
378+
@property
379+
def prefix(self) -> str | None:
380+
return self.document_value.get("prefix") # type: ignore
381+
382+
383+
@dataclass(init=False, frozen=True)
384+
class XMLFlattenedTrait(Trait, id=ShapeID("smithy.api#xmlFlattened")):
385+
def __post_init__(self):
386+
assert self.document_value is None
387+
388+
389+
@dataclass(init=False, frozen=True)
390+
class XMLAttributeTrait(Trait, id=ShapeID("smithy.api#xmlAttribute")):
391+
def __post_init__(self):
392+
assert self.document_value is None

0 commit comments

Comments
 (0)