Fix inconsistent snippet selection for OpenAPI docs - #300
Merged
Merged
Conversation
As it is possible to provide multiple snippets for a single endpoint, the API documentation logic has to decide which snippets should define the identity of the merged operation or item. The previous fix introduced deterministic success-first selection for OpenAPI and OpenAPI 3, but the behavior was still not fully aligned across generators and operationId derivation rules. This change makes the behavior consistent across OpenAPI 2, OpenAPI 3, and Postman. A shared selection strategy is now used to pick primary candidates for merged identity. It prefers 2xx over non-2xx, applies status priority in the order 200, 201, 202, 204, then other 2xx, then prefers non-blank summary and description, and finally uses lexical operationId as a tie-breaker. A shared merged operationId rule is now used as well. The merged ID is derived from the common prefix across selected operationIds, with sorted concatenation as fallback when there is no common prefix. OpenAPI 2 now also derives operationId from merged candidates instead of taking it directly from one selected snippet. Postman top-level item id now follows the same merged operationId rule, while description and request defaults still come from the selected primary candidate. Tests were added and extended to cover success versus error-only merge selection, 200 preferred over 201, and no-common-prefix fallback behavior. The README now documents merged snippet identity selection and operationId derivation behavior consistently. This keeps the success-first intent, removes generator-specific drift, and avoids arbitrary naming caused by snippet input order.
meysamzamani
approved these changes
Sep 9, 2026
Fall back to the top-priority primary candidate's own operationId instead of sorted concatenation when merging operationIds with no common prefix, across OpenAPI 2, OpenAPI 3, and Postman. This avoids having to deal with very long, complicated and ugly operationIds such as `some-operation-someotheroperation-somemore-operations` when they don't share the prefix
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



As it is possible to provide multiple snippets for a single endpoint,
the API documentation logic has to decide which snippets should define
the identity of the merged operation or item.
Previously, OpenAPI 3 derived a merged operationId from the common
prefix of snippet operationIds, falling back to sorted concatenation
when no common prefix existed. OpenAPI 2 did not merge at all and
simply took the operationId of whichever snippet happened to be first,
which was arbitrary and order-dependent. Postman had its own partial
handling of the same problem.
This change makes the behavior consistent across OpenAPI 2, OpenAPI 3,
and Postman. A shared selection strategy is now used to pick primary
candidates for merged identity. It prefers 2xx over non-2xx, applies
status priority in the order 200, 201, 202, 204, then other 2xx, then
prefers non-blank summary and description, and finally uses lexical
operationId as a tie-breaker.
A shared merged operationId rule is now used as well. The merged ID is
derived from the common prefix across selected operationIds. When no
common prefix exists, the rule now falls back to the top-priority
candidate's own operationId instead of concatenating all sorted
operationIds. Concatenation produced unreadable, codegen-hostile
identifiers (e.g. "products-createvariation-products-create") for the
common and legitimate case of multiple snippets documenting the same
path and method, which broke generated client method names downstream.
This fallback change applies to OpenAPI 2, OpenAPI 3, and Postman alike,
since all three share the same merge rule.
OpenAPI 2 now also derives operationId from merged candidates instead of
taking it directly from one selected snippet. Postman top-level item id
now follows the same merged operationId rule, while description and
request defaults still come from the selected primary candidate.
Tests were added and extended to cover success versus error-only merge
selection, 200 preferred over 201, and no-common-prefix fallback
behavior across all three generators. The README and CHANGELOG now
document merged snippet identity selection and operationId derivation
behavior consistently.
This keeps the success-first intent, removes generator-specific drift,
and avoids both arbitrary naming caused by snippet input order and
unreadable concatenated names when no common prefix exists.
Fixes #255