change Action.method to Action.methods as this can be a list of (unique) options. for https://github.com/opnsense/docs/pull/713

This commit is contained in:
Ad Schellevis 2025-05-04 17:03:08 +02:00
parent f7a0d79a0c
commit ed4048d011
3 changed files with 12 additions and 14 deletions

View File

@ -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 %}

View File

@ -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,
)

View File

@ -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 %}