mirror of
https://github.com/thegeneralist01/twitter-openapi
synced 2026-01-11 23:50:26 +01:00
update hooks
Signed-off-by: ふぁ <yuki@yuki0311.com>
This commit is contained in:
parent
982181af54
commit
a69582289e
1 changed files with 88 additions and 62 deletions
150
tools/hooks.py
150
tools/hooks.py
|
|
@ -117,98 +117,124 @@ class SetResponsesHeader(RequestHookBase):
|
||||||
return path, value
|
return path, value
|
||||||
|
|
||||||
|
|
||||||
class AddParametersOnParametersAsString(RequestHookBase):
|
# OnParameters
|
||||||
|
|
||||||
|
|
||||||
|
class AddParametersOnParameters(RequestHookBase):
|
||||||
|
schemaType: str | None
|
||||||
|
|
||||||
|
def __init__(self, split: str = 1, schemaType: str | None = None):
|
||||||
|
super().__init__(split=split)
|
||||||
|
self.schemaType = schemaType
|
||||||
|
|
||||||
def hook(self, path: str, value: dict):
|
def hook(self, path: str, value: dict):
|
||||||
path, value = super().hook(path, value)
|
path, value = super().hook(path, value)
|
||||||
for key in self.PLACEHOLDER[self.path_name].keys():
|
for key in self.PLACEHOLDER[self.path_name].keys():
|
||||||
example = json.dumps(self.PLACEHOLDER[self.path_name][key])
|
example = json.dumps(self.PLACEHOLDER[self.path_name][key])
|
||||||
|
if self.schemaType == "string":
|
||||||
|
schema = {
|
||||||
|
"type": "string",
|
||||||
|
"default": example,
|
||||||
|
"example": example,
|
||||||
|
}
|
||||||
|
elif self.schemaType == "object":
|
||||||
|
schema = {
|
||||||
|
"type": "object",
|
||||||
|
"default": example,
|
||||||
|
"example": example,
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
schema = self.placeholder_to_yaml(example)
|
||||||
value["parameters"].append(
|
value["parameters"].append(
|
||||||
{
|
{
|
||||||
"name": key,
|
"name": key,
|
||||||
"in": "query",
|
"in": "query",
|
||||||
"required": True,
|
"required": True,
|
||||||
"schema": {
|
"schema": schema,
|
||||||
"type": "string",
|
|
||||||
"default": example,
|
|
||||||
"example": example,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
return path, value
|
return path, value
|
||||||
|
|
||||||
|
|
||||||
class AddParametersOnParametersAsObject(RequestHookBase):
|
# OnBody
|
||||||
|
|
||||||
|
|
||||||
|
class AddParametersOnBody(RequestHookBase):
|
||||||
|
schemaType: str | None
|
||||||
|
contentType: str | None
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
split: str = 1,
|
||||||
|
contentType: str = "application/json",
|
||||||
|
schemaType: str | None = None,
|
||||||
|
):
|
||||||
|
super().__init__(split)
|
||||||
|
self.schemaType = schemaType
|
||||||
|
self.contentType = contentType
|
||||||
|
|
||||||
def hook(self, path: str, value: dict):
|
def hook(self, path: str, value: dict):
|
||||||
path, value = super().hook(path, value)
|
path, value = super().hook(path, value)
|
||||||
for key in self.PLACEHOLDER[self.path_name].keys():
|
data = self.PLACEHOLDER[self.path_name]
|
||||||
example = json.dumps(self.PLACEHOLDER[self.path_name][key])
|
|
||||||
value["parameters"].append(
|
if self.schemaType == "string":
|
||||||
{
|
example = json.dumps(self.PLACEHOLDER[self.path_name])
|
||||||
"name": key,
|
schema = {
|
||||||
"in": "query",
|
"type": "string",
|
||||||
"required": True,
|
"default": example,
|
||||||
"schema": {
|
"example": example,
|
||||||
"type": "object",
|
}
|
||||||
"default": example,
|
elif self.schemaType == "object":
|
||||||
"example": example,
|
example = json.dumps(self.PLACEHOLDER[self.path_name])
|
||||||
},
|
schema = {
|
||||||
|
"type": "object",
|
||||||
|
"default": example,
|
||||||
|
"example": example,
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
schema = {
|
||||||
|
"properties": {
|
||||||
|
i: self.placeholder_to_yaml(data[i]) for i in data.keys()
|
||||||
|
},
|
||||||
|
# "required": [i for i in data.keys()],
|
||||||
|
}
|
||||||
|
value["requestBody"] = {
|
||||||
|
"description": "body",
|
||||||
|
"required": True,
|
||||||
|
"content": {
|
||||||
|
self.contentType: {
|
||||||
|
"schema": schema,
|
||||||
}
|
}
|
||||||
)
|
},
|
||||||
|
}
|
||||||
return path, value
|
return path, value
|
||||||
|
|
||||||
|
|
||||||
|
# OnContent
|
||||||
|
|
||||||
|
|
||||||
class AddParametersOnContent(RequestHookBase):
|
class AddParametersOnContent(RequestHookBase):
|
||||||
|
contentType: str
|
||||||
|
|
||||||
|
def __init__(self, split: str = 1, contentType: str = "application/json"):
|
||||||
|
super().__init__(split=split)
|
||||||
|
self.contentType = contentType
|
||||||
|
|
||||||
def hook(self, path: str, value: dict):
|
def hook(self, path: str, value: dict):
|
||||||
path, value = super().hook(path, value)
|
path, value = super().hook(path, value)
|
||||||
for key in self.PLACEHOLDER[self.path_name].keys():
|
data = self.PLACEHOLDER[self.path_name]
|
||||||
|
for key in data.keys():
|
||||||
value["parameters"].append(
|
value["parameters"].append(
|
||||||
{
|
{
|
||||||
"name": key,
|
"name": key,
|
||||||
"in": "query",
|
"in": "query",
|
||||||
"required": True,
|
"required": True,
|
||||||
"content": {
|
"content": {
|
||||||
"application/json": {
|
self.contentType: {
|
||||||
"schema": self.placeholder_to_yaml(
|
"schema": self.placeholder_to_yaml(data[key]),
|
||||||
self.PLACEHOLDER[self.path_name][key]
|
# "required": [i for i in data[key]],
|
||||||
),
|
}
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
return path, value
|
return path, value
|
||||||
|
|
||||||
|
|
||||||
class AddParametersOnParameters(RequestHookBase):
|
|
||||||
def hook(self, path: str, value: dict):
|
|
||||||
path, value = super().hook(path, value)
|
|
||||||
for key in self.PLACEHOLDER[self.path_name].keys():
|
|
||||||
value["parameters"].append(
|
|
||||||
{
|
|
||||||
"name": key,
|
|
||||||
"in": "query",
|
|
||||||
"required": True,
|
|
||||||
"schema": self.placeholder_to_yaml(
|
|
||||||
self.PLACEHOLDER[self.path_name][key]
|
|
||||||
),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
return path, value
|
|
||||||
|
|
||||||
|
|
||||||
class AddParametersOnBody(RequestHookBase):
|
|
||||||
def hook(self, path: str, value: dict):
|
|
||||||
path, value = super().hook(path, value)
|
|
||||||
data = self.PLACEHOLDER[self.path_name]
|
|
||||||
schema = {i: self.placeholder_to_yaml(data[i]) for i in data.keys()}
|
|
||||||
value["requestBody"] = {
|
|
||||||
"description": "body",
|
|
||||||
"required": True,
|
|
||||||
"content": {
|
|
||||||
"application/json": {
|
|
||||||
"schema": {
|
|
||||||
"properties": schema,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
return path, value
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue