Skip to content
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

Fix formats in fastapi/utils #5075

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion fastapi/dependencies/utils.py
Expand Up @@ -721,7 +721,7 @@ def get_body_field(*, dependant: Dependant, name: str) -> Optional[ModelField]:
# That is combined (embedded) with other body fields
for param in flat_dependant.body_params:
setattr(param.field_info, "embed", True)
model_name = "Body_" + name
model_name = f"Body_{name}"
BodyModel: Type[BaseModel] = create_model(model_name)
for f in flat_dependant.body_params:
BodyModel.__fields__[f.name] = f
Expand Down
17 changes: 7 additions & 10 deletions fastapi/utils.py
Expand Up @@ -51,22 +51,20 @@ def create_response_field(
"""
Create a new response field. Raises if type_ is invalid.
"""
class_validators = class_validators or {}
field_info = field_info or FieldInfo()

response_field = functools.partial(
ModelField,
name=name,
type_=type_,
class_validators=class_validators,
class_validators=class_validators or {},
default=default,
required=required,
model_config=model_config,
alias=alias,
)

try:
return response_field(field_info=field_info)
_info = field_info or FieldInfo()
return response_field(field_info=_info)
except RuntimeError:
raise fastapi.exceptions.FastAPIError(
f"Invalid args for response field! Hint: check that {type_} is a valid pydantic field type"
Expand Down Expand Up @@ -134,16 +132,15 @@ def generate_operation_id_for_path(
)
operation_id = name + path
operation_id = re.sub("[^0-9a-zA-Z_]", "_", operation_id)
operation_id = operation_id + "_" + method.lower()
operation_id = f"{operation_id}_{method.lower()}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And therefor, I would also be supporting it here.

return operation_id


def generate_unique_id(route: "APIRoute") -> str:
operation_id = route.name + route.path_format
operation_id = re.sub("[^0-9a-zA-Z_]", "_", operation_id)
route_path_name = route.name + route.path_format
operation_id = re.sub("[^0-9a-zA-Z_]", "_", route_path_name)
assert route.methods
operation_id = operation_id + "_" + list(route.methods)[0].lower()
return operation_id
return f"{operation_id}_{list(route.methods)[0].lower()}"


def deep_dict_update(main_dict: Dict[Any, Any], update_dict: Dict[Any, Any]) -> None:
Expand Down