-
Notifications
You must be signed in to change notification settings - Fork 176
feat(cadl): support literal type model property #3036
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
feat(cadl): support literal type model property #3036
Conversation
- change json coverter for `InputModelProperty` to set the `DefaultValue` property if the property type is a literal type - update `ObjectTypeProperty` so that `DefaultValue` is set if it's from literal type - change `ModelTypeProviderFields`: - exclude literal properties from constructor parameter list - literal properties are `internal readonly` - change `ModelTypeProvider`, update the criteria on properties to be serialized, now literal type property will be serialized regardless it's read-only - fix a issue in emitter that boolean literal type is not identified - minor refactoring - update test projects resolve Azure#3035
ArcturusZhang
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a InputConstant in our input types, which is really similar to the literal type.
Do we need to use two things to represent a very similar case?
Currently the InputConstant class is only used in InputParamters, but I believe this literal type has very few differences from the LiteralType.
This is what InputConstant and InputLiteralType looks like:
internal record InputConstant(object? Value, InputType Type);
internal record InputLiteralType(string Name, InputType LiteralValueType, object Value, bool IsNullable = false)The Name in literal is constant Literal, and IsNullable makes no sense on literal types (you can only assign one value for it, how could it be null? if it could be null, it only longer only accepts one value).
Therefore I suggest we combine the InputConstant and InputLiteralType and things would align with how we deal with the same thing about ConstantSchema back using swaggers
- add simple value type check for `number` literal value in emitter, we only support int32 and float64 - change converter to support float64 which will be mapped to double in csharp - drop converter support for int64 since it's not emitted in the emitter - update test cases - minor refactoring
- modify cadl definition to add test case for literal model property - add a customization constructor of `CadlFirstTestClient` for test purpose - add mock api
- add a property `ShouldSkipDeserialization` in `PropertySerliaization` - update writer to skip generating deserialization codes for literal type properties
|
A couple of changes since last review:
|
src/AutoRest.CSharp/Common/Output/Models/Types/ObjectTypeProperty.cs
Outdated
Show resolved
Hide resolved
# Conflicts: # test/TestProjects/FirstTest-Cadl/Generated/Docs/CadlFirstTestClient.xml # test/TestProjects/FirstTest-Cadl/Generated/Models/Thing.cs # test/TestProjects/FirstTest-Cadl/Generated/cadl.json
# Conflicts: # test/TestProjects/FirstTest-Cadl/FirstTest-Cadl.cadl # test/TestProjects/FirstTest-Cadl/Generated/Docs/CadlFirstTestClient.xml # test/TestProjects/FirstTest-Cadl/Generated/Models/Thing.Serialization.cs # test/TestProjects/FirstTest-Cadl/Generated/Models/Thing.cs # test/TestProjects/FirstTest-Cadl/Generated/cadl.json
|
@m-nash I've committed change to treat literal type operation parameters as constant parameters (see the last 2nd commit). However, I think it's still better to handle that in the emitter, because:
|
# Conflicts: # test/TestProjects/FirstTest-Cadl/Generated/cadl.json
# Conflicts: # test/TestProjects/FirstTest-Cadl/Generated/Models/Thing.Serialization.cs
InputModelPropertyto set theDefaultValueproperty if the property type is a literal typeObjectTypePropertyso thatDefaultValueis set if it's from literal typeModelTypeProviderFields:internal readonlyModelTypeProvider, update the criteria on properties to be serialized, now literal type property will be serialized regardless it's read-onlyresolve #3035
Description
Add your description here!
Checklist
To ensure a quick review and merge, please ensure:
Ready to Land?