[dart-dio] fix: URI-encode path parameters

Merged
IN
4h ago
+98-40

Fixes #25527.

The dart-dio generator built request paths by substituting path parameters through the api/query_param helper — which (for built_value) passes strings through unchanged and (for freezed / json_serializable) interpolates the raw value. A path parameter containing /, spaces, or other reserved characters was therefore sent unencoded and broke the request path (e.g. a scanned QR-code URL as {bin} → 404).

What changed

  • New serialization/<library>/api/path_param.mustache for all three serialization libraries (built_value, freezed, json_serializable) wrapping the existing query_param rendering in Uri.encodeComponent(...) — suggested in the issue and credited to the reporter.
  • api.mustache now substitutes path parameters via api/path_param instead of api/query_param.

Uri.encodeComponent encodes the value as a single path component (including / → %2F), so values containing slashes stay within one segment — exactly the failing scenario from the issue.

Verification

  • New unit test testPathParamsAreUriEncoded generates the petstore client for all three serialization libraries and asserts Uri.encodeComponent( appears in the generated API classes. DartDioClientCodegenTest: 20 tests, 0 failures.
  • Regenerated all 9 dart-dio sample configs; every path substitution now goes through Uri.encodeComponent.
  • dart analyze on the regenerated built_value petstore sample: no issues (one pre-existing unrelated unused_import warning).

PR checklist

  • Read the contribution guidelines.
  • Regenerated the affected samples via ./bin/generate-samples.sh (all dart-dio configs); no files deleted.
  • Pull request is created against the master branch.

Summary by cubic

Fixes #25527. Generated dart-dio clients now URI-encode path parameters, so values containing / or spaces no longer break the request path.

  • Path parameters are substituted via a new api/path_param partial for all three serialization libraries (built_value, freezed, json_serializable), wrapping the value in Uri.encodeComponent on a single line to keep the generated path style unchanged.
  • api.mustache now uses this partial for path parameters instead of the query-param rendering.
  • Adds a unit test covering all three serialization libraries that asserts every path substitution in each generated API class is URI-encoded, and regenerates the affected samples.
  • Pins source_helper to >=1.3.8 <1.4.0 in the freezed variant's pubspec.mustache; version 1.4.0 added extension members that clash with json_serializable 6.x and break the build_runner build script, while 1.3.9+ requires Dart 3.9 (above the variant's advertised >=3.8.0).