mirror of
https://github.com/thegeneralist01/twitter-openapi
synced 2026-01-11 15:40:26 +01:00
add schemas hooks
Signed-off-by: ふぁ <yuki@yuki0311.com>
This commit is contained in:
parent
dfc0b8b2e0
commit
9d2fbc2755
3 changed files with 29 additions and 5 deletions
|
|
@ -6,7 +6,7 @@ import shutil
|
|||
import copy
|
||||
import re
|
||||
from build_config import Config
|
||||
from hooks import OpenapiHookBase, RequestHookBase
|
||||
from hooks import OpenapiHookBase, RequestHookBase, SchemasHookBase
|
||||
from tqdm import tqdm
|
||||
|
||||
|
||||
|
|
@ -21,7 +21,7 @@ try:
|
|||
except:
|
||||
pass
|
||||
|
||||
for lang in tqdm(config.main().keys(), leave=False):
|
||||
for lang, profile in tqdm(config.main().items(), leave=False):
|
||||
dist_replace = lambda x: x.replace(
|
||||
config.INPUT_DIR, config.OUTPUT_DIR.format(lang), 1
|
||||
)
|
||||
|
|
@ -39,7 +39,7 @@ for lang in tqdm(config.main().keys(), leave=False):
|
|||
for method in list(load["paths"][path]):
|
||||
for tag in list(load["paths"][path][method].get("tags", ["default"])):
|
||||
key, value = path, load["paths"][path][method]
|
||||
for hook in config.main()[lang]["request"][tag]:
|
||||
for hook in profile["request"][tag]:
|
||||
hook: RequestHookBase
|
||||
key, value = hook.hook(key, value)
|
||||
load["paths"][path][method] = value
|
||||
|
|
@ -48,7 +48,12 @@ for lang in tqdm(config.main().keys(), leave=False):
|
|||
escape = key.replace("/", "~1")
|
||||
relative = file.replace(config.INPUT_DIR, "", 1)
|
||||
paths.update({key: {"$ref": f".{relative}#/paths/{escape}"}})
|
||||
|
||||
for name in list(load.get("components", {}).get("schemas", {})):
|
||||
value = load["components"]["schemas"][name]
|
||||
for hook in profile["schemas"]:
|
||||
hook: SchemasHookBase
|
||||
value = hook.hook(value)
|
||||
load["components"]["schemas"][name] = value
|
||||
with open(dist_replace(file), mode="w+", encoding="utf-8") as f:
|
||||
f.write(yaml.dump(load))
|
||||
|
||||
|
|
@ -57,7 +62,7 @@ for lang in tqdm(config.main().keys(), leave=False):
|
|||
openapi = yaml.safe_load(f)
|
||||
for path in paths:
|
||||
openapi["paths"] = paths
|
||||
for hook in config.main()[lang]["openapi"]:
|
||||
for hook in profile["openapi"]:
|
||||
hook: OpenapiHookBase
|
||||
openapi = hook.hook(openapi)
|
||||
with open(dist_replace(file), mode="w+", encoding="utf-8") as f:
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ class Config:
|
|||
return {
|
||||
"docs": {
|
||||
"openapi": [AddSecuritySchemesOnSecuritySchemes()],
|
||||
"schemas": [],
|
||||
"request": {
|
||||
key: [
|
||||
ReplaceQueryIdPlaceholder(split=-1),
|
||||
|
|
@ -55,6 +56,7 @@ class Config:
|
|||
},
|
||||
"dart": {
|
||||
"openapi": [],
|
||||
"schemas": [],
|
||||
"request": {
|
||||
key: [
|
||||
ReplaceQueryIdPlaceholder(split=-1),
|
||||
|
|
@ -107,6 +109,7 @@ class Config:
|
|||
},
|
||||
"typescript": {
|
||||
"openapi": [AddSecuritySchemesOnSecuritySchemes()],
|
||||
"schemas": [RemoveDiscriminator()],
|
||||
"request": {
|
||||
key: [
|
||||
ReplaceQueryIdPlaceholder(split=-1),
|
||||
|
|
@ -143,6 +146,7 @@ class Config:
|
|||
},
|
||||
"test": {
|
||||
"openapi": [AddSecuritySchemesOnSecuritySchemes()],
|
||||
"schemas": [],
|
||||
"request": {
|
||||
key: [
|
||||
ReplaceQueryIdPlaceholder(split=-1),
|
||||
|
|
|
|||
|
|
@ -58,6 +58,11 @@ class OpenapiHookBase(HookBase):
|
|||
return value
|
||||
|
||||
|
||||
class SchemasHookBase(HookBase):
|
||||
def hook(self, value: dict):
|
||||
return value
|
||||
|
||||
|
||||
class RequestHookBase(HookBase):
|
||||
split: int
|
||||
path_name: str
|
||||
|
|
@ -84,6 +89,16 @@ class AddSecuritySchemesOnSecuritySchemes(OpenapiHookBase):
|
|||
return value
|
||||
|
||||
|
||||
# SchemasHookBase extends
|
||||
|
||||
|
||||
class RemoveDiscriminator(SchemasHookBase):
|
||||
def hook(self, value: dict):
|
||||
if value.get("discriminator") is not None:
|
||||
del value["discriminator"]
|
||||
return value
|
||||
|
||||
|
||||
# RequestHookBase extends
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue