Skip to content

fix(openapiv3): emit type:array for repeated query params (#161)#162

Merged
SebastienMelki merged 1 commit into
mainfrom
fix/openapi-repeated-query-params
Apr 23, 2026
Merged

fix(openapiv3): emit type:array for repeated query params (#161)#162
SebastienMelki merged 1 commit into
mainfrom
fix/openapi-repeated-query-params

Conversation

@SebastienMelki

Copy link
Copy Markdown
Owner

Summary

Fixes #161. protoc-gen-openapiv3 was rendering repeated <scalar> query params with the scalar type (e.g. type: string) instead of type: 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

createFieldSchema at internal/openapiv3/generator.go never checked field.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

  • Split createFieldSchema into scalar + list wrapper. Repeated fields now render as type: array with items: { ...scalar... }.
  • Emit style: form and explode: true on array query parameters. These are OpenAPI 3.1 defaults but explicit is safer for downstream tooling.

Test coverage

Extended SearchAdvancedRequest in internal/httpgen/testdata/proto/query_params.proto to cover repeated string, repeated int32, and repeated bool (addressing the issue's scope audit request). Golden files regenerated across openapiv3, httpgen, clientgen, tsclientgen, tsservergen.

Added a repeated string role_in query param to the multi-service-api bundle example so the fix is visible in generated docs — see examples/multi-service-api/docs/UserService.openapi.yaml and docs/openapi.yaml after running make generate.

Test plan

  • go test ./... — all packages pass
  • make lint-fix — 0 issues
  • Regenerated examples/multi-service-api and confirmed role_in appears as type: array with style: form / explode: true in both the per-service and bundle specs
  • Reviewer: pull the branch, cd examples/multi-service-api && buf generate, inspect docs/openapi.yaml for the role_in parameter

🤖 Generated with Claude Code

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

codecov Bot commented Apr 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 2.83%. Comparing base (e6a88ce) to head (1717637).
⚠️ Report is 3 commits behind head on main.

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              
Flag Coverage Δ
unittests 2.83% <ø> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

Copy link
Copy Markdown

🔍 CI Pipeline Status

Lint: success
Test: success
Coverage: success
Build: success
Integration: success


📊 Coverage Report: Available in checks above
🔗 Artifacts: Test results and coverage reports uploaded

@SebastienMelki
SebastienMelki merged commit 8045798 into main Apr 23, 2026
10 checks passed
@SebastienMelki
SebastienMelki deleted the fix/openapi-repeated-query-params branch April 23, 2026 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

protoc-gen-openapiv3: repeated string query params typed as type: string instead of type: array

1 participant