1
Fork 0
mirror of https://github.com/thegeneralist01/twitter-openapi synced 2026-01-11 15:40:26 +01:00

add AddPathQueryIdOnParameters

Signed-off-by: ふぁ <yuki@yuki0311.com>
This commit is contained in:
ふぁ 2023-06-13 14:56:57 +09:00
parent 7706204624
commit 68664c581f
No known key found for this signature in database
GPG key ID: 83A8A5E74872A8AA

View file

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