mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat(api): sort openapi schemas
Reduces the constant changes to the frontend client types due to inconsistent ordering of pydantic models.
This commit is contained in:
parent
5a4d10467b
commit
5beec8211a
@ -288,8 +288,9 @@ class AnyInvocation(BaseInvocation):
|
|||||||
# Nodes are too powerful, we have to make our own OpenAPI schema manually
|
# Nodes are too powerful, we have to make our own OpenAPI schema manually
|
||||||
# No but really, because the schema is dynamic depending on loaded nodes, we need to generate it manually
|
# No but really, because the schema is dynamic depending on loaded nodes, we need to generate it manually
|
||||||
oneOf: list[dict[str, str]] = []
|
oneOf: list[dict[str, str]] = []
|
||||||
for i in BaseInvocation.get_invocations():
|
names = [i.__name__ for i in BaseInvocation.get_invocations()]
|
||||||
oneOf.append({"$ref": f"#/components/schemas/{i.__name__}"})
|
for name in sorted(names):
|
||||||
|
oneOf.append({"$ref": f"#/components/schemas/{name}"})
|
||||||
return {"oneOf": oneOf}
|
return {"oneOf": oneOf}
|
||||||
|
|
||||||
|
|
||||||
@ -304,8 +305,9 @@ class AnyInvocationOutput(BaseInvocationOutput):
|
|||||||
# No but really, because the schema is dynamic depending on loaded nodes, we need to generate it manually
|
# No but really, because the schema is dynamic depending on loaded nodes, we need to generate it manually
|
||||||
|
|
||||||
oneOf: list[dict[str, str]] = []
|
oneOf: list[dict[str, str]] = []
|
||||||
for i in BaseInvocationOutput.get_outputs():
|
names = [i.__name__ for i in BaseInvocationOutput.get_outputs()]
|
||||||
oneOf.append({"$ref": f"#/components/schemas/{i.__name__}"})
|
for name in sorted(names):
|
||||||
|
oneOf.append({"$ref": f"#/components/schemas/{name}"})
|
||||||
return {"oneOf": oneOf}
|
return {"oneOf": oneOf}
|
||||||
|
|
||||||
|
|
||||||
|
@ -108,6 +108,8 @@ def get_openapi_func(
|
|||||||
if post_transform is not None:
|
if post_transform is not None:
|
||||||
openapi_schema = post_transform(openapi_schema)
|
openapi_schema = post_transform(openapi_schema)
|
||||||
|
|
||||||
|
openapi_schema["components"]["schemas"] = dict(sorted(openapi_schema["components"]["schemas"].items()))
|
||||||
|
|
||||||
app.openapi_schema = openapi_schema
|
app.openapi_schema = openapi_schema
|
||||||
return app.openapi_schema
|
return app.openapi_schema
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user