Skip to content

refactor: extract _collapse_versioned_paths from _custom_openapi#21

Merged
lesnik512 merged 3 commits into
mainfrom
refactor/collapse-versioned-paths-seam
Jul 4, 2026
Merged

refactor: extract _collapse_versioned_paths from _custom_openapi#21
lesnik512 merged 3 commits into
mainfrom
refactor/collapse-versioned-paths-seam

Conversation

@lesnik512

Copy link
Copy Markdown
Member

What

Behavior-preserving refactor from fresh architecture review #2 (candidate A). Lifts the OpenAPI path-collapse/content-rewrite loop out of the monkey-patched _custom_openapi into a pure module-level function:

_collapse_versioned_paths(raw_paths, versioned_paths, vendor_media_type) -> dict[str, typing.Any]

It splits the :<version> suffix, rewrites each requestBody content key to {vendor}; version=X.Y, and merges same-path versions via helpers.dict_merge. _custom_openapi now calls it.

Why

_iter_openapi_routes — the first half of the OpenAPI-versioning transform — was already a seam-testable function with a direct unit test. The collapse loop, its second half, was inline and reachable only by building an app and fetching /openapi.json. This completes the pattern: the collapse rules (colon split, content-key rewrite, per-version merge) are now verifiable without an ASGI round-trip. Vendor is a plain argument, so the function is pure w.r.t. the VENDOR_MEDIA_TYPE global.

A dedicated openapi.py module (symmetry with accept.py) was considered and rejected as YAGNI — app.py is ~130 lines with no size pressure. Recorded in the design doc.

Tests

Four async def unit tests in tests/test_app.py beside the _iter_openapi_routes test, one per branch: non-versioned passthrough, requestBody rewrite, two-version dict_merge, versioned-without-requestBody. Pure addition — the existing OpenAPI integration tests (distinct-models, prefix, colon-preservation) are unchanged and still exercise the real pipeline.

  • just test-ci — 36 passed, coverage 100%.
  • just lint-ci — ruff + ty clean, planning: OK.

Planning bundle: planning/changes/2026-07-04.03-collapse-versioned-paths-seam/.

🤖 Generated with Claude Code

lesnik512 and others added 3 commits July 4, 2026 15:21
Full-lane design.md + plan.md for extracting the OpenAPI path-collapse loop into a pure, unit-testable _collapse_versioned_paths.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@lesnik512 lesnik512 merged commit 7961484 into main Jul 4, 2026
6 checks passed
@lesnik512 lesnik512 deleted the refactor/collapse-versioned-paths-seam branch July 4, 2026 12:37
lesnik512 added a commit that referenced this pull request Jul 4, 2026
…#22)

* docs(planning): add 1.4.7 release notes

Case-insensitive vendor matching fix (#18) plus internal refactors (#17, #21) since 1.4.6.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* docs(planning): record vendor-media-type process-global decision

Review #2 candidate B: keep VENDOR_MEDIA_TYPE as class-global state; instance-scoping collides with the response-class mechanism and one-vendor-per-process is accepted.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* docs(architecture): seed capability pages and glossary

Living-truth pages for Accept-header version negotiation and OpenAPI schema versioning, plus the ubiquitous-language glossary.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant