-
Notifications
You must be signed in to change notification settings - Fork 74
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
Nested Polymorphism and Discriminators #458
Comments
@onalant - Thanks for filing the issue and the detailed explanation. We started using the While we can use the immediate parent instead of the uber parent in the key of Let me know if the issue persists. |
We seem to be unblocked thanks to the changes introduced by #457. Thank you for the quick response and the fix! If the PR is going to be merged soon, is this issue still necessary for you folks? |
We will merge the PR soon and publish a new version of the generator. This issue will be closed automatically by github once #457 is merged. We will also send a PR with the new code changes for Are there any other packages that you are using and see the same issue? |
I have not used these directly, but I found the following packages (in addition to
The commonality---with the exception of
in their |
new versions of arm-kusto and and arm-timeseriesinsights have been published. |
2019-07-26T16:48:30Z: trying cherry-pick of be5280d from #457
2019-07-26T17:16:35Z: this is resolved by #457
IN SHORT:
while
loop here causes issues with nested polymorphism and discriminators.Some Azure SDKs rely on discriminators to resolve serialization mappers at call-time. The mappers both validate and transform the input payload such that they are of the structure expected by the API. We discovered that in some instances the discriminator labels are not emitted correctly. We provide the example that first exposed this issue, the npm package
@azure/arm-timeseriesinsights
.The mapper definitions in
lib/models/mappers.ts
appear as expected. However, in the last section specifying the discriminators, we see the following:We would like to draw attention to the lines of the form
.+(Environment|EventSource)CreateOrUpdateParameters
. If, for example, we callclient.environments.createOrUpdate(...)
with the following parameters:we would naturally expect the environment to provision. However, we are instead met with an error message:
Briefly, this is because the mapper was not found. In
ms-rest-js/lib/serializer.ts
, we notice the functiongetPolymorphicMapper
. In particular, atgetPolymorphicMapper+8,+11
we see the linesAt runtime,
typeName
will resolve toEnvironmentCreateOrUpdateParameters
; but this does not matchCreateOrUpdateTrackedResourceProperties
as implied by thediscriminators
export above! Then,polymorphicMapper
will beundefined
, so that the originalmapper
object passed togetPolymorphicMapper
will be returned. Of course, since this would be the mapper for the base classEnvironmentCreateOrUpdateParameters
, theproperties
fields necessary for theStandard
andLongTerm
variants will be dropped.The root of this issue seems to lie at
src/vanilla/Model/CodeModelTS.cs#320
. While (no pun intended) we would expect the polymorphic type to ``step up'' one level, it instead goes to the very base. That is, if we haverather than using
B
as the polymorphic base ofC
,autorest.typescript
will useA
, thus generating the discriminator lineA.C
.When we remove the
while
loop and instead step only one level, the above issues disappear. That being said, we do understand that stepping to the ``base-most'' class of an inheritance hierarchy may sometimes be the more correct behavior. Our question then is: what are the issues of only stepping one level in the inheritance hierarchy?Attached is a patch file with the changes we made to our local
autorest.typescript
. If so desired, we can also provide a minimal project replicating the error described above.step.patch.txt
The text was updated successfully, but these errors were encountered: