Azure / typespec-azure

About TypeSpec Azure Libraries
https://azure.github.io/typespec-azure/
MIT License
11 stars 37 forks source link

Support explode in Query #1321

Open lmazuel opened 1 month ago

lmazuel commented 1 month ago

Support of:

@route("/c1/here") op c1(@query(#{ explode: true }) foo: string[]): void;

to mean that the url should explode the query parameter, for instance here foo=a&foo=b if we pass ["a","b"] at the SDK level.

### TypeSpec
- [ ] https://github.com/microsoft/typespec/issues/3736
### Spec
- [ ] https://github.com/Azure/cadl-ranch/issues/666
- [ ] https://github.com/Azure/typespec-azure/issues/1319
### Implementation
- [ ] https://github.com/Azure/typespec-azure/issues/1320
- [ ] https://github.com/Azure/autorest.python/issues/2755
- [ ] https://github.com/Azure/autorest.java/issues/2897
- [ ] https://github.com/Azure/autorest.typescript/issues/2735
- [ ] https://github.com/Azure/autorest.csharp/issues/4967
- [ ] https://github.com/Azure/autorest.go/issues/1423
- [ ] https://github.com/Azure/autorest.cpp/issues/374
- [ ] https://github.com/Azure/autorest.rust/issues/83
tadelesh commented 1 month ago

also this feature could cover the following uri template case:

@route("/action{?name*}") op action(name: string[]): void;
MaryGao commented 1 month ago

@lmazuel I want to clarify the scopes for this feature. According to uri temlate design, I think we mainly have below cases.

Are they all in scope of this issue?

image

Also there are some legacy cases which are moved from format to encode, we have some cadl-ranch cases to cover array's serliazation, but for object I guest it is not ready yet(at least for JS).

Are all workable cases in scope or only cases of cadl-ranch having in scope?

image

lmazuel commented 1 month ago

"explode" just means this:

This is orthogonale to how you serialize an array, an object, or a primitive. You should already have those scenarios covered, independently of "explode"

As of today, TypeSpec implies CSV (comma separated), it's not in scope to discuss pipe or space. DeepObject is not in scope either.

Optionality or required has nothing to do with the feature (the query parameter can be optional or required, it doesn't impact the value). Explode is about the value, not the optionality or not of the query key.

lmazuel commented 3 weeks ago

Additional note about after a comment I saw on the cadl-ranch PR, if "explode" is used on a non-array parameter, it's just ignored. The way url template RFC is written, given people could use a union like string | string[] and therefore there are scenario when it may be possible that a primitive type is associated with "explode". This is ok, just the explode should be ignored (not a failure)