Skip to content

fix(api): swap route registration order to prevent wildcard route hijacking list#167

Open
yuyudeqiu wants to merge 1 commit into
go-kratos:mainfrom
yuyudeqiu:fix/todo-route-priority
Open

fix(api): swap route registration order to prevent wildcard route hijacking list#167
yuyudeqiu wants to merge 1 commit into
go-kratos:mainfrom
yuyudeqiu:fix/todo-route-priority

Conversation

@yuyudeqiu

@yuyudeqiu yuyudeqiu commented Jun 27, 2026

Copy link
Copy Markdown

Description

In api/todo/v1/todo.proto, the GetTodo RPC (/v1/todos/{id}) was defined before the ListTodos RPC (/v1/todos/list).

Because Kratos registers routes in the order they are defined in the Proto file, the generated HTTP handlers in todo_http.pb.go registered the wildcard route /v1/todos/{id} first. Consequently, requests to GET /v1/todos/list were intercepted by the GetTodo handler with id="list", causing a decoding failure (400 Bad Request):

{"code":400, "reason":"CODEC", "message":"parsing field \"id\": strconv.ParseInt: parsing \"list\": invalid syntax"}

Changes

  • Swapped ListTodos and GetTodo order in api/todo/v1/todo.proto to ensure /v1/todos/list is registered first.
  • Regenerated the protobuf and HTTP client/server stubs.

Verification & Testing

Tested locally with the HTTP server:

  • POST /v1/todos/create succeeds.
  • GET /v1/todos/list correctly hits the list endpoint and returns the collection list.
  • GET /v1/todos/{id} correctly fetches single items and returns 404 for non-existent IDs.

@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Jun 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant