From 68664c581f044e8de0b77fdf94ff3ac7df72a8f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=B5=E3=81=81?= Date: Tue, 13 Jun 2023 14:56:57 +0900 Subject: [PATCH] add AddPathQueryIdOnParameters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ふぁ --- tools/hooks.py | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/tools/hooks.py b/tools/hooks.py index b3c0030..4b97b41 100644 --- a/tools/hooks.py +++ b/tools/hooks.py @@ -58,15 +58,17 @@ class HookBase: class OpenapiHookBase(HookBase): - def hook(self, value: dict)->dict: + def hook(self, value: dict) -> dict: return value + class OtherHookBase(HookBase): - def hook(self)->tuple[str, dict]: - return "", {} + def hook(self) -> tuple[str, dict]: + return "", {} + class SchemasHookBase(HookBase): - def hook(self, value: dict)->dict: + def hook(self, value: dict) -> dict: return value @@ -78,7 +80,7 @@ class RequestHookBase(HookBase): super().__init__() self.split = split - def hook(self, path: str, value: dict)->tuple[str, dict]: + def hook(self, path: str, value: dict) -> tuple[str, dict]: value["parameters"] = value.get("parameters", []) self.path_name = "/".join(path.split("/")[self.split :]) return path, value @@ -118,6 +120,14 @@ class AddSecuritySchemesOnHeader(RequestHookBase): value["parameters"].extend(param) return path, value + +class ReplaceQueryIdPlaceholder(RequestHookBase): + def hook(self, path: str, value: dict): + path, value = super().hook(path, value) + new = self.PLACEHOLDER[self.path_name]["queryId"] + return path.replace(r"{pathQueryId}", new), value + + class SetResponsesHeader(RequestHookBase): suffix: str @@ -132,6 +142,28 @@ class SetResponsesHeader(RequestHookBase): return path, value +class AddPathQueryIdOnParameters(RequestHookBase): + def __init__(self, split: str = 1): + super().__init__(split=split) + + def hook(self, path: str, value: dict): + path, value = super().hook(path, value) + data = self.PLACEHOLDER[self.path_name] + value["parameters"].append( + { + "in": "path", + "name": "pathQueryId", + "required": True, + "schema": { + "type": "string", + "default": data["queryId"], + "example": data["queryId"], + }, + } + ) + return path, value + + # OnParameters