-
Notifications
You must be signed in to change notification settings - Fork 160
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
base: feature/v3
Are you sure you want to change the base?
NestedDiscriminator Test #4470
Conversation
This reverts commit fbea6d6.
/// <param name="age"></param> | ||
public Shark(int age) : base(age) | ||
{ | ||
Sharktype = "shark"; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public partial class Shark : Fish | |
public abstract partial class Shark : Fish |
var value = new GoblinShark(1) | ||
{ | ||
Kind = "shark", | ||
}; |
There was a problem hiding this comment.
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
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" }, |
There was a problem hiding this comment.
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:
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" }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Partner = new Salmon(3) { Kind = "salmon" }, | |
Partner = new Salmon(3), |
Hate = | ||
{ | ||
["key1"] = new Salmon(4), | ||
["key2"] = new GoblinShark(2) { Kind = "shark" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
["key2"] = new GoblinShark(2) { Kind = "shark" } | |
["key2"] = new GoblinShark(2) |
["key2"] = new GoblinShark(2) { Kind = "shark" } | ||
} | ||
}, | ||
new GoblinShark(3) { Kind = "shark" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new GoblinShark(3) { Kind = "shark" } | |
new GoblinShark(3) |
["key3"] = new SawShark(3) | ||
{ | ||
Kind = "shark", | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
["key3"] = new SawShark(3) | |
{ | |
Kind = "shark", | |
}, | |
["key3"] = new SawShark(3), |
["key4"] = new Salmon(2) | ||
{ | ||
Kind = "salmon", | ||
Friends = | ||
{ | ||
new Salmon(1) { Kind = "salmon" }, | ||
new GoblinShark(4) { Kind = "shark" } | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
["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) | |
} | |
} |
Description
Add your description here!
Checklist
To ensure a quick review and merge, please ensure:
Ready to Land?