Skip to content

feat(core): validate operationId uniqueness and warn on duplicates#52

Open
halotukozak wants to merge 1 commit intomasterfrom
feat/validate-operation-id-uniqueness
Open

feat(core): validate operationId uniqueness and warn on duplicates#52
halotukozak wants to merge 1 commit intomasterfrom
feat/validate-operation-id-uniqueness

Conversation

@halotukozak
Copy link
Copy Markdown
Member

Summary

  • SpecValidator now detects duplicate operationId values across all operations
  • Emits a warning listing the conflicting path+method pairs
  • Code generation still succeeds — NameRegistry deduplication handles it, this is informational

Closes #40

Test plan

  • Test: spec with duplicate operationId emits warning mentioning the ID
  • Test: petstore spec has no duplicate warnings
  • ktlint passes
  • All existing tests pass

🤖 Generated with Claude Code

SpecValidator now detects duplicate operationId values across all
operations and emits a warning listing the conflicting path+method pairs.
Code generation still succeeds via NameRegistry deduplication.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 9, 2026 18:48
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds validation in the OpenAPI parsing pipeline to detect non-unique operationId values and surface them as non-fatal warnings, helping users proactively fix specs that could otherwise lead to confusing generated API method naming.

Changes:

  • Extend SpecValidator to detect and warn on duplicate operationId values across all operations.
  • Add parser-level tests verifying a duplicate emits a warning and that petstore.yaml emits none.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecValidator.kt Collects all operations, groups by operationId, and emits an accumulated warning for duplicates.
core/src/test/kotlin/com/avsystem/justworks/core/parser/SpecParserTest.kt Adds tests asserting duplicate operationId warnings are surfaced via ParseResult.warnings and that petstore has no such warnings.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +42 to +53
val operations = openApi.paths.orEmpty().flatMap { (path, pathItem) ->
pathItem.readOperationsMap().mapNotNull { (method, op) ->
op.operationId?.let { Triple(it, method.name, path) }
}
}
val operationIds = operations.groupBy { it.first }

for ((opId, occurrences) in operationIds) {
ensureOrAccumulate(occurrences.size == 1) {
val locations = occurrences.joinToString { "${it.second} ${it.third}" }
Issue.Warning("Duplicate operationId '$opId' found at: $locations")
}
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

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

The duplicate-warning message order depends on the iteration order of paths and readOperationsMap() (and then groupBy preserving that order). To keep warnings deterministic (and easier to scan / test), consider sorting occurrences (e.g., by path then method) before joinToString.

Copilot uses AI. Check for mistakes.
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.

Validate operationId uniqueness and warn on duplicates

2 participants