Python FAST-API中头方法的convert_下划线是如何工作的?
下面是Python FAST-API中头方法的convert_下划线是如何工作的?,python,fastapi,Python,Fastapi,下面是param_functions.py def头(#noqa:N802 默认值:Any, *, 别名:可选[str]=None, 转换下划线:bool=True, 标题:可选[str]=无, 说明:可选[str]=无, gt:可选[浮动]=无, ge:可选[浮动]=无, lt:可选[浮动]=无, le:可选[浮动]=无, 最小长度:可选[int]=无, 最大长度:可选[int]=无, 正则表达式:可选[str]=None, 不推荐使用:可选[bool]=无, **额外:任何, )->任何:
param_functions.py
def头(#noqa:N802
默认值:Any,
*,
别名:可选[str]=None,
转换下划线:bool=True,
标题:可选[str]=无,
说明:可选[str]=无,
gt:可选[浮动]=无,
ge:可选[浮动]=无,
lt:可选[浮动]=无,
le:可选[浮动]=无,
最小长度:可选[int]=无,
最大长度:可选[int]=无,
正则表达式:可选[str]=None,
不推荐使用:可选[bool]=无,
**额外:任何,
)->任何:
返回参数头(
违约
别名=别名,
convert_下划线=convert_下划线,
头衔,
描述=描述,
gt=gt,
ge=ge,
lt=lt,
乐=乐,
最小长度=最小长度,
最大长度=最大长度,
regex=regex,
弃用的,
**额外的,
)
下面是params.py
类标题(参数):
in=ParamTypes.header
定义初始化__(
自己
默认值:Any,
*,
别名:可选[str]=None,
转换下划线:bool=True,
标题:可选[str]=无,
说明:可选[str]=无,
gt:可选[浮动]=无,
ge:可选[浮动]=无,
lt:可选[浮动]=无,
le:可选[浮动]=无,
最小长度:可选[int]=无,
最大长度:可选[int]=无,
正则表达式:可选[str]=None,
不推荐使用:可选[bool]=无,
**额外:任何,
):
self.convert\u下划线=convert\u下划线
超级()。\uuu初始化__(
违约
别名=别名,
头衔,
描述=描述,
gt=gt,
ge=ge,
lt=lt,
乐=乐,
最小长度=最小长度,
最大长度=最大长度,
regex=regex,
弃用的,
**额外的,
)
我尝试了FAST-API的头方法。
现在我很好奇
如果我在Header方法中设置convert_下划线=False,FAST-API不会将连字符转换为下划线。所以我认为convert_下划线只是转换的标志
它是如何工作的?用连字符替换下划线的逻辑在函数中完成:
if not field_info.alias and getattr(field_info, "convert_underscores", None):
alias = param.name.replace("_", "-")