Per azure/typespec-azure-pr#728 We have a mechanism for providing service-side defaults, but need a mechanism that allows simplifying the client-side SDK by providing a suggested default value for required properties. This allows client SDKs to simplify an API, or prevent an SDK breaking change when there is a REST API breaking change making a formerly optional property required.
One proposal is to use a decorator @suggestedValue in cadl core that provides the value hint:
model SomeModel {
@suggestedValue("Value that client SDKs may supply by default if they make this property optional") requiredThing: string;
}
model FirewallRule
{
action: string;
port: string;
ipRange?: string;
}
model DefaultRule extends FirewallRule {
action: "Deny";
port: "*"
}
model AllowHttps extends FirewallRule {
action: "Allow";
port: 443;
}
model MyHttpsConnectedWidget {
@suggestedValue([DefaultRule, AllowHttps])
firewallRule: FirewallRule[];
...
}
As this applies to model properties, it would analogously apply to parameters
Questions / Considerations
checking will be a bit tricky - ideally, the decorator would enforce that the provided type is assignable to the decorated property type and that it consists entirely of defined literals (StringLiteral instead of string, for example)
Are we missing any scenarios using a decorator
If a decorator, what library does this decorator belong in?
Copied from https://github.com/Azure/typespec-azure-pr/issues/800
Per azure/typespec-azure-pr#728 We have a mechanism for providing service-side defaults, but need a mechanism that allows simplifying the client-side SDK by providing a suggested default value for required properties. This allows client SDKs to simplify an API, or prevent an SDK breaking change when there is a REST API breaking change making a formerly optional property required.
One proposal is to use a decorator
@suggestedValue
in cadl core that provides the value hint:Usages
Simple scalars
Suggested client SKU
Default object or collection
As this applies to model properties, it would analogously apply to parameters
Questions / Considerations