feat: add explode() annotation for OpenAPI 3.x parameters#2135
Open
curiosity-the-rover wants to merge 1 commit intoswaggo:v2from
Open
feat: add explode() annotation for OpenAPI 3.x parameters#2135curiosity-the-rover wants to merge 1 commit intoswaggo:v2from
curiosity-the-rover wants to merge 1 commit intoswaggo:v2from
Conversation
Add support for the explode() annotation to explicitly set the explode property on query/path/header parameters in OpenAPI 3.x. Usage: // @param ids query []string true "ID List" explode(false) // @param tags query []string true "Tag List" explode(true) This allows users to control whether array/object parameters are serialized as: - explode(true): ?ids=a&ids=b&ids=c (repeated params) - explode(false): ?ids=a,b,c (comma-separated) Changes: - operation.go: Add explodeTag constant and regex pattern - operationv3.go: Add setExplodeParamV3 function and case in switch - operationv3_test.go: Add tests for explode(true/false/invalid) Closes: swaggo#2134
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
Add support for the
explode()annotation to explicitly set theexplodeproperty on query/path/header parameters in OpenAPI 3.x.Closes #2134
Usage
This allows users to control whether array/object parameters are serialized as:
explode(true):?ids=a&ids=b&ids=c(repeated params, default for form style)explode(false):?ids=a,b,c(comma-separated)Changes
operation.go: AddexplodeTagconstant and regex patternoperationv3.go: AddsetExplodeParamV3function and case in switchoperationv3_test.go: Add tests forexplode(true/false/invalid)Generated Output
Testing
All existing tests pass, plus new tests added for:
explode(true)- sets explode to trueexplode(false)- sets explode to falseexplode(invalid)- returns appropriate errorNote
Important: For
explode: falseto be properly serialized in YAML/JSON output, the upstream dependencysv-tools/openapineeds to changeExplodefromboolto*bool. See: sv-tools/openapi#132Once that PR is merged, this PR should update the dependency and change the implementation to use
*bool.