开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
1 Star 0 Fork 76

zhang/FastAPI

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (24)
标签 (287)
master
codex/update-issue-manager-0-8-1
translate-hi-add-missing-a37a4519
translate-hi-add-missing-51ac334b
update-dependabot-config
set-dependabot-interval-monthly
fix-response_model_---parameters-with-Iterable
check-zh-translation-prompt
fix-multiple-upload-file-in-swagger
fix-broken-links-in-index.md
translate-de-add-missing-3f9149da
translate-ja-add-missing-4420c861
translate-ko-add-missing-2ec5599d
translate-uk-add-missing-5d45eb9e
translate-pt-add-missing-f27acfbd
translate-zh-add-missing-6eac157d
translate-zh-hant-add-missing-2ac5aaff
translate-fr-add-missing-1e3f6254
translate-tr-add-missing-5286437a
translate-es-add-missing-383d2b2a
0.139.0
0.138.2
0.138.1
0.138.0
0.137.2
0.137.1
0.137.0
0.136.3
0.136.2
0.136.1
0.136.0
0.135.4
0.135.3
0.135.2
0.135.1
0.135.0
0.134.0
0.133.1
0.133.0
0.132.1
master
分支 (24)
标签 (287)
master
codex/update-issue-manager-0-8-1
translate-hi-add-missing-a37a4519
translate-hi-add-missing-51ac334b
update-dependabot-config
set-dependabot-interval-monthly
fix-response_model_---parameters-with-Iterable
check-zh-translation-prompt
fix-multiple-upload-file-in-swagger
fix-broken-links-in-index.md
translate-de-add-missing-3f9149da
translate-ja-add-missing-4420c861
translate-ko-add-missing-2ec5599d
translate-uk-add-missing-5d45eb9e
translate-pt-add-missing-f27acfbd
translate-zh-add-missing-6eac157d
translate-zh-hant-add-missing-2ac5aaff
translate-fr-add-missing-1e3f6254
translate-tr-add-missing-5286437a
translate-es-add-missing-383d2b2a
0.139.0
0.138.2
0.138.1
0.138.0
0.137.2
0.137.1
0.137.0
0.136.3
0.136.2
0.136.1
0.136.0
0.135.4
0.135.3
0.135.2
0.135.1
0.135.0
0.134.0
0.133.1
0.133.0
0.132.1
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (24)
标签 (287)
master
codex/update-issue-manager-0-8-1
translate-hi-add-missing-a37a4519
translate-hi-add-missing-51ac334b
update-dependabot-config
set-dependabot-interval-monthly
fix-response_model_---parameters-with-Iterable
check-zh-translation-prompt
fix-multiple-upload-file-in-swagger
fix-broken-links-in-index.md
translate-de-add-missing-3f9149da
translate-ja-add-missing-4420c861
translate-ko-add-missing-2ec5599d
translate-uk-add-missing-5d45eb9e
translate-pt-add-missing-f27acfbd
translate-zh-add-missing-6eac157d
translate-zh-hant-add-missing-2ac5aaff
translate-fr-add-missing-1e3f6254
translate-tr-add-missing-5286437a
translate-es-add-missing-383d2b2a
0.139.0
0.138.2
0.138.1
0.138.0
0.137.2
0.137.1
0.137.0
0.136.3
0.136.2
0.136.1
0.136.0
0.135.4
0.135.3
0.135.2
0.135.1
0.135.0
0.134.0
0.133.1
0.133.0
0.132.1
FastAPI
/
fastapi
/
utils.py
FastAPI
/
fastapi
/
utils.py
utils.py 4.24 KB
一键复制 编辑 原始数据 按行查看 历史
import re
import warnings
from typing import (
TYPE_CHECKING,
Any,
Literal,
)
import fastapi
from fastapi._compat import (
ModelField,
PydanticSchemaGenerationError,
Undefined,
annotation_is_pydantic_v1,
)
from fastapi.datastructures import DefaultPlaceholder, DefaultType
from fastapi.exceptions import FastAPIDeprecationWarning, PydanticV1NotSupportedError
from pydantic.fields import FieldInfo
from ._compat import v2
if TYPE_CHECKING: # pragma: nocover
from .routing import APIRoute
def is_body_allowed_for_status_code(status_code: int | str | None) -> bool:
if status_code is None:
return True
# Ref: https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#patterned-fields-1
if status_code in {
"default",
"1XX",
"2XX",
"3XX",
"4XX",
"5XX",
}:
return True
current_status_code = int(status_code)
return not (current_status_code < 200 or current_status_code in {204, 205, 304})
def get_path_param_names(path: str) -> set[str]:
return set(re.findall("{(.*?)}", path))
_invalid_args_message = (
"Invalid args for response field! Hint: "
"check that {type_} is a valid Pydantic field type. "
"If you are using a return type annotation that is not a valid Pydantic "
"field (e.g. Union[Response, dict, None]) you can disable generating the "
"response model from the type annotation with the path operation decorator "
"parameter response_model=None. Read more: "
"https://fastapi.tiangolo.com/tutorial/response-model/"
)
def create_model_field(
name: str,
type_: Any,
default: Any | None = Undefined,
field_info: FieldInfo | None = None,
alias: str | None = None,
mode: Literal["validation", "serialization"] = "validation",
) -> ModelField:
if annotation_is_pydantic_v1(type_):
raise PydanticV1NotSupportedError(
"pydantic.v1 models are no longer supported by FastAPI."
f" Please update the response model {type_!r}."
)
field_info = field_info or FieldInfo(annotation=type_, default=default, alias=alias)
try:
return v2.ModelField(mode=mode, name=name, field_info=field_info)
except PydanticSchemaGenerationError:
raise fastapi.exceptions.FastAPIError(
_invalid_args_message.format(type_=type_)
) from None
def generate_operation_id_for_path(
*, name: str, path: str, method: str
) -> str: # pragma: nocover
warnings.warn(
message="fastapi.utils.generate_operation_id_for_path() was deprecated, "
"it is not used internally, and will be removed soon",
category=FastAPIDeprecationWarning,
stacklevel=2,
)
operation_id = f"{name}{path}"
operation_id = re.sub(r"\W", "_", operation_id)
operation_id = f"{operation_id}_{method.lower()}"
return operation_id
def generate_unique_id(route: "APIRoute") -> str:
operation_id = f"{route.name}{route.path_format}"
operation_id = re.sub(r"\W", "_", operation_id)
assert route.methods
operation_id = f"{operation_id}_{list(route.methods)[0].lower()}"
return operation_id
def deep_dict_update(main_dict: dict[Any, Any], update_dict: dict[Any, Any]) -> None:
for key, value in update_dict.items():
if (
key in main_dict
and isinstance(main_dict[key], dict)
and isinstance(value, dict)
):
deep_dict_update(main_dict[key], value)
elif (
key in main_dict
and isinstance(main_dict[key], list)
and isinstance(update_dict[key], list)
):
main_dict[key] = main_dict[key] + update_dict[key]
else:
main_dict[key] = value
def get_value_or_default(
first_item: DefaultPlaceholder | DefaultType,
*extra_items: DefaultPlaceholder | DefaultType,
) -> DefaultPlaceholder | DefaultType:
"""
Pass items or `DefaultPlaceholder`s by descending priority.
The first one to _not_ be a `DefaultPlaceholder` will be returned.
Otherwise, the first item (a `DefaultPlaceholder`) will be returned.
"""
items = (first_item,) + extra_items
for item in items:
if not isinstance(item, DefaultPlaceholder):
return item
return first_item
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

FastAPI 是一个高性能 Web 框架,用于构建 API
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/zhang192/FastAPI.git
git@gitee.com:zhang192/FastAPI.git
zhang192
FastAPI
FastAPI
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /