fix(openapiv3): emit type:array for repeated query params (#161)#162
Merged
Conversation
repeated scalar query params were rendered as their scalar schema (e.g. type: string), so SDK generators consuming the spec produced single-valued fields even though our TS client/server correctly emit and parse ?foo=a&foo=b. bundle mode in v0.11.0 made this ship-visible to external consumers. Fix createFieldSchema to wrap repeated fields in an array schema, and emit style: form / explode: true on array query parameters. Extends the QueryParam golden coverage with repeated int32 and repeated bool, and adds a repeated string role_in filter to the multi-service-api bundle example. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #162 +/- ##
========================================
- Coverage 2.86% 2.83% -0.03%
========================================
Files 47 47
Lines 8273 9860 +1587
========================================
+ Hits 237 280 +43
- Misses 8032 9576 +1544
Partials 4 4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
🔍 CI Pipeline Status✅ Lint: success 📊 Coverage Report: Available in checks above |
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
Fixes #161.
protoc-gen-openapiv3was renderingrepeated <scalar>query params with the scalar type (e.g.type: string) instead oftype: array, even though our TS client/server correctly emit and parse?foo=a&foo=b. Any SDK generator consuming the spec (openapi-generator, kiota, Stoplight, etc.) would produce broken single-valued fields. Bundle mode in v0.11.0 made this ship-visible to external consumers.Root cause
createFieldSchemaatinternal/openapiv3/generator.gonever checkedfield.Desc.IsList(), so repeated fields fell through to the scalar branch.Not a regression from v0.11.0 — the bug pre-existed in per-service specs. A test case did exist (
SearchAdvancedRequest.countries), but the golden file had captured the buggy output (the proto comment literally said"bugs #3 and #4").Fix
createFieldSchemainto scalar + list wrapper. Repeated fields now render astype: arraywithitems: { ...scalar... }.style: formandexplode: trueon array query parameters. These are OpenAPI 3.1 defaults but explicit is safer for downstream tooling.Test coverage
Extended
SearchAdvancedRequestininternal/httpgen/testdata/proto/query_params.prototo coverrepeated string,repeated int32, andrepeated bool(addressing the issue's scope audit request). Golden files regenerated across openapiv3, httpgen, clientgen, tsclientgen, tsservergen.Added a
repeated string role_inquery param to the multi-service-api bundle example so the fix is visible in generated docs — seeexamples/multi-service-api/docs/UserService.openapi.yamlanddocs/openapi.yamlafter runningmake generate.Test plan
go test ./...— all packages passmake lint-fix— 0 issuesexamples/multi-service-apiand confirmedrole_inappears astype: arraywithstyle: form/explode: truein both the per-service and bundle specscd examples/multi-service-api && buf generate, inspectdocs/openapi.yamlfor therole_inparameter🤖 Generated with Claude Code