Remove pass discriminator to children setting#2563
Conversation
|
This is a wide API change? It adds a getter to all of these models. There would be hundreds of them in mgmt. Also there appear to be a bug with this, when serialize it to JSON #2411 |
|
And I do not see why "pass to children" is the default. If user does not use this getter, it does not need to be there. So far, no mgmt user asks for it. |
|
That's good feedback @weidongxu-microsoft. My thinking is this feature is very confusing and not well used. It'd be better for serialization to always have the discriminator property in the model so it isn't lost, which could happen when we're deserializing an unknown polymorphic type. And I agree, adding a getter everywhere won't be great but this may be nice to just have so our models aren't as mysterious. But if it's going to add a lot of noise, I think we can still remove the current setting and add a much clearer setting |
There was a problem hiding this comment.
Yeah, maybe its fine. Please get a sign off from Srikanta as well, because it affect API shape of all polymorphic classes (I see it already applied to stream serialization, hence there is few changes in test module now -- the remaining Jackson ones).

I see now the getter is added to the base class, not the terminal class. Again, no major objection.
The current CI error may relate to the issue I've linked.
Mgmt would generate model test cases like this
https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/security/azure-resourcemanager-security/src/test/java/com/azure/resourcemanager/security/generated/ContainerRegistryVulnerabilityPropertiesTests.java
And it seems the test of the serialization fails with the Jackson form of this.
|
Given what's merged to main branch, we now having another issue (that we need to solve before next typespec-java release) But code only return a It should return a I would go figure it out way sometime later as this is typespec. And the cause likely in typescript part. It may apply to Swagger as well, since the kind there could also be an enum. |
It looks like this does get handled as expected, returning a |
There was a problem hiding this comment.
I think it's okay to remove this option and always have the getter for the discriminator property added to the base type of polymorphic models. Having this getter is quite useful for troubleshooting and in general represents the service response more accurately. .NET always makes the discriminator visible. So, this will add parity in Java.
While this may cause a lot of classes in mgmt plane to be updated with a getter, it's not a breaking change and is a read-only method.
It is due to change in codegen #2571 which I did last Friday. It won't break SDK or customer. The I just find that the enabling of stream serialization also enable this "getter", so I had to make the type correct (without the getter, type does not matter). |
|
also some error in test code gen I will have Xiaofei take a look. #2574 |
|
I've check the Swagger case, it would also generate the So we are good on parity of TypeSpec and Swagger (mgmt needs this) @XiaofeiCao see #2599 |
Removes the
pass-discriminator-to-child-deserializationsetting as the discriminator is now always passed to children models.