Implement AllowReserved support for path parameters with URL encoding#550
Draft
Implement AllowReserved support for path parameters with URL encoding#550
Conversation
Co-authored-by: RickWinter <4430337+RickWinter@users.noreply.github.com>
Co-authored-by: RickWinter <4430337+RickWinter@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Support AllowReserved in Path Implementation
Implement AllowReserved support for path parameters with URL encoding
Aug 8, 2025
RickWinter
reviewed
Aug 8, 2025
| expect(useText).toContain('percent_encode'); | ||
| expect(useText).toContain('CONTROLS'); | ||
| }); | ||
| }); No newline at end of file |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR implements proper support for the
allowReservedproperty in path parameters by adding URL encoding logic to the TypeSpec Rust emitter.Problem
The TypeSpec Rust emitter was not handling the
allowReservedproperty for path parameters correctly. The issue manifested in two ways:param.allowReservedvalue was being passed directly as theencodedparameter, when it should be inverted (!param.allowReserved)encodedproperty was defined but never used in code generation, so path parameters were always replaced using simple string substitution without any URL encodingThis meant that reserved characters (like
/,?,#,[,],@, etc.) in path parameter values were not being properly URL-encoded, which could lead to malformed URLs and incorrect API calls.Solution
1. Fixed Semantic Inversion
Updated
src/tcgcadapter/adapter.tsto correctly mapallowReservedto theencodedproperty:allowReserved=false(default):encoded=true(apply URL encoding)allowReserved=true:encoded=false(skip URL encoding)2. Implemented URL Encoding Logic
Added comprehensive URL encoding support in
src/codegen/clients.ts:percent_encode()to the entire parameter value whenencoded=trueThe implementation uses
url::percent_encoding::percent_encodewith theCONTROLSencode set for proper URL path encoding.3. Added Test Coverage
Created
test/allowreserved.test.tswith comprehensive tests that verify:allowReservedvalueExample
Before this change, a path parameter with value
"foo/bar"would be inserted directly:After this change, with
allowReserved=false(default):With
allowReserved=true:Fixes #82.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.