Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions invokeai/app/util/custom_openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@ def move_defs_to_top_level(openapi_schema: dict[str, Any], component_schema: dic
openapi_schema["components"]["schemas"][schema_key] = json_schema


def normalize_path_defaults(node: Any) -> None:
"""Recursively normalize `default` strings on schema nodes whose `format` is `path` to use forward slashes.

Pydantic stringifies `Path` defaults using the host OS's separator, so a default declared as
`Path("models/.convert_cache")` serializes to `models\\.convert_cache` on Windows. That OS-dependent drift
pollutes diffs whenever schema is regenerated on Windows. We force POSIX form for path-typed defaults.
"""
if isinstance(node, dict):
if node.get("format") == "path" and isinstance(node.get("default"), str):
node["default"] = node["default"].replace("\\", "/")
for v in node.values():
normalize_path_defaults(v)
elif isinstance(node, list):
for v in node:
normalize_path_defaults(v)


def get_openapi_func(
app: FastAPI, post_transform: Optional[Callable[[dict[str, Any]], dict[str, Any]]] = None
) -> Callable[[], dict[str, Any]]:
Expand Down Expand Up @@ -126,6 +143,8 @@ def openapi() -> dict[str, Any]:
if post_transform is not None:
openapi_schema = post_transform(openapi_schema)

normalize_path_defaults(openapi_schema)

openapi_schema["components"]["schemas"] = dict(sorted(openapi_schema["components"]["schemas"].items()))

app.openapi_schema = openapi_schema
Expand Down
Loading