-
Notifications
You must be signed in to change notification settings - Fork 24
Add HTTP Binding serializers and deserializers #400
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
Changes from all commits
8953f74
a4f9e25
e672578
d9a63b7
789c48e
9077d30
ccae6a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,11 +7,11 @@ | |
| # they're correct regardless, so it's okay if the checks are stripped out. | ||
| # ruff: noqa: S101 | ||
|
|
||
| from dataclasses import dataclass | ||
| from dataclasses import dataclass, field | ||
| from enum import Enum | ||
| from typing import TYPE_CHECKING, ClassVar | ||
| from typing import TYPE_CHECKING, ClassVar, Mapping | ||
|
|
||
| from .types import TimestampFormat | ||
| from .types import TimestampFormat, PathPattern | ||
| from .shapes import ShapeID | ||
|
|
||
| if TYPE_CHECKING: | ||
|
|
@@ -193,3 +193,117 @@ def __post_init__(self): | |
| @property | ||
| def value(self) -> str: | ||
| return self.document_value # type: ignore | ||
|
|
||
|
|
||
| # TODO: Get all this moved over to the http package | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it need to be? I don't think we need to put traits in their "respective" packages
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd tend to agree with this, I think the other PR we moved everything into the centralized location. I like that unless we have a technical limitation of keeping them together. Is the concern that we may include traits that aren't needed if the smithy-http package isn't present, or are we hitting typing problems?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's more about fighting against package size inflation, though practically for HTTP it's not much of an issue. |
||
| @dataclass(init=False, frozen=True) | ||
| class HTTPTrait(Trait, id=ShapeID("smithy.api#http")): | ||
| path: PathPattern = field(repr=False, hash=False, compare=False) | ||
| code: int = field(repr=False, hash=False, compare=False) | ||
| query: str | None = field(default=None, repr=False, hash=False, compare=False) | ||
|
|
||
| def __init__(self, value: "DocumentValue | DynamicTrait" = None): | ||
| super().__init__(value) | ||
| assert isinstance(self.document_value, Mapping) | ||
| assert isinstance(self.document_value["method"], str) | ||
|
|
||
| code = self.document_value.get("code", 200) | ||
| assert isinstance(code, int) | ||
| object.__setattr__(self, "code", code) | ||
|
|
||
| uri = self.document_value["uri"] | ||
| assert isinstance(uri, str) | ||
| parts = uri.split("?", 1) | ||
|
|
||
| object.__setattr__(self, "path", PathPattern(parts[0])) | ||
| object.__setattr__(self, "query", parts[1] if len(parts) == 2 else None) | ||
|
|
||
| @property | ||
| def method(self) -> str: | ||
| return self.document_value["method"] # type: ignore | ||
|
|
||
|
|
||
| @dataclass(init=False, frozen=True) | ||
| class HTTPErrorTrait(Trait, id=ShapeID("smithy.api#httpError")): | ||
| def __post_init__(self): | ||
| assert isinstance(self.document_value, int) | ||
|
|
||
| @property | ||
| def code(self) -> int: | ||
| return self.document_value # type: ignore | ||
|
|
||
|
|
||
| @dataclass(init=False, frozen=True) | ||
| class HTTPHeaderTrait(Trait, id=ShapeID("smithy.api#httpHeader")): | ||
| def __post_init__(self): | ||
| assert isinstance(self.document_value, str) | ||
|
|
||
| @property | ||
| def key(self) -> str: | ||
| return self.document_value # type: ignore | ||
|
|
||
|
|
||
| @dataclass(init=False, frozen=True) | ||
| class HTTPLabelTrait(Trait, id=ShapeID("smithy.api#httpLabel")): | ||
| def __post_init__(self): | ||
| assert self.document_value is None | ||
|
|
||
|
|
||
| @dataclass(init=False, frozen=True) | ||
| class HTTPPayloadTrait(Trait, id=ShapeID("smithy.api#httpPayload")): | ||
| def __post_init__(self): | ||
| assert self.document_value is None | ||
|
|
||
|
|
||
| @dataclass(init=False, frozen=True) | ||
| class HTTPPrefixHeadersTrait(Trait, id=ShapeID("smithy.api#httpPrefixHeaders")): | ||
| def __post_init__(self): | ||
| assert isinstance(self.document_value, str) | ||
|
|
||
| @property | ||
| def prefix(self) -> str: | ||
| return self.document_value # type: ignore | ||
|
|
||
|
|
||
| @dataclass(init=False, frozen=True) | ||
| class HTTPQueryTrait(Trait, id=ShapeID("smithy.api#httpQuery")): | ||
| def __post_init__(self): | ||
| assert isinstance(self.document_value, str) | ||
|
|
||
| @property | ||
| def key(self) -> str: | ||
| return self.document_value # type: ignore | ||
|
|
||
|
|
||
| @dataclass(init=False, frozen=True) | ||
| class HTTPQueryParamsTrait(Trait, id=ShapeID("smithy.api#httpQueryParams")): | ||
| def __post_init__(self): | ||
| assert self.document_value is None | ||
|
|
||
|
|
||
| @dataclass(init=False, frozen=True) | ||
| class HTTPResponseCodeTrait(Trait, id=ShapeID("smithy.api#httpResponseCode")): | ||
| def __post_init__(self): | ||
| assert self.document_value is None | ||
|
|
||
|
|
||
| @dataclass(init=False, frozen=True) | ||
| class HTTPChecksumRequiredTrait(Trait, id=ShapeID("smithy.api#httpChecksumRequired")): | ||
| def __post_init__(self): | ||
| assert self.document_value is None | ||
|
|
||
|
|
||
| @dataclass(init=False, frozen=True) | ||
| class EndpointTrait(Trait, id=ShapeID("smithy.api#endpoint")): | ||
| def __post_init__(self): | ||
| assert isinstance(self.document_value, str) | ||
|
|
||
| @property | ||
| def host_prefix(self) -> str: | ||
| return self.document_value["hostPrefix"] # type: ignore | ||
|
|
||
|
|
||
| @dataclass(init=False, frozen=True) | ||
| class HostLabelTrait(Trait, id=ShapeID("smithy.api#hostLabel")): | ||
| def __post_init__(self): | ||
| assert self.document_value is None | ||
Uh oh!
There was an error while loading. Please reload this page.