You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Way to skip or specify to urlencode a parameter #851
Currently autorest has this extension x-ms-skip-url-encoding which lets tells that the parameter shouldn't be url encoded. We are lacking this functionality
I recently got some clarification on URL encoding from Darrel Miller:
URLs should be encoded at the point of construction. That is the only time when you know which parts are data elements in the URL. If a URL has been fully constructed, it should be considered sufficiently encoded [ref RFC 3986]
So I'm wondering when we would ever want to specify "x-ms-skip-url-encoding".
I would have expected "/" to be encoded in filePath, but maybe this is a special case. Do we have anything like this in any of the services we are planning for this semester?
As for a parameter/property that is a URL, these should always be encoded, so we don't need x-ms-skip-url-encoding for these.
which is at /repos/{owner}/{repo}/contents/{path} and would be that https://api.github.com/repos/octocat/Hello-World/contents/notes/hello.txt for notes/hello.txt as the path.
This I guess is the OpenAPI issue to support that built in OAI/OpenAPI-Specification#892, maybe that's how we need to think about it for that use case instead.
Mike Kistler (@mikekistler) example of case, scope in ARM is a url, like /subscription/123-456-789/resourceGroup/rgname and when you set a policy you do something like POST /subscription/123-456-789/resourceGroup/rgname/policy. The template will be defined as {scope}/policy. with scope tagged to NOT be encoded.
So wondering if the only case is really that we don't want to escape / but wouldn't we maybe still want to escape in between.
For example if the scope was /subscription/123-456/rg with spaces/bar (just supposing that was allowed)
Wondering if maybe what we want is a way to say that a path parameter is actually multiple segment:
@route("{*scope}/policy") // I think the way dotnet does it with a * prefix.
@route("{scope*}/policy") // With a * suffix
@route("{scope+}/policy") // With a + suffix
op test(@path scope: string);
Laurent Mazuel (@lmazuel) My point is that if we know something is a URL then we never want to encode it. It would be wrong to encode it. So there is no need to specify "skip-url-encoding" on URLs.
the path parameter type is uri and is used in @server value.
if path parameter is uri in an operation it gets encoded
A path parameter is marked as having multiple segments(multiple /)
In this case it wouldn't actually skip encoding completely, it would only need to skip encoding of /
How to mark a path parameter as having multiple segments(multiple /)
Option 1: Have a convention in the @route path
@route("{*scope}/policy") // I think the way dotnet does it with a * prefix.
@route("{scope*}/policy") // With a * suffix
@route("{scope+}/policy") // With a + suffix
op test(@path scope: string): void;
Pros:
Similar to a lot of web api framework
Cons:
Cannot reuse the parameter with this config. (But maybe that's better that way)
Option 2 Add a flag on @path decorator
@route("{scope}/policy") // With a + suffix
op test(@path({multi: true}) scope: string): void;
Pros:
Easier to reuse the parameter. When using this param wherever it will always skip encoding of /
Path parameters that may contain unencoded "/" are strongly discouraged as they make the REST API definition ambiguous. If we support this then we also need a linter message that flags these.
Cases in which the path parameter is a uri path (already appropriately url encoded)
Cases in which the path parameter consists of multiple segments that are not url encoded
Consider each of these in route and autoRoute cases. autoRoute will be much more prevalent in Azure
Is there a general need for specifying 'urlEncode' / 'skipUrlEncode' other than in path parameters?
Include expected representations in cadl-autorest and OpenAPI3
// using route template
route("{scope+}/policy")
op myOp(@path scope: string) : void;
// using array value to indicate multiple unencoded parts
@autoRoute
op myOp(@path scope: string[], @path name: string) : void;
// using multi to encode segment by segment
scope: "/subscription/mysub/rg/my+rg/providers/Microsoft.Provider/type/name/"
@autoRoute
op myOp(@path({multi: true}) scope: string, @path name: string): void;
// using skip encoding to skip encoding altogether
scope: "/subscription/mysub/rg/my+rg/providers/Microsoft.Provider/type/name/"
@autoRoute
op myOp(@path({skipEncoding: true}) scope: string, @path name: string): void;
//using type to skip encoding
@format("uri")
model uriPath is string;
scope: "/subscription/mysub/rg/my+rg/providers/Microsoft.Provider/type/name/"
op myOp(@path scope: uriPath, @path name: string): void;
However, in Azure APIs, there is a common pattern, originating in ARM but also used in data planes of entities that 'extend' other entities. This results in paths of variable length for the same operation, like:
Since {extended-entity-identifier} is unknown, could contain any number of segments, and does not actually change the operations over the extending resource, it makes sense to describe these as operations under a single path, rather than enumerating all of the possible paths and repeating the operations.
Personally I am favoring something like a UriPath type. This would allow clients to decide whether to accept an 'already encoded' path variable, or to accept an array of path segments or the like. Languages with Uri types might decide to use those Uri types. This also means we can maintain the current mechanisms we use to represent these operations in OpenAPI.We should propose how to represent them in OpenAPI3 as well.
Add an optional settings parameter to @path decorator that marks a path as multi-segment
@path({multi: true}) myMultiSegmentPath: string
This would be used for parameters that represent path segments that may contain a '/' and should not be url encoded
Sample usage: extension resources
// extensionUri is a multi-segment path to the resource the extension applies to
// 'name' is the name of the FooExtension resource
@route("{extensionUri}/fooextension/{name}")
op getFooExtension(@path({multi: true}) extensionUri: string, @path name: string): Foo | Error;
Representation in cadl-autorest
While it is technically invalid, this pattern is common in autorest-inflected swagger. A urlPath parameter should be marked with the 'x-ms-skip-url-encoding' extension:
It seems that we should add this extension to OpenAPI3, as in cases like this, there are no real alternatives.
Scenario Coverage
Case
Code
Behavior
1. Simple string param
op simple(@path foo: string)
Encode foo
2. Uri param
op simple(@path foo: uri)
Encode foo
3. Param is a string but I don't want to encode /
op simple(@path({multi: true}) foo: string)
Don't encode the /
4. Param is an array of string
op simple(@path foos: string[])
Encode each foo and join with /. Note that @autoRoute would have to be expanded to allow this
Alternative implementation - explicitly skip URL encoding
We could differentiate between the multi-segment path scenario and other scenarios in which a parameter should not be url encoded, by adding a skipUrlEncoding property to @path and @query decorators
It feels like any explicit directive to skip url encoding a parameter is specifically a client concern, and likely belongs in the DPG library, rather than in a more core library
Alternative implementation - Only use array types to indicate multiple segments
@path myMultiSegmentPath: string[]
This might cause some problems with how autoroute currently functions
Per RFC 3986 model a type similar to relative-reference that represents fully-encoded url paths in cadl/http.
@format("uri")
model urlPath is string;
Relative and absolute paths
The spec describes 3 types of relative-references:
Absolute paths, starting with '/'
Relative paths, not starting with '/'
Network paths (disused), starting with '//'
The proposal is to use a single type to represent the common absolute and relative paths, as this provides all necessary information about encoding.
An alternate idea is to provide individual types for relative and absolute paths, but this would largely be for documentary purposes, as we would expect any processor to correctly handle leading and trailing slashes.
Emitters would represent relative and absolute url paths, consistent with the relative-reference concept, producing the following default behavior
Case
Code
Behavior
1. string in path
op simple(@path foo: string)
Encode foo
2. urlPath in path
op simple(@path foo: urlPath)
Don't encode
3. uri in path
op simple(@path foo: uri)
encode reserved characters
4. string in query
op simple(@query foo: string)
Encode foo
5. urlPath in query
op simple(@query foo: urlPath)
Don't encode
6. uri in query
op simple(@query foo: uri)
Don't encode*
7. Path Param is an array of string
op simple(@path foos: string[])
Encode each foo and join with /.
for backward compatibility with older processors, it may be desirable to encode '/' and '?' in query parameters
Note that here, we are discounting use of the 'network-path' option for relative-path (paths starting with //), as the spec indicates that this is a disused pattern, and we have never seen it. However, we could add a networkPath type in the future, if needed.
Activity
markcowl commentedon Aug 16, 2022
pri: 0
tjprescott commentedon Aug 17, 2022
I'd be happy to work on this but I can't assign myself.
mikekistler commentedon Aug 17, 2022
I recently got some clarification on URL encoding from Darrel Miller:
So I'm wondering when we would ever want to specify "x-ms-skip-url-encoding".
timotheeguerin commentedon Aug 17, 2022
/file/{filePath}I think a path parameter like that you don't want/to be encoded no?Or if the type is
urifor the server variables. but for that one we can maybe auto guessmikekistler commentedon Aug 17, 2022
I would have expected "/" to be encoded in
filePath, but maybe this is a special case. Do we have anything like this in any of the services we are planning for this semester?As for a parameter/property that is a URL, these should always be encoded, so we don't need
x-ms-skip-url-encodingfor these.timotheeguerin commentedon Aug 17, 2022
I mean in this case
I do feel like this is something we need to support. For example github api to get files:
https://docs.github.com/en/rest/repos/contents
which is at
/repos/{owner}/{repo}/contents/{path}and would be thathttps://api.github.com/repos/octocat/Hello-World/contents/notes/hello.txtfornotes/hello.txtas the path.This I guess is the OpenAPI issue to support that built in OAI/OpenAPI-Specification#892, maybe that's how we need to think about it for that use case instead.
For usage needed Travis Prescott (@tjprescott) had a service who needed and can probably tell us more.
lmazuel commentedon Aug 17, 2022
Mike Kistler (@mikekistler) example of case, scope in ARM is a url, like
/subscription/123-456-789/resourceGroup/rgnameand when you set a policy you do something like POST/subscription/123-456-789/resourceGroup/rgname/policy. The template will be defined as{scope}/policy. with scope tagged to NOT be encoded.Example:
https://github.com/Azure/azure-rest-api-specs/blob/2614c5038cb384e864c1608e76be61a5ee84cb02/specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/policyAssignments.json#L37
timotheeguerin commentedon Aug 17, 2022
So wondering if the only case is really that we don't want to escape
/but wouldn't we maybe still want to escape in between.For example if the scope was
/subscription/123-456/rg with spaces/bar(just supposing that was allowed)Wondering if maybe what we want is a way to say that a path parameter is actually multiple segment:
mikekistler commentedon Aug 18, 2022
Laurent Mazuel (@lmazuel) My point is that if we know something is a URL then we never want to encode it. It would be wrong to encode it. So there is no need to specify "skip-url-encoding" on URLs.
8 remaining items
timotheeguerin commentedon Sep 13, 2022
Proposal
Path parameters are always url encoded except:
uriand is used in@servervalue.uriin an operation it gets encoded/)/How to mark a path parameter as having multiple segments(multiple
/)Option 1: Have a convention in the
@routepathPros:
Cons:
Option 2 Add a flag on
@pathdecoratorPros:
/Cons:
mikekistler commentedon Sep 13, 2022
Path parameters that may contain unencoded "/" are strongly discouraged as they make the REST API definition ambiguous. If we support this then we also need a linter message that flags these.
markcowl commentedon Sep 14, 2022
Notes
markcowl commentedon Sep 14, 2022
Mike Kistler (@mikekistler) Yes, in OpenAPI path segments must not contain unencoded path separators.
However, in Azure APIs, there is a common pattern, originating in ARM but also used in data planes of entities that 'extend' other entities. This results in paths of variable length for the same operation, like:
/{extended-entity-identifier}/{extending-entity-type}/{extending-entity-name}Since
{extended-entity-identifier}is unknown, could contain any number of segments, and does not actually change the operations over the extending resource, it makes sense to describe these as operations under a single path, rather than enumerating all of the possible paths and repeating the operations.Personally I am favoring something like a
UriPathtype. This would allow clients to decide whether to accept an 'already encoded' path variable, or to accept an array of path segments or the like. Languages with Uri types might decide to use those Uri types. This also means we can maintain the current mechanisms we use to represent these operations in OpenAPI.We should propose how to represent them in OpenAPI3 as well.markcowl commentedon Oct 20, 2022
Revised Proposal
@pathdecorator that marks a path as multi-segmentRepresentation in cadl-autorest
While it is technically invalid, this pattern is common in autorest-inflected swagger. A urlPath parameter should be marked with the 'x-ms-skip-url-encoding' extension:
Representation in OpenAPI3
Scenario Coverage
op simple(@path foo: string)op simple(@path foo: uri)/op simple(@path({multi: true}) foo: string)/op simple(@path foos: string[])/. Note that@autoRoutewould have to be expanded to allow thisAlternative implementation - explicitly skip URL encoding
skipUrlEncodingproperty to@pathand@querydecoratorsAlternative implementation - Only use array types to indicate multiple segments
markcowl commentedon Oct 20, 2022
Notes from Design Meeting
markcowl commentedon Nov 2, 2022
Revised Proposal
Relative and absolute paths
The proposal is to use a single type to represent the common absolute and relative paths, as this provides all necessary information about encoding.
An alternate idea is to provide individual types for relative and absolute paths, but this would largely be for documentary purposes, as we would expect any processor to correctly handle leading and trailing slashes.
Emitters would represent relative and absolute url paths, consistent with the relative-reference concept, producing the following default behavior
op simple(@path foo: string)op simple(@path foo: urlPath)op simple(@path foo: uri)op simple(@query foo: string)op simple(@query foo: urlPath)op simple(@query foo: uri)op simple(@path foos: string[])/.Note that here, we are discounting use of the 'network-path' option for relative-path (paths starting with
//), as the spec indicates that this is a disused pattern, and we have never seen it. However, we could add a networkPath type in the future, if needed.markcowl commentedon Nov 3, 2022
proposal:
verify no discrepancies with the new spec: https://url.spec.whatwg.org/#relative-url-string