autorest icon indicating copy to clipboard operation
autorest copied to clipboard

[bug] child classes are not recognized if discriminator type is defined in parent of base class

Open archerzz opened this issue 2 years ago • 2 comments

Before filling a bug

  • [x] have you checked the faq for known issues.
  • [x] have you checked existing issues

Describe the bug

Some services will adopt the following pattern of defining discriminator:

  • Base type has a discriminator property
  • However, the discriminator property is defined in the parent class of the base type
  • An example is SecurityCenter which has a ExternalSecuritySolution type. ExternalSecuritySolution has a kind property as discriminator, but kind is actually defined in one of its parent class ExternalSecuritySolutionKind.

In such cases, autorest could not correctly deduce the child classes. I've written a test case Discriminator.zip. In it:

  • Discriminator.json provides a base type with inline discriminator property
  • Discriminator2.json provides a base type of which the discriminator property is defined in its parent class

Expected behavior

Autorest should deduce the child classes when discriminator property is defined in the parent class of the base type. Or it should report error if such pattern is not supported.

Additional context Add any other context about the problem here.

archerzz avatar Nov 08 '22 07:11 archerzz

Another example is LocalSearch. It contains a type definition Action which has a very deep inheritance path from ResponseBase which contains the discriminator property.

archerzz avatar Nov 08 '22 08:11 archerzz

I can repro this with the latest Go code generator for ExternalSecuritySolution

jhendrixMSFT avatar Sep 06 '23 15:09 jhendrixMSFT