Skip to content

fix(warnings): emit DUPLICATE_OPERATION as a structured warning - #387

Merged
yeongseon merged 1 commit into
mainfrom
fix/386-duplicate-operation-warning
Aug 10, 2026
Merged

fix(warnings): emit DUPLICATE_OPERATION as a structured warning#387
yeongseon merged 1 commit into
mainfrom
fix/386-duplicate-operation-warning

Conversation

@yeongseon

Copy link
Copy Markdown
Owner

Summary

  • WarningCode.DUPLICATE_OPERATION was dead code: defined but never emitted and untested. A METHOD path collision between two @openapi registrations silently dropped the earlier operation, appearing only as a logger.warning — so collect_spec_warnings(...) returned [] and --fail-on-warnings passed green while an endpoint vanished from the spec.
  • Added a dedicated OpenAPIRegistry channel (add_duplicate_operation / duplicate_operations, cleared in clear()) that records each METHOD path collision during generation.
  • _collect_duplicate_operation_warnings surfaces those records through collect_spec_warnings as a structured DUPLICATE_OPERATION SpecWarning, mirroring the discovery-skipped / binding-mismatch pattern.
  • strict=True behaviour is unchanged (still raises OpenAPISpecConfigError).

Acceptance

  • Structured DUPLICATE_OPERATION warning emitted on non-strict collision, in addition to the existing log.
  • strict=True still raises.
  • Test: duplicate registration yields exactly one DUPLICATE_OPERATION warning, last op wins, and --fail-on-warnings exits non-zero.
  • make check-all green; coverage stays >= 95%.

Closes #386

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 OpenAPIRegistry via add_duplicate_operation(...) and clear them in OpenAPIRegistry.clear().
  • Surface recorded collisions as structured SpecWarning(code=DUPLICATE_OPERATION, ...) via _collect_duplicate_operation_warnings(...) and include them in collect_spec_warnings(...).
  • Add tests covering structured duplicate-operation warnings, strict-mode behavior, and CLI --fail-on-warnings exit 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.

Comment on lines +468 to +471
# 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.
@yeongseon
yeongseon force-pushed the fix/386-duplicate-operation-warning branch from c18ad47 to 0c4abb6 Compare August 10, 2026 11:21
@yeongseon

Copy link
Copy Markdown
Owner Author

Resolved rebase conflicts against main (empty-discovery + duplicate-operation warning channels now coexist in spec.py/registry.py). Addressed Copilot review: test_last_operation_wins_in_spec now asserts the surviving operation is the second registration (operationId == "post_second"), verifying "last wins" instead of merely "one survives". make check-all green.

@yeongseon
yeongseon merged commit 4826211 into main Aug 10, 2026
14 checks passed
@yeongseon
yeongseon deleted the fix/386-duplicate-operation-warning branch August 10, 2026 11:22
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.

fix(warnings): emit DUPLICATE_OPERATION as a structured warning

3 participants