generated from yanyongyu/python-poetry-template
-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Feature: introduce api versioning, lazy loading and webhook namespa…
…ce (#73)
- Loading branch information
Showing
182 changed files
with
233,575 additions
and
66,306 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,53 @@ | ||
from typing import Any, Dict, List | ||
from typing import Any | ||
from pathlib import Path | ||
|
||
from pydantic import Field, BaseModel | ||
|
||
|
||
class Overridable(BaseModel): | ||
class_overrides: Dict[str, str] = Field(default_factory=dict) | ||
field_overrides: Dict[str, str] = Field(default_factory=dict) | ||
schema_overrides: Dict[str, Dict[str, Any]] = Field(default_factory=dict) | ||
class Override(BaseModel): | ||
class_overrides: dict[str, str] = Field(default_factory=dict) | ||
field_overrides: dict[str, str] = Field(default_factory=dict) | ||
schema_overrides: dict[str, dict[str, Any]] = Field(default_factory=dict) | ||
|
||
|
||
class RestConfig(Overridable): | ||
version: str | ||
description_source: str | ||
output_dir: str | ||
|
||
class VersionedOverride(Override): | ||
target_versions: list[str] = Field(default_factory=list) | ||
|
||
class WebhookConfig(Overridable): | ||
schema_source: str | ||
output: str | ||
types_output: str | ||
|
||
|
||
class Config(Overridable): | ||
rest: List[RestConfig] | ||
webhook: WebhookConfig | ||
class DescriptionConfig(BaseModel): | ||
version: str | ||
is_latest: bool = False | ||
"""If true, the description will be used as the default description.""" | ||
source: str | ||
|
||
|
||
class Config(BaseModel): | ||
output_dir: Path | ||
legacy_rest_models: Path | ||
version_prefix: str = "v" | ||
descriptions: list[DescriptionConfig] | ||
overrides: list[VersionedOverride] = Field(default_factory=list) | ||
|
||
def get_override_config_for_version(self, version: str) -> Override: | ||
selected_overrides = [ | ||
override | ||
for override in self.overrides | ||
if version in override.target_versions or not override.target_versions | ||
] | ||
return Override( | ||
class_overrides={ | ||
key: value | ||
for override in selected_overrides | ||
for key, value in override.class_overrides.items() | ||
}, | ||
field_overrides={ | ||
key: value | ||
for override in selected_overrides | ||
for key, value in override.field_overrides.items() | ||
}, | ||
schema_overrides={ | ||
key: value | ||
for override in selected_overrides | ||
for key, value in override.schema_overrides.items() | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.