mirror of
https://github.com/thegeneralist01/twitter-openapi
synced 2026-01-11 15:40:26 +01:00
add var
Signed-off-by: ふぁ <yuki@yuki0311.com>
This commit is contained in:
parent
dd0869a6f5
commit
328543616c
4 changed files with 99 additions and 45 deletions
|
|
@ -26,7 +26,8 @@ paths:
|
||||||
default: "{{Query}}"
|
default: "{{Query}}"
|
||||||
example: "{{Query}}"
|
example: "{{Query}}"
|
||||||
|
|
||||||
# ======== Security ========
|
# {% if header == parameters %}
|
||||||
|
|
||||||
- name: authorization
|
- name: authorization
|
||||||
in: header
|
in: header
|
||||||
required: true
|
required: true
|
||||||
|
|
@ -55,6 +56,9 @@ paths:
|
||||||
type: string
|
type: string
|
||||||
default: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"
|
default: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"
|
||||||
description: "UserAgent, some APIs may be rejected if changed."
|
description: "UserAgent, some APIs may be rejected if changed."
|
||||||
|
|
||||||
|
# {% endif %}
|
||||||
|
|
||||||
responses:
|
responses:
|
||||||
"200":
|
"200":
|
||||||
description: ""
|
description: ""
|
||||||
|
|
|
||||||
8
src/config/variable.json
Normal file
8
src/config/variable.json
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"dart": {
|
||||||
|
"header": "parameters"
|
||||||
|
},
|
||||||
|
"typescript": {
|
||||||
|
"header": "securitySchemes"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -18,12 +18,6 @@ components:
|
||||||
schemas: {}
|
schemas: {}
|
||||||
|
|
||||||
securitySchemes:
|
securitySchemes:
|
||||||
# Moved to Parameters because it is not working as Security
|
|
||||||
# BearerAuth:
|
|
||||||
# type: http
|
|
||||||
# scheme: bearer
|
|
||||||
# description: "AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA"
|
|
||||||
|
|
||||||
CsrfToken:
|
CsrfToken:
|
||||||
type: apiKey
|
type: apiKey
|
||||||
in: header
|
in: header
|
||||||
|
|
@ -48,6 +42,30 @@ components:
|
||||||
name: x-twitter-auth-type
|
name: x-twitter-auth-type
|
||||||
description: "OAuth2Session if you are logged in"
|
description: "OAuth2Session if you are logged in"
|
||||||
|
|
||||||
|
# {% if header == securitySchemes %}
|
||||||
|
|
||||||
|
UserAgent:
|
||||||
|
description: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"
|
||||||
|
in: header
|
||||||
|
name: user-agent
|
||||||
|
type: apiKey
|
||||||
|
ActiveUser:
|
||||||
|
description: "yes"
|
||||||
|
in: header
|
||||||
|
name: x-twitter-active-user
|
||||||
|
type: apiKey
|
||||||
|
BearerAuth:
|
||||||
|
description: AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA
|
||||||
|
scheme: bearer
|
||||||
|
type: http
|
||||||
|
ClientLanguage:
|
||||||
|
description: en
|
||||||
|
in: header
|
||||||
|
name: x-twitter-client-language
|
||||||
|
type: apiKey
|
||||||
|
|
||||||
|
# {% endif %}
|
||||||
|
|
||||||
security:
|
security:
|
||||||
- bearerAuth: []
|
- bearerAuth: []
|
||||||
- CsrfToken: []
|
- CsrfToken: []
|
||||||
|
|
|
||||||
100
tools/build.py
100
tools/build.py
|
|
@ -3,6 +3,8 @@ import glob
|
||||||
import json
|
import json
|
||||||
import yaml
|
import yaml
|
||||||
import shutil
|
import shutil
|
||||||
|
import copy
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
class placeholder_manager:
|
class placeholder_manager:
|
||||||
|
|
@ -36,57 +38,79 @@ class placeholder_manager:
|
||||||
return file
|
return file
|
||||||
|
|
||||||
|
|
||||||
OUTPUT_DIR = "dist"
|
OUTPUT_DIR = "dist/{0}"
|
||||||
INPUT_DIR = "src/openapi"
|
INPUT_DIR = "src/openapi"
|
||||||
|
|
||||||
|
try:
|
||||||
|
shutil.rmtree("dist")
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
def read(file: str):
|
with open("src/config/variable.json", mode="r", encoding="utf-8") as f:
|
||||||
with open(file, mode="r", encoding="utf-8") as f:
|
variable = json.load(f)
|
||||||
return f.read()
|
|
||||||
|
|
||||||
|
|
||||||
def write(file: str, data: str) -> None:
|
for lang in variable.keys():
|
||||||
with open(file.replace(INPUT_DIR, OUTPUT_DIR, 1), mode="w+", encoding="utf-8") as f:
|
|
||||||
f.write(data)
|
|
||||||
|
|
||||||
|
def read(file: str):
|
||||||
|
with open(file, mode="r", encoding="utf-8") as f:
|
||||||
|
return remove(f.read())
|
||||||
|
|
||||||
def get_yaml(data, key):
|
def write(file: str, data: str) -> None:
|
||||||
return yaml.safe_load(placeholder.replace_file(str(data), key))
|
with open(
|
||||||
|
file.replace(INPUT_DIR, OUTPUT_DIR.format(lang), 1),
|
||||||
|
mode="w+",
|
||||||
|
encoding="utf-8",
|
||||||
|
) as f:
|
||||||
|
f.write(data)
|
||||||
|
|
||||||
|
def get_yaml(data, key):
|
||||||
|
return yaml.safe_load(placeholder.replace_file(str(data), key))
|
||||||
|
|
||||||
shutil.rmtree("dist")
|
def remove(data):
|
||||||
for dir in glob.glob(os.path.join(INPUT_DIR, "**/")):
|
for match in re.findall(r"(\{% (.*?) %\})", data):
|
||||||
os.makedirs(dir.replace(INPUT_DIR, OUTPUT_DIR, 1), exist_ok=True)
|
equation = match[1].split(" ")
|
||||||
|
if equation[0] == "if" and equation[2] == "==":
|
||||||
|
if equation[3] != variable[lang][equation[1]]:
|
||||||
|
data = re.sub(
|
||||||
|
re.escape(match[0]) + "[\s\S]*?" + re.escape("{% endif %}"),
|
||||||
|
"",
|
||||||
|
data,
|
||||||
|
)
|
||||||
|
|
||||||
placeholder = placeholder_manager()
|
return data
|
||||||
parameters = read("src/config/parameters.yaml")
|
|
||||||
header = read("src/config/header.yaml")
|
|
||||||
|
|
||||||
paths = {}
|
for dir in glob.glob(os.path.join(INPUT_DIR, "**/")):
|
||||||
for file in glob.glob(os.path.join(INPUT_DIR, "**/*.yaml")):
|
os.makedirs(dir.replace(INPUT_DIR, OUTPUT_DIR.format(lang), 1), exist_ok=True)
|
||||||
file = file.replace(os.path.sep, "/")
|
|
||||||
relative = file.replace(INPUT_DIR, "", 1)
|
|
||||||
|
|
||||||
load = yaml.safe_load(placeholder.replace(read(file)))
|
placeholder = placeholder_manager()
|
||||||
|
parameters = read("src/config/parameters.yaml")
|
||||||
|
header = read("src/config/header.yaml")
|
||||||
|
|
||||||
for key in load["paths"].keys():
|
paths = {}
|
||||||
append = get_yaml(parameters, key.split("/")[-1])
|
for file in glob.glob(os.path.join(INPUT_DIR, "**/*.yaml")):
|
||||||
req = load["paths"][key]["get"]
|
file = file.replace(os.path.sep, "/")
|
||||||
req["parameters"] = append["paths"]["/parameters"]["get"]["parameters"]
|
relative = file.replace(INPUT_DIR, "", 1)
|
||||||
|
|
||||||
append = get_yaml(header, key.split("/")[-1])
|
load = yaml.safe_load(placeholder.replace(read(file)))
|
||||||
req = load["paths"][key]["get"]
|
|
||||||
req["responses"]["200"]["headers"] = append["components"]["headers"]
|
for key in load["paths"].keys():
|
||||||
|
append = get_yaml(parameters, key.split("/")[-1])
|
||||||
|
req = load["paths"][key]["get"]
|
||||||
|
req["parameters"] = append["paths"]["/parameters"]["get"]["parameters"]
|
||||||
|
|
||||||
|
append = get_yaml(header, key.split("/")[-1])
|
||||||
|
req = load["paths"][key]["get"]
|
||||||
|
req["responses"]["200"]["headers"] = append["components"]["headers"]
|
||||||
|
|
||||||
|
escape = key.replace("/", "~1")
|
||||||
|
paths.update({key: {"$ref": f".{relative}#/paths/{escape}"}})
|
||||||
|
write(file, yaml.dump(load))
|
||||||
|
|
||||||
|
file = "src/openapi/openapi-3.0.yaml"
|
||||||
|
data = read(file)
|
||||||
|
for path in paths:
|
||||||
|
load = yaml.safe_load(placeholder.replace(data))
|
||||||
|
load["paths"] = paths
|
||||||
|
|
||||||
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"
|
|
||||||
data = read(file)
|
|
||||||
for path in paths:
|
|
||||||
load = yaml.safe_load(placeholder.replace(data))
|
|
||||||
load["paths"] = paths
|
|
||||||
|
|
||||||
write(file, yaml.dump(load))
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue