Skip to content

fix(fetch): restore urlEncodeParameters support for the fetch client (#3343) - #3405

Merged
melloware merged 6 commits into
orval-labs:masterfrom
zeriong:fix/fetch-url-encode-parameters-3343
May 20, 2026
Merged

fix(fetch): restore urlEncodeParameters support for the fetch client (#3343)#3405
melloware merged 6 commits into
orval-labs:masterfrom
zeriong:fix/fetch-url-encode-parameters-3343

Conversation

@zeriong

@zeriong zeriong commented May 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #3343.

The fetch client generator stopped honoring the urlEncodeParameters output option after commit cb06139 (#2168) accidentally dropped the guard introduced by #2292. As a result, generated get<Op>Url helpers interpolated path parameters into the URL template literal as-is, so values containing reserved characters (/, #, ?, ...) leaked into the request URL. The axios path in @orval/query was unaffected because it has its own makeRouteSafe call site.

This PR re-applies makeRouteSafe(route) at the top of generateRequestFunction in @orval/fetch, mirroring the axios path. Each ${param} segment in the generated URL is wrapped with encodeURIComponent(String(...)) when urlEncodeParameters: true. Query parameters remain handled by URLSearchParams (no double encoding); this option only affects path parameters.

The fix is split across three commits to keep review surgical:

  1. refactor(core,query) — relocate makeRouteSafe and wrapRouteParameters from @orval/query/utils to @orval/core/getters/route so @orval/fetch can reuse them without introducing a reverse dependency on @orval/query. Unit tests move alongside. No behavior change.
  2. fix(fetch) — apply the guard, and add a dedicated fetch + urlEncodeParameters snapshot fixture so a future regression in the fetch path won't be silently absorbed by the existing dateParams fixture.
  3. docs(output) — clarify that the option only wraps path parameters and that array/object path params fall back to String(value) (orval does not generate style: simple|matrix|label for path parameters).

Scope notes

  • pathRoute (used for OpenAPI spec lookup, e.g. MSW handlers) is intentionally left unencoded — it is a literal OpenAPI path string used as a key, not a runtime URL.
  • The angular HTTP client path in @orval/query has the same gap but is out of scope for this issue (urlEncodeParameters option not working ? #3343 reports the fetch case); it can be tracked separately if desired.
  • Array/object path parameter style serialization (OpenAPI style: simple|matrix|label + explode) is unimplemented before and after this PR. Documented as a known limitation.

Test plan

  • bun run build passes
  • bun run lint passes
  • bun run typecheck passes
  • bun vitest run — only pre-existing resolve-version.test.ts failures unrelated to this PR (verified by stashing the diff and re-running)
  • bun run test:snapshots passes; snapshot diffs are limited to:
    • tests/__snapshots__/fetch/url-encode-parameters/ (new fixture, exercises the fix)
    • tests/__snapshots__/fetch/dateParams/pets/pets.ts (existing fetch fixture now correctly emits encodeURIComponent(String(...)))
    • tests/__snapshots__/vue-query/url-encode-parameters/endpoints.ts and tests/__snapshots__/vue-query/combination-used-by-maxim-mazurok/endpoints.ts (vue-query defaults to the fetch HTTP client; same fix flows through)
  • No untracked files unrelated to the PR

Summary by CodeRabbit

  • New Features

    • Generated clients now percent-encode path parameters when urlEncodeParameters is enabled.
  • Documentation

    • Clarified that path parameters are wrapped with encodeURIComponent(String(...)), query parameter encoding is delegated to the client, and array/object path values are stringified via String(value).
  • Tests

    • Added and updated tests covering parameter encoding and template-wrapping behavior.

Review Change Stack

zeriong added 3 commits May 20, 2026 22:06
Move makeRouteSafe and wrapRouteParameters from @orval/query/utils into
@orval/core/getters/route so non-query packages can reuse them without
introducing a reverse dependency on @orval/query. Update query/src/client.ts
to import makeRouteSafe from @orval/core and move the related unit tests
to core/getters/route.test.ts. Behavior is unchanged.

This prepares for the follow-up fix that restores urlEncodeParameters
support in @orval/fetch (orval-labs#3343).

Signed-off-by: zeriong <jaeryong95@gmail.com>
The fetch client generator stopped honoring the `urlEncodeParameters`
output option after commit cb06139 (orval-labs#2168) accidentally dropped the
guard introduced by orval-labs#2292. Generated URL helpers interpolated path
parameters as-is, so values containing reserved characters (`/`, `#`,
`?`, ...) leaked into the request URL.

Re-apply `makeRouteSafe(route)` at the top of `generateRequestFunction`
in `@orval/fetch`, mirroring the axios path in `@orval/query`. This wraps
each `\${param}` segment with `encodeURIComponent(String(...))`. Query
parameters remain handled by `URLSearchParams` as before; this option
only affects path parameters.

Add a dedicated fetch + `urlEncodeParameters` snapshot fixture so a
future regression in the fetch path won't be silently absorbed by the
`dateParams` fixture.
State explicitly that the option wraps only path parameters (query
parameters are already encoded by the underlying client) and note that
array/object path parameters fall back to `String(value)` instead of
following their OpenAPI `style` serialization, since orval does not
generate `style: simple|matrix|label` for path parameters.
@coderabbitai

coderabbitai Bot commented May 20, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c50c2101-536f-488d-9c19-01c4989dc975

📥 Commits

Reviewing files that changed from the base of the PR and between 4a2b268 and 6f3339f.

📒 Files selected for processing (1)
  • tests/__snapshots__/fetch/url-encode-parameters/endpoints.ts

📝 Walkthrough

Walkthrough

Adds core helpers to wrap template path parameters with encodeURIComponent(String(...)), applies them conditionally in the fetch generator when urlEncodeParameters is enabled, removes duplicate helpers from the query package, updates docs/config, and refreshes generated snapshots to reflect encoded path segments.

Changes

URL Parameter Encoding

Layer / File(s) Summary
Core routing parameter wrapping helpers
packages/core/src/getters/route.ts, packages/core/src/getters/route.test.ts
wrapRouteParameters and makeRouteSafe utilities wrap route template ${param} segments with encodeURIComponent(String(...)), with tests for single/adjacent params, separators, no-parameter, and empty-route cases.
Fetch generator integration
packages/fetch/src/index.ts
Fetch generator conditionally applies makeRouteSafe to the request URL route when context.output.urlEncodeParameters is true before other parameter handling.
Query package consolidation
packages/query/src/client.ts, packages/query/src/utils.ts, packages/query/src/utils.test.ts
Removes duplicate wrapRouteParameters and makeRouteSafe from query utilities and updates imports to use the core versions instead.
Documentation and test configuration
docs/content/docs/reference/configuration/output.mdx, tests/configs/fetch.config.ts
Docs updated to state path params are encoded with encodeURIComponent(String(...)), query encoding is delegated to the client, and arrays/objects stringify via String(value); adds fetch config enabling urlEncodeParameters.
Generated snapshots
tests/__snapshots__/fetch/url-encode-parameters/endpoints.ts, tests/__snapshots__/fetch/dateParams/pets/pets.ts, tests/__snapshots__/vue-query/*/endpoints.ts
Generated URL helpers and client snapshots now percent-encode path segments (e.g., encodeURIComponent(String(petId))) across fetch and vue-query outputs; adds full fetch snapshot covering all endpoints.

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

fetch

Suggested reviewers

  • melloware
  • soartec-lab

"🧑‍💻🐇
I hopped through templates with care,
Wrapped each param in encoded air,
No more slashes, dots, or weird char pain,
Paths now safe for sun and rain,
Hooray — the routes are snug and sane!"

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main fix: restoring urlEncodeParameters support specifically for the fetch client, addressing issue #3343.
Linked Issues check ✅ Passed The PR successfully addresses all coding objectives from issue #3343: restoring urlEncodeParameters encoding for fetch-generated clients using encodeURIComponent(String(...)) for path parameters while preserving query parameter handling via URLSearchParams, and limiting changes to runtime URL generation.
Out of Scope Changes check ✅ Passed All changes are in scope: moving makeRouteSafe/wrapRouteParameters to core for reuse across fetch and query, applying the fix to fetch's generateRequestFunction, updating related tests, and documenting the behavior. No unrelated refactoring or features were introduced.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

zeriong and others added 3 commits May 20, 2026 22:36
…t drift

The model files generated by this fixture exhibited a JSDoc reflow only
on CI (Ubuntu) that didn't reproduce locally, while the same petstore
spec under other fixtures stayed stable. Drop `schemas` and `mock` from
the fixture so it only emits `endpoints.ts`; that single file still
exercises the regression covered by orval-labs#3343 — `${encodeURIComponent(
String(petId))}` is asserted in the URL helper output.
After the master merge of orval-labs#3393 (`fix(core): handle multi-line
descriptions in JSDoc generation`), the core now emits multi-line
JSDoc with proper ` * ` line prefixes. Regenerate the snapshot for
this PR's new fixture so it matches the post-orval-labs#3393 output. The
`encodeURIComponent(String(petId))` assertions covering orval-labs#3343 are
preserved.
@melloware melloware added the fetch Fetch client related issue label May 20, 2026
@melloware
melloware merged commit 90532f4 into orval-labs:master May 20, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fetch Fetch client related issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

urlEncodeParameters option not working ?

2 participants