-
Notifications
You must be signed in to change notification settings - Fork 243
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
bug: Unable to set default on scalar definition #1646
Comments
@markcowl what is the design discussion needed here? Can we schedule this? |
There is a related issue now (#2359, for general declarations not just scalars). Sorry for the delay and I agree this issue has been around for a quite a while and is something we should support, I'll try to get something on the design agenda for next week (and will scope the issue to just scalars in case model defaults is a bridge too far for folks). /cc @markcowl |
@bterlson great news! This issue is the only thing preventing me from converting all OpenAPI definitions to TypeSpec at a customer engagement. Can't wait 😊👌🏼 |
@tmeckel we managed to discussed this briefly today, but did not come to any conclusion for scalar defaults yet. However, it was noted that the code above, which previously threw an error, does not throw! In particular, this should work fine today:
Perhaps this is a viable workaround. It does mean any usages of
Lastly, it would be helpful to understand the underlying motivation behind the need for scalar defaults - is it about not repeating the default everywhere it is used, matching an existing OpenAPI document, etc. |
@bterlson Many thanks for the detailed answer! I'll give both workarounds a shot. See which might work best for me. About the reasons you asked:
|
closing in favor of #2359 |
The following screenshot shows a valid OpenAPI YAML definition for a component which derives from a string and has a default value assigned. The default value is inherited when, the component definition is (re-)used as reference inside another component (model) definition:
With CADL 0.4.0 the following code creates a compile time error:
It is possible though to define/assign a default value to the
id
field ofmodel Item
when the fieldid
is marked optional. But this is definitely not the same behavior as with the initially mentioned OpenAPI definition.The text was updated successfully, but these errors were encountered: