Skip to content

fix(openapi): normalize Path defaults to POSIX in schema generation#9209

Open
Pfannkuchensack wants to merge 2 commits into
invoke-ai:mainfrom
Pfannkuchensack:dev/openapi-path
Open

fix(openapi): normalize Path defaults to POSIX in schema generation#9209
Pfannkuchensack wants to merge 2 commits into
invoke-ai:mainfrom
Pfannkuchensack:dev/openapi-path

Conversation

@Pfannkuchensack
Copy link
Copy Markdown
Collaborator

Summary

Pydantic stringifies Path defaults via the host OS's separator, so a default like Path("models/.convert_cache") serialized to "models\.convert_cache" whenever the schema was regenerated on Windows — polluting every diff with cross-OS noise.

Added normalize_path_defaults() to walk the finished OpenAPI schema and flip backslashes to forward slashes on any node with format: path. Ran once at the end of get_openapi_func so it covers all current and future Path-typed fields without per-field annotations. Regenerated openapi.json and schema.ts cleanly on Windows.

Related Issues / Discussions

None — this is a developer-experience fix for contributors running make frontend-openapi / pnpm typegen on Windows.

QA Instructions

  1. On Linux/macOS: regenerate the schema with make frontend-openapi (or the manual python scripts/generate_openapi_schema.py > invokeai/frontend/web/openapi.json && pnpm prettier --write openapi.json flow). Confirm git diff origin/main -- invokeai/frontend/web/openapi.json invokeai/frontend/web/src/services/api/schema.ts shows no change for any models/.convert_cache / models/.download_cache defaults (they should stay as /).
  2. On Windows (PowerShell): from invokeai/frontend/web/ run
    uv run --extra cuda python ../../../scripts/generate_openapi_schema.py | pnpm typegen
    
    Then git diff -- src/services/api/schema.ts | grep "models\\\\" — should return nothing. Without this fix you'd see lines like @default models\.convert_cache.
  3. Grep the regenerated artifacts for any leftover backslash drift on path defaults:
    grep -E "@default models\\\\" invokeai/frontend/web/src/services/api/schema.ts
    grep -E "\"default\": \"models\\\\\\\\" invokeai/frontend/web/openapi.json
    
    Both should return no matches on any OS.
  4. The intentional Windows-path example inside the install_model docstring (C:\\users\\fred\\model.safetensors) is unaffected because it lives in a description, not a default, and isn't on a node with format: path. Confirm it's still present in openapi.json line ~2818.
  5. App startup unchanged — the normalization runs only at schema-generation time inside get_openapi_func.

Merge Plan

No coordination needed. Pure dev-tooling fix; runtime behaviour is unchanged. After merge, anyone who currently has Windows-flavoured schema drift in their branch can rebase + regen cleanly.

Checklist

  • The PR has a short but descriptive title, suitable for a changelog
  • Tests added / updated (if applicable) — pure schema-serialization helper; covered by manual regen verification above
  • ❗Changes to a redux slice have a corresponding migration
  • Documentation added / updated (if applicable)
  • Updated What's New copy (if doing a release after this PR)

Pydantic stringifies Path defaults via the host OS's separator, so a
default like Path("models/.convert_cache") serialized to
"models\.convert_cache" whenever the schema was regenerated on Windows
— polluting every diff with cross-OS noise.

Added normalize_path_defaults() to walk the finished OpenAPI schema and
flip backslashes to forward slashes on any node with format: path. Ran
once at the end of get_openapi_func so it covers all current and future
Path-typed fields without per-field annotations. Regenerated openapi.json
and schema.ts cleanly on Windows.
@github-actions github-actions Bot added the python PRs that change python files label May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python PRs that change python files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants