-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Upgrade pydantic>=2.0, flask>=3.0
- Loading branch information
Michal Korbela
committed
Nov 6, 2023
1 parent
d19a00e
commit 829e069
Showing
14 changed files
with
467 additions
and
407 deletions.
There are no files selected for viewing
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,6 +1,6 @@ | ||
from flask_ninja.api import NinjaAPI, Server | ||
from flask_ninja.constants import ParamType | ||
from flask_ninja.operation import ApiConfigError, Callback, Operation | ||
from flask_ninja.param_functions import Header, Path, Query | ||
from flask_ninja.param_functions import Body, Header, Path, Query | ||
from flask_ninja.router import Router | ||
from flask_ninja.security import HttpAuthBase, HttpBearer |
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
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import types | ||
from dataclasses import dataclass | ||
from typing import Annotated, Any, Dict, List, Literal, Sequence, Set, Tuple, Union | ||
|
||
from pydantic import TypeAdapter | ||
from pydantic.fields import FieldInfo | ||
from pydantic.json_schema import JsonSchemaValue | ||
from pydantic_core import PydanticUndefined, PydanticUndefinedType | ||
|
||
Required = PydanticUndefined | ||
Undefined = PydanticUndefined | ||
UndefinedType = PydanticUndefinedType | ||
IncEx = Union[Set[int], Set[str], Dict[int, Any], Dict[str, Any]] | ||
UnionType = getattr(types, "UnionType", Union) | ||
|
||
|
||
@dataclass | ||
class ModelField: | ||
field_info: FieldInfo | ||
name: str | ||
mode: Literal["validation", "serialization"] = "validation" | ||
|
||
@property | ||
def alias(self) -> str: | ||
a = self.field_info.alias | ||
return a if a is not None else self.name | ||
|
||
@property | ||
def required(self) -> bool: | ||
return self.field_info.is_required() | ||
|
||
@property | ||
def default(self) -> Any: | ||
return self.get_default() | ||
|
||
@property | ||
def type_(self) -> Any: | ||
return self.field_info.annotation | ||
|
||
def __post_init__(self) -> None: | ||
self.type_adapter: TypeAdapter[Any] = TypeAdapter( | ||
Annotated[self.field_info.annotation, self.field_info] | ||
) | ||
|
||
def get_default(self) -> Any: | ||
if self.field_info.is_required(): | ||
return Undefined | ||
return self.field_info.get_default(call_default_factory=True) | ||
|
||
def __hash__(self) -> int: | ||
# Each ModelField is unique for our purposes, to allow making a dict from | ||
# ModelField to its JSON Schema. | ||
return id(self) | ||
|
||
|
||
def _regenerate_error_with_loc( | ||
*, errors: Sequence[Any], loc_prefix: Tuple[Union[str, int], ...] | ||
) -> List[Dict[str, Any]]: | ||
updated_loc_errors: List[Any] = [ | ||
{**err, "loc": loc_prefix + err.get("loc", ())} for err in errors | ||
] | ||
|
||
return updated_loc_errors | ||
|
||
|
||
FieldMapping = Dict[ | ||
tuple[ModelField, Literal["validation", "serialization"]], JsonSchemaValue | ||
] |
Oops, something went wrong.