From f707403009cf06d56d6bd3b1438ddd2a7efb1d55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=B5=E3=81=81?= Date: Sun, 28 May 2023 02:23:22 +0900 Subject: [PATCH] update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ふぁ --- dist/dart/paths/other.yaml | 4 +--- dist/docs/paths/other.yaml | 4 +--- dist/test/paths/other.yaml | 4 +--- dist/typescript/paths/other.yaml | 4 +--- src/config/placeholder.json | 4 ++-- src/openapi/paths/other.yaml | 4 +--- tools/build.py | 10 +++++++++- tools/build_config.py | 4 ++++ tools/hooks.py | 13 ++++++++++--- 9 files changed, 30 insertions(+), 21 deletions(-) diff --git a/dist/dart/paths/other.yaml b/dist/dart/paths/other.yaml index 766da46..c8e1e3e 100644 --- a/dist/dart/paths/other.yaml +++ b/dist/dart/paths/other.yaml @@ -16,10 +16,8 @@ components: type: object OtherResponse: properties: - session: + Session: $ref: '#/components/schemas/Session' - required: - - session type: object Session: properties: diff --git a/dist/docs/paths/other.yaml b/dist/docs/paths/other.yaml index 766da46..c8e1e3e 100644 --- a/dist/docs/paths/other.yaml +++ b/dist/docs/paths/other.yaml @@ -16,10 +16,8 @@ components: type: object OtherResponse: properties: - session: + Session: $ref: '#/components/schemas/Session' - required: - - session type: object Session: properties: diff --git a/dist/test/paths/other.yaml b/dist/test/paths/other.yaml index 766da46..c8e1e3e 100644 --- a/dist/test/paths/other.yaml +++ b/dist/test/paths/other.yaml @@ -16,10 +16,8 @@ components: type: object OtherResponse: properties: - session: + Session: $ref: '#/components/schemas/Session' - required: - - session type: object Session: properties: diff --git a/dist/typescript/paths/other.yaml b/dist/typescript/paths/other.yaml index 766da46..c8e1e3e 100644 --- a/dist/typescript/paths/other.yaml +++ b/dist/typescript/paths/other.yaml @@ -16,10 +16,8 @@ components: type: object OtherResponse: properties: - session: + Session: $ref: '#/components/schemas/Session' - required: - - session type: object Session: properties: diff --git a/src/config/placeholder.json b/src/config/placeholder.json index c188b2d..8747cc8 100644 --- a/src/config/placeholder.json +++ b/src/config/placeholder.json @@ -428,7 +428,7 @@ "dark_request": false } }, - "=====v1.1====": { + "#=====v1.1====": { "url": "https://twitter.com/i/api/1.1/" }, "friendships/create.json": { @@ -490,7 +490,7 @@ "src": "search_box", "result_type": "events,users,topics" }, - "=====v2====": { + "#=====v2====": { "url": "https://twitter.com/i/api/2" }, "search/adaptive.json": { diff --git a/src/openapi/paths/other.yaml b/src/openapi/paths/other.yaml index 2a057c1..6700968 100644 --- a/src/openapi/paths/other.yaml +++ b/src/openapi/paths/other.yaml @@ -22,10 +22,8 @@ components: schemas: OtherResponse: type: object - required: - - "session" properties: - session: + Session: $ref: "#/components/schemas/Session" # window.__INITIAL_STATE__ Session: type: object diff --git a/tools/build.py b/tools/build.py index 7117546..fa7550b 100644 --- a/tools/build.py +++ b/tools/build.py @@ -6,7 +6,7 @@ import shutil import copy import re from build_config import Config -from hooks import OpenapiHookBase, RequestHookBase, SchemasHookBase +from hooks import OpenapiHookBase, RequestHookBase, SchemasHookBase,OtherHookBase from tqdm import tqdm @@ -54,6 +54,14 @@ for lang, profile in tqdm(config.main().items(), leave=False): hook: SchemasHookBase value = hook.hook(value) load["components"]["schemas"][name] = value + if file == "src/openapi/paths/other.yaml": + for hook in profile["other"]: + hook: OtherHookBase + key, value = hook.hook() + load["components"]["schemas"][key] = value + load["components"]["schemas"]["OtherResponse"]["properties"][key] = { + "$ref": f"#/components/schemas/{key}" + } with open(dist_replace(file), mode="w+", encoding="utf-8") as f: f.write(yaml.dump(load)) diff --git a/tools/build_config.py b/tools/build_config.py index a5cd9aa..b2a72d2 100644 --- a/tools/build_config.py +++ b/tools/build_config.py @@ -10,6 +10,7 @@ class Config: "docs": { "openapi": [AddSecuritySchemesOnSecuritySchemes()], "schemas": [], + "other":[], "request": { key: [ ReplaceQueryIdPlaceholder(split=-1), @@ -57,6 +58,7 @@ class Config: "dart": { "openapi": [], "schemas": [], + "other":[], "request": { key: [ ReplaceQueryIdPlaceholder(split=-1), @@ -110,6 +112,7 @@ class Config: "typescript": { "openapi": [AddSecuritySchemesOnSecuritySchemes()], "schemas": [RemoveDiscriminator()], + "other":[], "request": { key: [ ReplaceQueryIdPlaceholder(split=-1), @@ -159,6 +162,7 @@ class Config: "test": { "openapi": [AddSecuritySchemesOnSecuritySchemes()], "schemas": [], + "other":[], "request": { key: [ ReplaceQueryIdPlaceholder(split=-1), diff --git a/tools/hooks.py b/tools/hooks.py index 4fa6d8e..742a0eb 100644 --- a/tools/hooks.py +++ b/tools/hooks.py @@ -49,17 +49,24 @@ class HookBase: with open(f"src/config/component/{name}.yaml", mode="r", encoding="utf-8") as f: return yaml.safe_load(f) + def load_placeholder(self) -> dict: + with open("src/config/placeholder.json", mode="r", encoding="utf-8") as f: + return yaml.safe_load(f) + # HookBase extends class OpenapiHookBase(HookBase): - def hook(self, value: dict): + def hook(self, value: dict)->dict: return value +class OtherHookBase(HookBase): + def hook(self)->tuple[str, dict]: + return "", {} class SchemasHookBase(HookBase): - def hook(self, value: dict): + def hook(self, value: dict)->dict: return value @@ -71,7 +78,7 @@ class RequestHookBase(HookBase): super().__init__() self.split = split - def hook(self, path: str, value: 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