Complete backend MVP
This commit is contained in:
@@ -30,10 +30,31 @@ def operation_id(controller: str, handler: str) -> str:
|
||||
|
||||
def openapi_path(path: str) -> tuple[str, list[dict[str, Any]]]:
|
||||
parameters: list[dict[str, Any]] = []
|
||||
segments = path.split("/")
|
||||
placeholder_names: dict[int, str] = {}
|
||||
|
||||
for position, segment in enumerate(segments):
|
||||
match = re.fullmatch(r"\{(\d+)\}", segment)
|
||||
if not match:
|
||||
continue
|
||||
|
||||
index = int(match.group(1))
|
||||
if index == 1:
|
||||
placeholder_names[index] = "id"
|
||||
continue
|
||||
|
||||
previous = segments[position - 1] if position > 0 else ""
|
||||
if previous.endswith("ies"):
|
||||
stem = previous[:-3] + "y"
|
||||
elif previous.endswith("s") and len(previous) > 1:
|
||||
stem = previous[:-1]
|
||||
else:
|
||||
stem = previous or f"param{index}"
|
||||
placeholder_names[index] = f"{stem}_id"
|
||||
|
||||
def replace(match: re.Match[str]) -> str:
|
||||
index = int(match.group(1))
|
||||
name = "id" if index == 1 else f"param{index}"
|
||||
name = placeholder_names.get(index, f"param{index}")
|
||||
parameters.append(
|
||||
{
|
||||
"name": name,
|
||||
|
||||
Reference in New Issue
Block a user