Skip to content

Commit

Permalink
Automatically set operation_id, tags and response_model
Browse files Browse the repository at this point in the history
  • Loading branch information
sayanarijit committed Dec 22, 2023
1 parent a57d210 commit 507f4ca
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion apphelpers/rest/fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,20 @@ def choose_router(self, f):
return self.secure_router if login_required else self.router

def build(self, method, method_args, method_kw, f):
module = f.__module__.split(".")[-1].strip("_")
name = f.__name__.strip("_")
return_type = inspect.signature(f).return_annotation

if "operation_id" not in method_kw:
method_kw["operation_id"] = f"{ep}_{module}"
if "tags" not in method_kw:
method_kw["tags"] = [module]
if "response_model" not in method_kw and "response_class" not in method_kw:
method_kw["response_model"] = return_type

print(
f"{method_args[0]}",
f"[{method.__name__.upper()}] => {f.__module__}:{f.__name__}",
f"[{method.__name__.upper()}] => {module}:{name}",
)
m = method(*method_args, **method_kw)
f = self.access_wrapper(
Expand Down

0 comments on commit 507f4ca

Please sign in to comment.