diff --git a/collect_api_endpoints.in b/collect_api_endpoints.in index efda08fe..b37a1518 100644 --- a/collect_api_endpoints.in +++ b/collect_api_endpoints.in @@ -5,7 +5,7 @@ :header: "Method", "Module", "Controller", "Command", "Parameters" :widths: 4, 15, 15, 30, 40 {% for endpoint in controller.endpoints %} - "``{{endpoint.method}}``","{{controller.module}}","{{controller.controller}}","{{endpoint.command}}","{{endpoint.parameters}}" + "``{{endpoint.methods|join(',')}}``","{{controller.module}}","{{controller.controller}}","{{endpoint.command}}","{{endpoint.parameters}}" {%- endfor %} {%- if controller.uses %} {% for use in controller.uses %} diff --git a/lib/__init__.py b/lib/__init__.py index 4b25110e..4473570c 100644 --- a/lib/__init__.py +++ b/lib/__init__.py @@ -7,13 +7,13 @@ from lib.phply.phplex import lexer from lib.phply.phpparse import make_parser -HttpMethod = Literal["GET", "POST", "GET,POST"] +HttpMethod = Literal["GET", "POST"] ControllerType = Literal["Abstract [non-callable]", "Service", "Resources"] class Action(BaseModel): command: str parameters: str - method: HttpMethod + methods: list[HttpMethod] model_path: str | None = None class Controller(BaseModel): @@ -31,32 +31,32 @@ DEFAULT_BASE_METHODS = { "ApiMutableModelControllerBase": [Action( command="set", parameters="", - method="POST", + methods=["POST"], ), Action( command="get", parameters="", - method="GET", + methods=["GET"], )], "ApiMutableServiceControllerBase": [Action( command="status", parameters="", - method="GET", + methods=["GET"], ), Action( command="start", parameters="", - method="POST", + methods=["POST"], ), Action( command="stop", parameters="", - method="POST", + methods=["POST"], ), Action( command="restart", parameters="", - method="POST", + methods=["POST"], ), Action( command="reconfigure", parameters="", - method="POST", + methods=["POST"], )] } @@ -133,12 +133,10 @@ class ApiParser: detected_methods.add('POST') default_method = 'POST' if cmd == 'set' else 'GET' - method = 'GET,POST' if len(detected_methods) > 1 else detected_methods.pop() if detected_methods else default_method - self.api_commands[cmd] = Action( command=cmd, parameters=','.join(params), - method=method, + methods=sorted(detected_methods) if detected_methods else [default_method], model_path=model_path, ) diff --git a/source/development/api/core/firewall.rst.in b/source/development/api/core/firewall.rst.in index 63ca2294..af6eb5dd 100644 --- a/source/development/api/core/firewall.rst.in +++ b/source/development/api/core/firewall.rst.in @@ -20,7 +20,7 @@ as a reference and testbed. There's no relation to any of the rules being manage :header: "Method", "Module", "Controller", "Command", "Parameters" :widths: 4, 15, 15, 30, 40 {% for endpoint in controller.endpoints %} - "``{{endpoint.method}}``","{{controller.module}}","{{controller.controller}}","{{endpoint.command}}","{{endpoint.parameters}}" + "``{{endpoint.methods|join(',')}}``","{{controller.module}}","{{controller.controller}}","{{endpoint.command}}","{{endpoint.parameters}}" {%- endfor %} {%- if controller.uses %} {% for use in controller.uses %}