Skip to content
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

NestedDiscriminator Test #4470

Draft
wants to merge 10 commits into
base: feature/v3
Choose a base branch
from
Draft

Conversation

mcgallan
Copy link
Member

Description

Add your description here!

Checklist

To ensure a quick review and merge, please ensure:

  • The PR has a understandable title and description explaining the why and what.
  • The PR is opened in draft if not ready for review yet.
    • If opened in draft, please allocate sufficient time (24 hours) after moving out of draft for review
  • The branch is recent enough to not have merge conflicts upon creation.

Ready to Land?

  • Build is completely green
    • Submissions with test failures require tracking issue and approval of a CODEOWNER
  • At least one +1 review by a CODEOWNER
  • All -1 reviews are confirmed resolved by the reviewer
    • Override/Marking reviews stale must be discussed with CODEOWNERS first

/// <param name="age"></param>
public Shark(int age) : base(age)
{
Sharktype = "shark";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the reason why we said .Net generator is not fully support "nested discriminator". This class is not correctly generated.

According to the spec here, the Shark class should have a discriminator sharktype defined, and have a property kind with the value of shark, but the generated code is messing them up together. Also because Shark defines a new discriminator sharktype but does not provide a value for sharktype, and because discriminator properties are required in payload, this class should be abstract to ensure that it is never instantiated because it will never have a proper value for sharktype.

We need to fix this first before we introduce this test case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Sharktype = "shark";
Kind = "shark";

/// Please note <see cref="Shark"/> is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes.
/// The available derived classes include <see cref="GoblinShark"/> and <see cref="SawShark"/>.
/// </summary>
public partial class Shark : Fish
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public partial class Shark : Fish
public abstract partial class Shark : Fish

Comment on lines +24 to +27
var value = new GoblinShark(1)
{
Kind = "shark",
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well it is cheating that we assign the internal properties in a test case because users of our generated libraries could never assign them.
Since the current implemented code is not correct, therefore without assigning this property will never let the test pass.
But still I suggest we change the implementation of our test cases to the correct way and let the test fail and wait for the real fix on the generator.
Therefore it should be

Suggested change
var value = new GoblinShark(1)
{
Kind = "shark",
};
var value = new GoblinShark(1);

here, and the test now will fail, just let it fail. It should pass when the generator fixes its issue.

var value = new Salmon(1)
{
Kind = "salmon",
Partner = new Shark(2) { Kind = "shark", Sharktype = "saw" },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same thing happens here, we should not assign values to the two discriminators Kind and Sharktype.
Here we should have:

Suggested change
Partner = new Shark(2) { Kind = "shark", Sharktype = "saw" },
Partner = new SawShark(2),

because sawshark is a shark of fish therefore kind should be shark, and sharktype is saw.

{
new Salmon(2)
{
Partner = new Salmon(3) { Kind = "salmon" },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Partner = new Salmon(3) { Kind = "salmon" },
Partner = new Salmon(3),

Hate =
{
["key1"] = new Salmon(4),
["key2"] = new GoblinShark(2) { Kind = "shark" }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
["key2"] = new GoblinShark(2) { Kind = "shark" }
["key2"] = new GoblinShark(2)

["key2"] = new GoblinShark(2) { Kind = "shark" }
}
},
new GoblinShark(3) { Kind = "shark" }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
new GoblinShark(3) { Kind = "shark" }
new GoblinShark(3)

Comment on lines +87 to +90
["key3"] = new SawShark(3)
{
Kind = "shark",
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
["key3"] = new SawShark(3)
{
Kind = "shark",
},
["key3"] = new SawShark(3),

Comment on lines +91 to +99
["key4"] = new Salmon(2)
{
Kind = "salmon",
Friends =
{
new Salmon(1) { Kind = "salmon" },
new GoblinShark(4) { Kind = "shark" }
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
["key4"] = new Salmon(2)
{
Kind = "salmon",
Friends =
{
new Salmon(1) { Kind = "salmon" },
new GoblinShark(4) { Kind = "shark" }
}
}
["key4"] = new Salmon(2)
{
Friends =
{
new Salmon(1),
new GoblinShark(4)
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants