feat: add sum type parameter support#1581
Merged
ernado merged 3 commits intoogen-go:mainfrom Nov 25, 2025
Merged
Conversation
Member
|
Please rebase and re-generate |
Implement support for oneOf, anyOf, and allOf sum types in path, query, header, and cookie parameters. Previously sum types only worked in request/response bodies. Changes: - gen_parameters.go: Enable sum type validation in isParamAllowed() by recursively validating each variant instead of returning ErrNotImplemented - uri/encode.tmpl: Add encoding via discriminator-based type switch - uri/decode.tmpl: Add decoding via fallback strategy that tries each variant in order until one succeeds Closes #3
Add comprehensive test coverage for sum type parameter support: - Update gen_test.go to remove 'sum type parameter' from unimplemented features list (now implemented) - Add basic generation test with path/query parameter examples - Add integration test with default error responses Test scenarios: - Path parameter with anyOf: [uuid, integer] - Query parameter with anyOf: [string, integer] - Both required and optional parameter cases
c0b41c3 to
ef36d29
Compare
The GitHub OpenAPI spec generated slightly different validation code. This is expected when rebasing onto a newer base with template changes.
ernado
approved these changes
Nov 25, 2025
lanej
added a commit
to lanej/ogen
that referenced
this pull request
Nov 25, 2025
These files were incorrectly deleted - they test sum type parameters (feature from PR ogen-go#1581), not sum type discrimination (this PR). Restored files: - _testdata/positive/sum_type_params.yaml - internal/integration/test_sum_params/test_sum_params.yaml
lanej
added a commit
to lanej/ogen
that referenced
this pull request
Nov 25, 2025
These test files were incorrectly restored. They belong to PR ogen-go#1581 (sum type parameters) which hasn't been fully merged into this branch yet. Removing them to fix test failures.
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
Adds support for OpenAPI 3.x
oneOfandanyOfsum types in parameters - path, query, header, and cookie. Previously sum types only worked in request/response bodies.Note:
allOfis for schema merging (intersection), not sum types, and already worked.Fixes lanej#3
Changes
gen_parameters.goExample
Before: Generation failed with "sum type parameter not implemented"
After: Works seamlessly
Generated code:
Testing
anyOf: [uuid, integer]anyOf: [string, integer]