Skip to content

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

@shavaizknz

Description

@shavaizknz

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions