fix(warnings): emit DUPLICATE_OPERATION as a structured warning - #387
Conversation
There was a problem hiding this comment.
Pull request overview
Adds structured emission of WarningCode.DUPLICATE_OPERATION so METHOD/path collisions during spec generation are CI-observable via collect_spec_warnings(...) / --fail-on-warnings, rather than being log-only.
Changes:
- Record merge-time METHOD/path collisions in
OpenAPIRegistryviaadd_duplicate_operation(...)and clear them inOpenAPIRegistry.clear(). - Surface recorded collisions as structured
SpecWarning(code=DUPLICATE_OPERATION, ...)via_collect_duplicate_operation_warnings(...)and include them incollect_spec_warnings(...). - Add tests covering structured duplicate-operation warnings, strict-mode behavior, and CLI
--fail-on-warningsexit code behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/azure_functions_openapi/spec.py |
Records duplicate METHOD/path collisions during generation and emits them as structured warnings via collect_spec_warnings. |
src/azure_functions_openapi/registry.py |
Adds a dedicated registry channel for duplicate operations, with deduping + sorting and clear() support. |
tests/test_spec_warnings.py |
Adds regression tests for structured duplicate-operation warnings, strict behavior, and --fail-on-warnings gating. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| # The merge keeps exactly one POST operation for the shared path. | ||
| path_item = spec["paths"]["/api/dup"] | ||
| assert list(path_item.keys()) == ["post"] | ||
|
|
A METHOD path collision between two @openapi registrations silently dropped the earlier operation, surfacing only as a log line — so --fail-on-warnings could not observe a vanished endpoint (#386). Record each collision on a dedicated registry channel during generation and surface it through collect_spec_warnings as a DUPLICATE_OPERATION SpecWarning. Strict mode still raises.
c18ad47 to
0c4abb6
Compare
|
Resolved rebase conflicts against |
Summary
WarningCode.DUPLICATE_OPERATIONwas dead code: defined but never emitted and untested. AMETHOD pathcollision between two@openapiregistrations silently dropped the earlier operation, appearing only as alogger.warning— socollect_spec_warnings(...)returned[]and--fail-on-warningspassed green while an endpoint vanished from the spec.OpenAPIRegistrychannel (add_duplicate_operation/duplicate_operations, cleared inclear()) that records eachMETHOD pathcollision during generation._collect_duplicate_operation_warningssurfaces those records throughcollect_spec_warningsas a structuredDUPLICATE_OPERATIONSpecWarning, mirroring the discovery-skipped / binding-mismatch pattern.strict=Truebehaviour is unchanged (still raisesOpenAPISpecConfigError).Acceptance
DUPLICATE_OPERATIONwarning emitted on non-strict collision, in addition to the existing log.strict=Truestill raises.DUPLICATE_OPERATIONwarning, last op wins, and--fail-on-warningsexits non-zero.make check-allgreen; coverage stays >= 95%.Closes #386