mirror of
https://github.com/thegeneralist01/twitter-openapi
synced 2026-01-11 23:50:26 +01:00
update build
Signed-off-by: ふぁ <yuki@yuki0311.com>
This commit is contained in:
parent
2d0a071c0b
commit
a69d2fa7d8
1 changed files with 79 additions and 10 deletions
|
|
@ -38,6 +38,38 @@ class placeholder_manager:
|
||||||
return file
|
return file
|
||||||
|
|
||||||
|
|
||||||
|
def placeholder_to_yaml(obj):
|
||||||
|
if type(obj) is dict:
|
||||||
|
return {
|
||||||
|
"type": "object",
|
||||||
|
"required": [i for i in obj],
|
||||||
|
"properties": {i: placeholder_to_yaml(obj[i]) for i in obj},
|
||||||
|
# "default": {i: placeholder_to_yaml(obj[i]) for i in obj},
|
||||||
|
# "example": {i: placeholder_to_yaml(obj[i]) for i in obj},
|
||||||
|
}
|
||||||
|
elif type(obj) is list:
|
||||||
|
if len(obj) == 0:
|
||||||
|
return {
|
||||||
|
"type": "array",
|
||||||
|
"items": {"type": "object"},
|
||||||
|
# "default": [],
|
||||||
|
# "example": [],
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
"type": "array",
|
||||||
|
"items": placeholder_to_yaml(obj[0]),
|
||||||
|
# "default": placeholder_to_yaml(obj[0]),
|
||||||
|
# "example": placeholder_to_yaml(obj[0]),
|
||||||
|
}
|
||||||
|
elif type(obj) is str:
|
||||||
|
return {"type": "string", "example": obj, "default": obj}
|
||||||
|
elif type(obj) is bool:
|
||||||
|
return {"type": "boolean", "example": obj, "default": obj}
|
||||||
|
elif type(obj) is int:
|
||||||
|
return {"type": "integer", "example": obj, "default": obj}
|
||||||
|
|
||||||
|
|
||||||
|
print("=== Build Start ===")
|
||||||
OUTPUT_DIR = "dist/{0}"
|
OUTPUT_DIR = "dist/{0}"
|
||||||
INPUT_DIR = "src/openapi"
|
INPUT_DIR = "src/openapi"
|
||||||
METHODS = ["get", "put", "post", "delete", "options", "head", "patch", "trace"]
|
METHODS = ["get", "put", "post", "delete", "options", "head", "patch", "trace"]
|
||||||
|
|
@ -51,6 +83,8 @@ with open("src/config/variable.json", mode="r", encoding="utf-8") as f:
|
||||||
variable = json.load(f)
|
variable = json.load(f)
|
||||||
|
|
||||||
|
|
||||||
|
placeholder = placeholder_manager()
|
||||||
|
|
||||||
for lang in variable.keys():
|
for lang in variable.keys():
|
||||||
|
|
||||||
def read(file: str):
|
def read(file: str):
|
||||||
|
|
@ -84,7 +118,6 @@ for lang in variable.keys():
|
||||||
for dir in glob.glob(os.path.join(INPUT_DIR, "**/")):
|
for dir in glob.glob(os.path.join(INPUT_DIR, "**/")):
|
||||||
os.makedirs(dir.replace(INPUT_DIR, OUTPUT_DIR.format(lang), 1), exist_ok=True)
|
os.makedirs(dir.replace(INPUT_DIR, OUTPUT_DIR.format(lang), 1), exist_ok=True)
|
||||||
|
|
||||||
placeholder = placeholder_manager()
|
|
||||||
parameters = read("src/config/parameters.yaml")
|
parameters = read("src/config/parameters.yaml")
|
||||||
header = read("src/config/header.yaml")
|
header = read("src/config/header.yaml")
|
||||||
|
|
||||||
|
|
@ -98,17 +131,51 @@ for lang in variable.keys():
|
||||||
for key in load["paths"].keys():
|
for key in load["paths"].keys():
|
||||||
append = get_yaml(parameters, key.split("/")[-1])
|
append = get_yaml(parameters, key.split("/")[-1])
|
||||||
param = append["paths"]["/parameters"]
|
param = append["paths"]["/parameters"]
|
||||||
for method in METHODS:
|
for method in load["paths"][key].keys():
|
||||||
if load["paths"][key].get(method, None) is not None:
|
req = load["paths"][key][method]
|
||||||
req = load["paths"][key][method]
|
|
||||||
req["parameters"] = param[method]["parameters"]
|
|
||||||
|
|
||||||
append = get_yaml(header, key.split("/")[-1])
|
req["parameters"] = req.get("parameters", [])
|
||||||
req = load["paths"][key][method]
|
req["parameters"] += param[method].get("parameters", [])
|
||||||
req["responses"]["200"]["headers"] = append["components"]["headers"]
|
|
||||||
|
|
||||||
escape = key.replace("/", "~1")
|
if param[method].get("requestBody") is not None:
|
||||||
paths.update({key: {"$ref": f".{relative}#/paths/{escape}"}})
|
req["requestBody"] = param[method].get("requestBody")
|
||||||
|
|
||||||
|
if variable[lang].get(method + "_parameters") == "schema_parameters":
|
||||||
|
for p_key in placeholder.data[key.split("/")[-1]].keys():
|
||||||
|
if p_key.lower() == "query":
|
||||||
|
continue
|
||||||
|
req["parameters"].append(
|
||||||
|
{
|
||||||
|
"name": p_key.lower(),
|
||||||
|
"in": "query",
|
||||||
|
"schema": placeholder_to_yaml(
|
||||||
|
placeholder.data[key.split("/")[-1]][p_key]
|
||||||
|
),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
if variable[lang].get(method + "_parameters") == "schema_request_body":
|
||||||
|
data = placeholder.data[key.split("/")[-1]]
|
||||||
|
schema = {i: placeholder_to_yaml(data[i]) for i in data.keys()}
|
||||||
|
|
||||||
|
req["requestBody"] = {
|
||||||
|
"description": key.split("/")[-1] + "body",
|
||||||
|
"required": True,
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"properties": schema,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
append = get_yaml(header, key.split("/")[-1])
|
||||||
|
req = load["paths"][key][method]
|
||||||
|
req["responses"]["200"]["headers"] = append["components"]["headers"]
|
||||||
|
|
||||||
|
escape = key.replace("/", "~1")
|
||||||
|
paths.update({key: {"$ref": f".{relative}#/paths/{escape}"}})
|
||||||
write(file, yaml.dump(load))
|
write(file, yaml.dump(load))
|
||||||
|
|
||||||
file = "src/openapi/openapi-3.0.yaml"
|
file = "src/openapi/openapi-3.0.yaml"
|
||||||
|
|
@ -118,3 +185,5 @@ for lang in variable.keys():
|
||||||
load["paths"] = paths
|
load["paths"] = paths
|
||||||
|
|
||||||
write(file, yaml.dump(load))
|
write(file, yaml.dump(load))
|
||||||
|
|
||||||
|
print("=== Build End ===")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue