[dart-dio] fix: URI-encode path parameters
Merged
IN
4h ago+98+98+01234567890123456789-40-40-01234567890123456789
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.mustachefor all three serialization libraries (built_value,freezed,json_serializable) wrapping the existing query_param rendering inUri.encodeComponent(...)— suggested in the issue and credited to the reporter. api.mustachenow substitutes path parameters viaapi/path_paraminstead ofapi/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
testPathParamsAreUriEncodedgenerates the petstore client for all three serialization libraries and assertsUri.encodeComponent(appears in the generated API classes.DartDioClientCodegenTest: 20 tests, 0 failures. - Regenerated all 9
dart-diosample configs; every path substitution now goes throughUri.encodeComponent. dart analyzeon the regeneratedbuilt_valuepetstore sample: no issues (one pre-existing unrelatedunused_importwarning).
PR checklist
- Read the contribution guidelines.
- Regenerated the affected samples via
./bin/generate-samples.sh(alldart-dioconfigs); no files deleted. - Pull request is created against the
masterbranch.
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_parampartial for all three serialization libraries (built_value,freezed,json_serializable), wrapping the value inUri.encodeComponenton a single line to keep the generated path style unchanged. api.mustachenow 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_helperto>=1.3.8 <1.4.0in thefreezedvariant'spubspec.mustache; version 1.4.0 added extension members that clash withjson_serializable6.x and break thebuild_runnerbuild script, while 1.3.9+ requires Dart 3.9 (above the variant's advertised >=3.8.0).