API: types schema improve typescript performance
This commit is contained in:
@@ -163,6 +163,7 @@ API.register(open_file)
|
||||
"properties": {},
|
||||
}
|
||||
|
||||
err_type = None
|
||||
for name, func in self._registry.items():
|
||||
hints = get_type_hints(func)
|
||||
|
||||
@@ -175,6 +176,15 @@ API.register(open_file)
|
||||
|
||||
return_type = serialized_hints.pop("return")
|
||||
|
||||
if err_type is None:
|
||||
err_type = next(
|
||||
t
|
||||
for t in return_type["oneOf"]
|
||||
if ("error" in t["properties"]["status"]["enum"])
|
||||
)
|
||||
|
||||
return_type["oneOf"][1] = {"$ref": "#/$defs/error"}
|
||||
|
||||
sig = signature(func)
|
||||
required_args = []
|
||||
for n, param in sig.parameters.items():
|
||||
@@ -196,6 +206,8 @@ API.register(open_file)
|
||||
},
|
||||
}
|
||||
|
||||
api_schema["$defs"] = {"error": err_type}
|
||||
|
||||
return api_schema
|
||||
|
||||
def get_method_argtype(self, method_name: str, arg_name: str) -> Any:
|
||||
|
||||
@@ -92,7 +92,7 @@ def type_to_dict(
|
||||
required.add(pn)
|
||||
|
||||
elif pv.get("oneOf") is not None:
|
||||
if "null" not in [i["type"] for i in pv.get("oneOf", [])]:
|
||||
if "null" not in [i.get("type") for i in pv.get("oneOf", [])]:
|
||||
required.add(pn)
|
||||
|
||||
required_fields = {
|
||||
|
||||
Reference in New Issue
Block a user