Fixes for JSON merge patch in polymorphic types#2775
Fixes for JSON merge patch in polymorphic types#2775alzimmermsft merged 8 commits intoAzure:mainfrom
Conversation
typespec-tests/src/main/java/com/cadl/armresourceprovider/models/UserAssignedIdentities.java
Outdated
Show resolved
Hide resolved
typespec-tests/src/main/java/com/cadl/flatten/implementation/JsonMergePatchHelper.java
Show resolved
Hide resolved
There was a problem hiding this comment.
@haolingdong-msft
You are the owner of patch feature. We will need you to sign off.
| continue; | ||
| } | ||
|
|
||
| if (model.isPolymorphic() && CoreUtils.isNullOrEmpty(model.getDerivedModels())) { |
There was a problem hiding this comment.
Just a notice: criteria like "CoreUtils.isNullOrEmpty(model.getDerivedModels()) => polymorphic parent" that works for single-level polymorphic won't work for multi-level discriminator -- not a blocker as existing code likely already having similar problems
Also, in Swagger there could be (still single discriminator)
classDiagram
base <|-- level1Terminal
base <|-- level1NonTerminal
level1NonTerminal <|-- level2Terminal
class base {
+kind/discriminator
}
class level1NonTerminal {
+property1
}
class level1Terminal {
kind=terminal1
}
class level2Terminal {
kind=terminal2
}
Does level1NonTerminal.property1 need to have accessor?
There was a problem hiding this comment.
This should work in this scenario and the intermediate polymorphic parent will need accessors for all its new properties so that level2Terminal can set those values during deserialization.
I'll update patch.tsp to add this scenario so it can be validated.
There was a problem hiding this comment.
Yeah, I think current logic is good.
There was a problem hiding this comment.
What's the difference of this line and model.isPolymorphic() && !model.isPolymorphicParent()?
There was a problem hiding this comment.
Hmm, doesn't seem like too much now that I look at it again. I got caught up on model.isPolymorphicParent() checking both model.isPolymorphic() && !CoreUtils.isNullOrEmpty(model.getDerivedModels()), so it ends up being the same in this case. I likely overlooked this as my first design used !model.isPolymorphicParent() by itself, which would have been wrong here as non-polymorphic models would have passed the check.
javagen/src/main/java/com/azure/autorest/implementation/ClientModelPropertiesManager.java
Show resolved
Hide resolved
|
The getLength() change to fire serialization and removing extra code in the accessor look good to me. |
Fixes #2769
Fixes #2770
Fixes #2771
Some fixes when handling stream-style, polymorphic, JSON merge patch models.
BinaryDatais created to just useBinaryData.fromObject. To make sure serialization happens before JSON merge patch serialization is disabledBinaryData.getLength()is called instead of the previousBinaryData.fromBytes(BinaryData.fromObject(object).toBytes())pattern, this will retain information inBinaryDatathat it is based on an object.