mirror of
https://github.com/thegeneralist01/twitter-openapi
synced 2026-01-11 23:50: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 copy
|
||||||
import re
|
import re
|
||||||
from build_config import Config
|
from build_config import Config
|
||||||
from hooks import OpenapiHookBase, RequestHookBase
|
from hooks import OpenapiHookBase, RequestHookBase, SchemasHookBase
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -21,7 +21,7 @@ try:
|
||||||
except:
|
except:
|
||||||
pass
|
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(
|
dist_replace = lambda x: x.replace(
|
||||||
config.INPUT_DIR, config.OUTPUT_DIR.format(lang), 1
|
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 method in list(load["paths"][path]):
|
||||||
for tag in list(load["paths"][path][method].get("tags", ["default"])):
|
for tag in list(load["paths"][path][method].get("tags", ["default"])):
|
||||||
key, value = path, load["paths"][path][method]
|
key, value = path, load["paths"][path][method]
|
||||||
for hook in config.main()[lang]["request"][tag]:
|
for hook in profile["request"][tag]:
|
||||||
hook: RequestHookBase
|
hook: RequestHookBase
|
||||||
key, value = hook.hook(key, value)
|
key, value = hook.hook(key, value)
|
||||||
load["paths"][path][method] = value
|
load["paths"][path][method] = value
|
||||||
|
|
@ -48,7 +48,12 @@ for lang in tqdm(config.main().keys(), leave=False):
|
||||||
escape = key.replace("/", "~1")
|
escape = key.replace("/", "~1")
|
||||||
relative = file.replace(config.INPUT_DIR, "", 1)
|
relative = file.replace(config.INPUT_DIR, "", 1)
|
||||||
paths.update({key: {"$ref": f".{relative}#/paths/{escape}"}})
|
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:
|
with open(dist_replace(file), mode="w+", encoding="utf-8") as f:
|
||||||
f.write(yaml.dump(load))
|
f.write(yaml.dump(load))
|
||||||
|
|
||||||
|
|
@ -57,7 +62,7 @@ for lang in tqdm(config.main().keys(), leave=False):
|
||||||
openapi = yaml.safe_load(f)
|
openapi = yaml.safe_load(f)
|
||||||
for path in paths:
|
for path in paths:
|
||||||
openapi["paths"] = paths
|
openapi["paths"] = paths
|
||||||
for hook in config.main()[lang]["openapi"]:
|
for hook in profile["openapi"]:
|
||||||
hook: OpenapiHookBase
|
hook: OpenapiHookBase
|
||||||
openapi = hook.hook(openapi)
|
openapi = hook.hook(openapi)
|
||||||
with open(dist_replace(file), mode="w+", encoding="utf-8") as f:
|
with open(dist_replace(file), mode="w+", encoding="utf-8") as f:
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ class Config:
|
||||||
return {
|
return {
|
||||||
"docs": {
|
"docs": {
|
||||||
"openapi": [AddSecuritySchemesOnSecuritySchemes()],
|
"openapi": [AddSecuritySchemesOnSecuritySchemes()],
|
||||||
|
"schemas": [],
|
||||||
"request": {
|
"request": {
|
||||||
key: [
|
key: [
|
||||||
ReplaceQueryIdPlaceholder(split=-1),
|
ReplaceQueryIdPlaceholder(split=-1),
|
||||||
|
|
@ -55,6 +56,7 @@ class Config:
|
||||||
},
|
},
|
||||||
"dart": {
|
"dart": {
|
||||||
"openapi": [],
|
"openapi": [],
|
||||||
|
"schemas": [],
|
||||||
"request": {
|
"request": {
|
||||||
key: [
|
key: [
|
||||||
ReplaceQueryIdPlaceholder(split=-1),
|
ReplaceQueryIdPlaceholder(split=-1),
|
||||||
|
|
@ -107,6 +109,7 @@ class Config:
|
||||||
},
|
},
|
||||||
"typescript": {
|
"typescript": {
|
||||||
"openapi": [AddSecuritySchemesOnSecuritySchemes()],
|
"openapi": [AddSecuritySchemesOnSecuritySchemes()],
|
||||||
|
"schemas": [RemoveDiscriminator()],
|
||||||
"request": {
|
"request": {
|
||||||
key: [
|
key: [
|
||||||
ReplaceQueryIdPlaceholder(split=-1),
|
ReplaceQueryIdPlaceholder(split=-1),
|
||||||
|
|
@ -143,6 +146,7 @@ class Config:
|
||||||
},
|
},
|
||||||
"test": {
|
"test": {
|
||||||
"openapi": [AddSecuritySchemesOnSecuritySchemes()],
|
"openapi": [AddSecuritySchemesOnSecuritySchemes()],
|
||||||
|
"schemas": [],
|
||||||
"request": {
|
"request": {
|
||||||
key: [
|
key: [
|
||||||
ReplaceQueryIdPlaceholder(split=-1),
|
ReplaceQueryIdPlaceholder(split=-1),
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,11 @@ class OpenapiHookBase(HookBase):
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
class SchemasHookBase(HookBase):
|
||||||
|
def hook(self, value: dict):
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
class RequestHookBase(HookBase):
|
class RequestHookBase(HookBase):
|
||||||
split: int
|
split: int
|
||||||
path_name: str
|
path_name: str
|
||||||
|
|
@ -84,6 +89,16 @@ class AddSecuritySchemesOnSecuritySchemes(OpenapiHookBase):
|
||||||
return value
|
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
|
# RequestHookBase extends
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue