Skip to content

Commit

Permalink
Documentation: list roles that are allowed to call a method (#15380)
Browse files Browse the repository at this point in the history
  • Loading branch information
themylogin authored Jan 13, 2025
1 parent c2363f6 commit ab0edee
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/middlewared/middlewared/api/base/server/doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class APIDump(BaseModel):

class APIDumpMethod(BaseModel):
name: str
roles: list[str]
doc: str | None
schemas: dict

Expand Down Expand Up @@ -64,6 +65,7 @@ def _dump_method(self, method: Method):

return APIDumpMethod(
name=name,
roles=method.methodobj.roles,
doc=doc,
schemas=self._dump_method_schemas(method),
)
Expand Down
6 changes: 5 additions & 1 deletion src/middlewared_docs/generate_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ def _generate_method_rst(self, method: APIDumpMethod, method_schemas_html: str):
result += f"{method.doc}\n\n"

result += f".. raw:: html\n\n"
result += textwrap.indent(f"<div id=\"json-schema\">" + method_schemas_html + "</div>", " " * 4) + "\n\n"
result += textwrap.indent(
f"<div id=\"json-schema\">" + method_schemas_html + "</div><br><br>", " " * 4
) + "\n\n"

result += "*Required roles:* " + " | ".join(method.roles) + "\n\n"

return result

Expand Down

0 comments on commit ab0edee

Please sign in to comment.