Skip to content

[rpc-codegen] Percent-encode generated path parameters #670

@kang-heewon

Description

@kang-heewon

Priority

P1

Problem

Generated RPC clients interpolate path parameters directly into URL templates. Values containing /, spaces, ?, #, %, or other reserved characters can change the route path or query boundary instead of being treated as a single path segment.

Evidence

  • packages/rpc-codegen/src/libs/generate.ts builds path expressions by replacing :${paramName} with ${input.path.${paramName}}.
  • packages/rpc-codegen/src/tests/codegen.spec.ts currently expects const path = \/users/${input.path.id}`;`.
  • packages/rpc-codegen/src/tests/e2e.spec.ts also asserts direct interpolation for /users/:id.
  • Route path schemas are extracted from @Param in packages/protocols-core/src/libs/schemaBuilder.ts, so path parameters are first-class generated inputs.

Desired outcome

Generated clients preserve route semantics by percent-encoding path segment values before building URLs.

Proposed implementation path

  1. Update path expression generation to wrap each path parameter with encodeURIComponent(String(...)) or a small generated helper.
  2. Keep type generation unchanged; serialization should happen only in the generated request path.
  3. Add tests for path values containing /, spaces, and URL-reserved characters.
  4. Update existing expectations that currently assert raw interpolation.

Acceptance criteria

  • Generated clients encode each path parameter before interpolation.
  • Existing query serialization remains separate from path construction.
  • Round-trip tests prove an input like { path: { id: "a/b c" } } calls /users/a%2Fb%20c, not /users/a/b c.
  • Generated clients still compile without importing runtime dependencies.

Validation

  • pnpm test --filter=@croco/rpc-codegen
  • pnpm typecheck --filter=@croco/rpc-codegen
  • pnpm build --filter=@croco/rpc-codegen

Scope boundaries

  • This issue is limited to path segment encoding.
  • It does not change query parameter serialization or body serialization.
  • It does not introduce a configurable URL builder.

Metadata

Metadata

Assignees

Labels

P1Priority 1 issuebugSomething isn't workingtech-debtTechnical debt

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions