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
The source of request parameters could be from operation, from (shared) model (explicit or implicit body property), from (shared) template, from (shared) trait. This is one of the difficulties, that dev is likely not able to write an operation with a single model that contains all request parameters and body properties, as they uses Azure.Core template and trait.
A typical situation in SDK is that the parameters of the API is too long/complex, and SDK would like to group them into an options parameter pattern, e.g.
One major difficulty is to have the mapping of the properties in (if we define this options parameter model in client.tsp)
modelActionOptions{
name: Resource.name;
prop1: RequiredClientOptions.prop1;
prop2?: OptionalClientOptions.prop2;
prop3: string;// not able to ref
queryParam?: OptionalClientOptions.queryParam;
headerParam?: OptionalClientOptions.headerParam;
headerParam2?: string;// not able to ref}
to the parameters of the operation
opaction is ResourceOperations.ResourceAction<Resource,{@headerheaderParam2?: string, ...RequiredClientOptions, ...OptionalClientOptions},Response,RequestPropertiessTrait>;
Candidate design: provide a model name for "options parameter"
Provide a decorator that only provide the name for "options parameter".
Emitter would put all the path/header/query/property of the API into this options parameter.
This solution could avoid the difficulty of mapping the properties.
For a POST action already have a model as request body, we can ask dev to use an alias/spread to avoid the model be visible in SDK.
This may also solve the problem that Python want the alias/spread (i.e., all parameters and body properties on method signature), and other language want the options parameter -- via the scope of @optionsParameter.
This design is not able to support API with finer structure like public Response action(String name, ActionOptions actionOptions).
This is a most flexible representation in client.tsp. However, it would involve the complexity of mapping the properties. It is hard to figure out that ActionOptions.prop3 is from trait RequestPropertiessTrait.reuqest.properties.prop3.
And it could be hard to maintain, if service evolve the API and add more (optional) parameters/properties.
Check that this issue is about the Azure libraries for typespec. For feature request in the typespec language or core libraries file it in the TypeSpec repo
Clear and concise description of the problem
Requirement
route can be
The source of request parameters could be from operation, from (shared) model (explicit or implicit body property), from (shared) template, from (shared) trait. This is one of the difficulties, that dev is likely not able to write an operation with a single model that contains all request parameters and body properties, as they uses Azure.Core template and trait.
A typical situation in SDK is that the parameters of the API is too long/complex, and SDK would like to group them into an options parameter pattern, e.g.
(some properties in
ActionOptions
is required)A slightly different API could be
Alternatives on Design
One major difficulty is to have the mapping of the properties in (if we define this options parameter model in client.tsp)
to the parameters of the operation
Candidate design: provide a model name for "options parameter"
Provide a decorator that only provide the name for "options parameter".
Emitter would put all the path/header/query/property of the API into this options parameter.
This solution could avoid the difficulty of mapping the properties.
For a POST action already have a model as request body, we can ask dev to use an alias/spread to avoid the model be visible in SDK.
This may also solve the problem that Python want the alias/spread (i.e., all parameters and body properties on method signature), and other language want the options parameter -- via the scope of
@optionsParameter
.This design is not able to support API with finer structure like
public Response action(String name, ActionOptions actionOptions)
.Candidate design: TOM pattern
This is a most flexible representation in client.tsp. However, it would involve the complexity of mapping the properties. It is hard to figure out that
ActionOptions.prop3
is from traitRequestPropertiessTrait.reuqest.properties.prop3
.And it could be hard to maintain, if service evolve the API and add more (optional) parameters/properties.
Welcome suggestions on better design
Checklist
The text was updated successfully, but these errors were encountered: