-
Notifications
You must be signed in to change notification settings - Fork 230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
URI templates support #3736
Comments
From the original design we had here we seemed to have decided the following but it might be good to verify this is the way to go as it was only partially implemented (
But with the following changes
|
Feels like the same than Azure/typespec-azure#1022 |
yeah that seems to be an additional use for it |
Summarizing the previous proposal with the new names and what we already have for clarity Add 2 new types:
|
Concern back from this original proposal that we a mixing the type with the encoding here. There is also the issue that union of encoded and non encoded type are ambigious
do we encode or not above? |
Uri Templates in TypeSpecProposal is to use Uri Templates spec to define encoding, optional parameters, and validation of the input and output of the API. Reserved expensions SpecSkipping encoding of certain characters can be done by using @route("{+path}/here") op a(@path path: string): void; // path: /foo/bar -> route: /foo/bar/here Equivalent to passing Multiple segmentsMultiple segments can be specified with the @route("blobs{path*}") op a(@path path: string[]): void; // /blobs/foo,bar
@route("blobs{/path*}") op a(@path path: string[]): void; // /blobs/foo/bar When using The equivalent option would be passing Other expansions:The uri template allows you to specify other ways to expand path and query parameters. Part of this proposal is we support uri template fully. So it means we need equivalent config in TypeSpec. Path expansion
Query expansion
Change to the Http library APICurrently each operation as a Example you should be able to do the following given uriTemplateExpander(route.uritemplate, {
...pathParametersValues,
...queryParametersValues,
}); Examples
|
I wonder if the above design can also resolve this issue #2476 ? though the last column is empty as shown in the table. |
@markcowl discuss in DPG meeting 7/18 |
Loop @archerzz to verify if System.Net.Url can handle this. |
There is an old |
For Go, the build in modules does not support URI template proposed in this issue and Go also has quite a high bar to use a 3rd-party module. cc: @ArthurMa1978 it may take some time for Go to fully support this. |
For some info I implemented a uri parser here and looking at other libraries in JS it is quite simple to implement yourself with regex. If we were to define a good test suite I don't think this is something that would be hard to have every generator be able to do themself. |
fix #3736 --------- Co-authored-by: Christopher Radek <[email protected]>
Uri Templates in TypeSpec
Uri Template Spec
Proposal is to use Uri Templates spec to define encoding, optional parameters, and validation of the input and output of the API.
TypeSpec of course does have its own way of defining part of those (optionality, if a param is a path or query param, etc.) so goal is to unify those.
Reserved expensions Spec
Skipping encoding of certain characters can be done by using
+
in the param interpolationEquivalent to passing
allowReserved: true
to@path
or@query
Multiple segments
Multiple segments can be specified with the
*
suffix. By default it should be joined with a comma but a different prefix can be used to specify the separatorWhen using
*
we should error if the param type is not an array.The equivalent option would be passing
expode: true
(same name as openapi3) to@path
or@query
Other expansions:
The uri template allows you to specify other ways to expand path and query parameters. Part of this proposal is we support uri template fully. So it means we need equivalent config in TypeSpec.
Path expansion
/users/{id}
/users/5
/users/3,4,5
/users/role,admin,firstName,Alex
/users/{id*}
/users/5
/users/3,4,5
/users/role=admin,firstName=Alex
/users/{.id}
/users/.5
/users/.3,4,5
/users/.role,admin,firstName,Alex
/users/{.id*}
/users/.5
/users/.3.4.5
/users/.role=admin.firstName=Alex
/users/{;id}
/users/;id=5
/users/;id=3,4,5
/users/;id=role,admin,firstName,Alex
/users/{;id*}
/users/;id=5
/users/;id=3;id=4;id=5
/users/;role=admin;firstName=Alex
Query expansion
/users{?id}
/users?id=5
/users?id=3,4,5
/users?id=role,admin,firstName,Alex
/users{?id*}
/users?id=5
/users?id=3&id=4&id=5
/users?role=admin&firstName=Alex
Change to the Http library API
Currently each operation as a
path: string
property which reference the path. This will remain as it is but a newuriTemplate: string
that represent the exact template uri that should be able to be used to generate the uri given all teh path and query parameters.Example you should be able to do the following given
uriTemplateExpander
is a spec compliant function that takes a uri template and a map of values and returns the uriExamples
@route("blobs/{path*}") op a(@path path: string[]): void;
/blobs/foo,bar
@route("blobs{/path*}") op a(@path path: string[]): void;
/blobs/foo/bar
@route("blobs{/path*}") op a(@path path: string): void;
/blobs/foo
Things that uri Template don't cover
In the case of
explode: false
when dealing with arrays or object, openapi2 and openapi3 had some additional styles to serialize those:pipeDelimited
for arrays?foo=bar|baz
spaceDelimited
for arrays?foo=bar baz
In the case of
explode: true
for query parameters there is alsodeepObject
which is/users?id[role]=admin&id[firstName]=Alex
OpenAPI2 also had things that were removed in openapi3:
tsv
tab separated formatProposal on that
format:
on@query
and@header
@encode
*
explode: true
+
allowReserved: true
;
style: "matrix"
/
style: "path"
.
style: "label"
The text was updated successfully, but these errors were encountered: