feat(core): validate operationId uniqueness and warn on duplicates#52
feat(core): validate operationId uniqueness and warn on duplicates#52halotukozak wants to merge 1 commit intomasterfrom
Conversation
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>
There was a problem hiding this comment.
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
SpecValidatorto detect and warn on duplicateoperationIdvalues across all operations. - Add parser-level tests verifying a duplicate emits a warning and that
petstore.yamlemits 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.
| 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") | ||
| } |
There was a problem hiding this comment.
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.
Summary
SpecValidatornow detects duplicateoperationIdvalues across all operationsNameRegistrydeduplication handles it, this is informationalCloses #40
Test plan
operationIdemits warning mentioning the ID🤖 Generated with Claude Code