feat: merge duplicate status code responses into oneOf#44
Open
oscarbc96 wants to merge 1 commit intooaswrap:mainfrom
Open
feat: merge duplicate status code responses into oneOf#44oscarbc96 wants to merge 1 commit intooaswrap:mainfrom
oscarbc96 wants to merge 1 commit intooaswrap:mainfrom
Conversation
When two responses share the same HTTP status code and content type, the second silently overwrites the first. Fix this by grouping duplicate responses and combining them via jsonschema.OneOf(). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
200 application/jsonresponses with different structs), the second silently overwrites the first in the upstreamopenapi-golibraryoperationContextImpl.build()before callingAddRespStructure, grouping duplicates by(HTTPStatus, ContentType), and merging groups with >1 entry into a singleoneOfresponse viajsonschema.OneOf()— a helper already supported upstreamWhat's included
operation.go— newmergeResponseshelper + updatedbuild():(HTTPStatus, ContentType)keyjsonschema.OneOf(s1, s2, ...), first entry's description preserved, singleContentUnitproducedrouter_test.go— new"Duplicate Status Code Responses"test case that registers two200responses with different structs on the same endpointtestdata/duplicate_status_code_responses_3.yaml— golden file for OpenAPI 3.0testdata/duplicate_status_code_responses_31.yaml— golden file for OpenAPI 3.1Generated output
Both golden files confirm the
oneOfoutput:How to test
This was developed using Claude Code. To test before this is merged, you can use Go module replacements in your
go.mod:🤖 Generated with Claude Code