Errors when message & oneof share field names
If the name of the properties inside the oneof and one level above matches, the result of the work of the methods becomes erroneous and irreversible
PROTO
message ExampleType {
optional string propName1 = 1;
optional oneof propName2 {
string propName0 = 2;
string propName1 = 3;
string propName3 = 4;
}
optional string propName3 = 5;
}
TS
Error1
const value: ExampleType = {
propName1: "string1"
propName2: {
$case: "propName1",
propName1: "string2"
}
propName3: "string3"
}
ExampleType.toJSON(value);
{
propName1: "string2", // incorrect
propName3: "string3"
}
Error2
const value: ExampleType = {
propName1: "string1"
propName2: "string2",
propName3: "string3"
}
ExampleType.fromJSON(value);
{
propName1: "string1",
propName2: { // incorrect
$case: "propName1",
propName1: "string1",
}
propName3: "string3"
}
Error3
const value: ExampleType = {
propName3: "string3"
}
ExampleType.fromJSON(value);
{
propName2: { // incorrect
$case: "propName3",
propName1: "string3",
}
propName3: "string3"
}
Consequence
const value1 = { ..... };
const value2 = ExampleType.fromJSON(ExampleType.toJSON(value1));
value1 !== value2; // !!!!!
Ah yeah, that looks interesting. I'm not surprised this doesn't work/overlaps.
Honestly I'm not sure/don't remember what the canonical proto3 JSON encoding of your schema would be.
Do you know?
If you figure it out, a pull request would be great. :-) Thanks!
Push > ERROR: Permission to stephenh/ts-proto.git denied to wsp-repo
Ah yeah, @wsp-repo I think you can make a fork of stephenh/ts-proto with github, and push to your fork, then make a pull request from there.