Skip to content

fix: support enum fields in query and path parameters#152

Open
shavaizknz wants to merge 3 commits into
SebastienMelki:mainfrom
shavaizknz:fix/enum-query-param-support
Open

fix: support enum fields in query and path parameters#152
shavaizknz wants to merge 3 commits into
SebastienMelki:mainfrom
shavaizknz:fix/enum-query-param-support

Conversation

@shavaizknz
Copy link
Copy Markdown
Collaborator

Summary

  • Add protoreflect.EnumKind case to convertStringToFieldValue so enum fields work as query/path parameters
  • Support both numeric values (e.g. 3) and proto enum name strings (e.g. TIMEFRAME_ALL) via the field's enum descriptor
  • Change function signature from (string, protoreflect.Kind) to (string, protoreflect.FieldDescriptor) to enable enum name lookup

Fixes #151

Test plan

  • All existing golden file tests pass (UPDATE_GOLDEN=1 go test to regenerate)
  • All internal/... tests pass
  • Verify with a proto service that uses an enum query parameter (e.g. ?timeframe=TIMEFRAME_ALL)
  • Verify numeric enum values also work (e.g. ?timeframe=3)

🤖 Generated with Claude Code

shavaizknz added a commit to shavaizknz/sebuf that referenced this pull request Apr 19, 2026
… example

Address all review feedback from SebastienMelki#151 and PR SebastienMelki#152:

- Add forward-compat comment explaining why unknown enum numbers are
  accepted (proto3/protojson alignment)
- Improve error message to include enum type name:
  invalid value "FOO" for enum Timeframe
- Enable enum as path parameter type in isPathParamCompatible()
- Filter empty query param strings (?param=) as unset
- Fix TS server generator: cast enum path params (as Region) and
  repeated enum query params (as Region[])
- Add 11 runtime test cases covering valid name, numeric, UNSPECIFIED,
  unknown name/number, wrong case, empty string, repeated enum,
  and path param variants
- Add examples/enum-params/ with Timeframe + AssetClass enums
  demonstrating query and path parameter usage end-to-end
- Document supported query/path parameter types in http-generation.md
  with enum section and examples
- Regenerate all golden files across all 5 generators

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@shavaizknz
Copy link
Copy Markdown
Collaborator Author

Latest push addresses the review feedback:

Changes:

  • Added code comment explaining why unknown enum numbers are accepted (proto3 forward-compat / protojson alignment)
  • Improved error message to include enum type: invalid value "FOO" for enum Timeframe
  • isPathParamCompatible() now accepts EnumKind
  • Empty query param values (?param=) filtered as unset
  • Fixed TS server generator: enum path params now cast (as Region), repeated enum query params cast (as Region[]) — pre-existing gap exposed by the new test proto

Tests (11 runtime cases in internal/httpgen/enum_query_test.go):

  1. Query: valid enum name → 200
  2. Query: valid numeric → 200
  3. Query: UNSPECIFIED/0 → 200
  4. Query: unknown name → 400, violations with enum type in message
  5. Query: unknown number → 200 (forward-compat)
  6. Query: wrong case → 400
  7. Query: empty string → treated as unset
  8. Query: repeated enum (?regions=A&regions=B) → both parsed
    9a. Path: valid name → 200
    9b. Path: valid number → 200
    9c. Path: unknown name → 400

Example: examples/enum-params/ — portfolio service with Timeframe query param and AssetClass path param

Docs: Added "Supported Query & Path Parameter Types" section to http-generation.md with enum documentation, and added enum to query params example in client-generation.md

Co-authored-by: Claude Code

@shavaizknz shavaizknz force-pushed the fix/enum-query-param-support branch from 16cce80 to 356c332 Compare May 5, 2026 09:09
shavaizknz added a commit to shavaizknz/sebuf that referenced this pull request May 5, 2026
… example

Address all review feedback from SebastienMelki#151 and PR SebastienMelki#152:

- Add forward-compat comment explaining why unknown enum numbers are
  accepted (proto3/protojson alignment)
- Improve error message to include enum type name:
  invalid value "FOO" for enum Timeframe
- Enable enum as path parameter type in isPathParamCompatible()
- Filter empty query param strings (?param=) as unset
- Fix TS server generator: cast enum path params (as Region) and
  repeated enum query params (as Region[])
- Add 11 runtime test cases covering valid name, numeric, UNSPECIFIED,
  unknown name/number, wrong case, empty string, repeated enum,
  and path param variants
- Add examples/enum-params/ with Timeframe + AssetClass enums
  demonstrating query and path parameter usage end-to-end
- Document supported query/path parameter types in http-generation.md
  with enum section and examples
- Regenerate all golden files across all 5 generators

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@shavaizknz
Copy link
Copy Markdown
Collaborator Author

Test results after rebasing on main:

Passing (6/7 packages):

  • internal/annotations
  • internal/clientgen
  • internal/openapiv3
  • internal/tsclientgen
  • internal/tscommon
  • internal/tsservergen

Failing (1/7 packages):

  • internal/httpgen — 7 pre-existing consistency test failures (UnmarshalJSON vs UnmarshalJSONSebuf mismatch between go-http and go-client generators). These same tests fail on main at commit 4beef2b — not introduced by this PR.

All enum-specific tests pass, including the 11 runtime test cases in TestEnumQueryAndPathParams and all golden file comparisons.

Co-authored-by: Claude Code

@shavaizknz shavaizknz marked this pull request as ready for review May 5, 2026 09:15
@codecov
Copy link
Copy Markdown

codecov Bot commented May 5, 2026

Codecov Report

❌ Patch coverage is 0% with 66 lines in your changes missing coverage. Please review.
✅ Project coverage is 4.92%. Comparing base (1b08604) to head (ae34205).

Files with missing lines Patch % Lines
internal/tsservergen/generator.go 0.00% 66 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##            main    #152      +/-   ##
========================================
- Coverage   4.97%   4.92%   -0.06%     
========================================
  Files         35      35              
  Lines       4443    4490      +47     
========================================
  Hits         221     221              
- Misses      4218    4265      +47     
  Partials       4       4              
Flag Coverage Δ
unittests 4.92% <0.00%> (-0.06%) ⬇️

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.

@SebastienMelki
Copy link
Copy Markdown
Owner

Hi @shavaizknz thanks for the fix! Can you please review the linting issue happening on the PR? Thank you

shavaizknz and others added 2 commits May 18, 2026 13:17
The convertStringToFieldValue function lacked a case for
protoreflect.EnumKind, causing enum query/path parameters to fail with
"unsupported field type: enum". Add enum support that accepts both
numeric values (e.g. 3) and proto enum names (e.g. TIMEFRAME_ALL) by
looking up the value in the field's enum descriptor.

The function signature is changed from accepting protoreflect.Kind to
protoreflect.FieldDescriptor so the enum descriptor is available for
name-based lookup.

Fixes SebastienMelki#151

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… example

Address all review feedback from SebastienMelki#151 and PR SebastienMelki#152:

- Add forward-compat comment explaining why unknown enum numbers are
  accepted (proto3/protojson alignment)
- Improve error message to include enum type name:
  invalid value "FOO" for enum Timeframe
- Enable enum as path parameter type in isPathParamCompatible()
- Filter empty query param strings (?param=) as unset
- Fix TS server generator: cast enum path params (as Region) and
  repeated enum query params (as Region[])
- Add 11 runtime test cases covering valid name, numeric, UNSPECIFIED,
  unknown name/number, wrong case, empty string, repeated enum,
  and path param variants
- Add examples/enum-params/ with Timeframe + AssetClass enums
  demonstrating query and path parameter usage end-to-end
- Document supported query/path parameter types in http-generation.md
  with enum section and examples
- Regenerate all golden files across all 5 generators

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@shavaizknz shavaizknz force-pushed the fix/enum-query-param-support branch from 356c332 to 0c1f408 Compare May 18, 2026 08:28
- goimports: reformat enum_query_test.go and tsservergen/generator.go
- golines: wrap long lines in httpgen/generator.go and tsservergen/generator.go
- govet shadow: rename inner err variables (mkErr, writeErr) to avoid shadowing
  the outer err in TestEnumQueryAndPathParams

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@shavaizknz
Copy link
Copy Markdown
Collaborator Author

Linting issues resolved in the latest push. Reproduced locally with golangci-lint run and fixed:

  • goimports formatting in enum_query_test.go and tsservergen/generator.go
  • golines line-length in httpgen/generator.go and tsservergen/generator.go
  • govet shadow warnings in enum_query_test.go (renamed inner err to mkErr/writeErr)

All 9 actual CI checks now pass: Build Binaries, Coverage Analysis, Coverage Status Check, Integration Tests, Lint & Code Quality, Test (Go 1.26 macos + ubuntu), codecov/patch, codecov/project.

The only failure is "PR Status Summary", but checking the job details shows it fails with Resource not accessible by integration (HTTP 403) when trying to post a comment — not a code/test failure. This is likely because the source branch is on my fork and I wasn't a collaborator when the PR was opened, so the GitHub Actions token has limited write permissions for comments on this PR.

Co-authored-by: Claude Code

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.

Enum fields in query parameters return 'unsupported field type: enum'

2 participants