Description
When using a proto enum as a query parameter, the generated HTTP handler returns a validation error:
{
"violations": [
{
"field": "timeframe",
"description": "invalid value for query parameter timeframe: unsupported field type: enum"
}
]
}
Reproduction
Given this proto definition:
enum Timeframe {
TIMEFRAME_UNSPECIFIED = 0;
TIMEFRAME_DAILY = 1;
TIMEFRAME_WEEKLY = 2;
TIMEFRAME_ALL = 3;
}
message GetPortfolioRequest {
string account_id = 1;
Timeframe timeframe = 2 [(sebuf.http.query) = { name: "timeframe" }];
}
service PortfolioService {
rpc GetPortfolio(GetPortfolioRequest) returns (Portfolio) {
option (sebuf.http.config) = {
method: "GET"
path: "/api/v1/accounts/{account_id}/portfolio"
};
}
}
A request like GET /api/v1/accounts/123/portfolio?timeframe=TIMEFRAME_ALL fails with the above error.
Root Cause
The convertStringToFieldValue function in internal/httpgen/generator.go handles string, int, uint, bool, and float kinds but has no case for protoreflect.EnumKind. Enum query parameters fall through to the default error case.
Expected Behavior
Enum query parameters should be accepted as:
- Enum name strings (e.g.,
TIMEFRAME_ALL) — resolved via the field's enum descriptor
- Numeric values (e.g.,
3) — parsed directly as the enum number
Affected Components
protoc-gen-go-http — HTTP handler generator
- Both path parameters and query parameters are affected
Description
When using a proto enum as a query parameter, the generated HTTP handler returns a validation error:
{ "violations": [ { "field": "timeframe", "description": "invalid value for query parameter timeframe: unsupported field type: enum" } ] }Reproduction
Given this proto definition:
A request like
GET /api/v1/accounts/123/portfolio?timeframe=TIMEFRAME_ALLfails with the above error.Root Cause
The
convertStringToFieldValuefunction ininternal/httpgen/generator.gohandles string, int, uint, bool, and float kinds but has no case forprotoreflect.EnumKind. Enum query parameters fall through to the default error case.Expected Behavior
Enum query parameters should be accepted as:
TIMEFRAME_ALL) — resolved via the field's enum descriptor3) — parsed directly as the enum numberAffected Components
protoc-gen-go-http— HTTP handler generator