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

Errors when message & oneof share field names #835

Open
wsp-repo opened this issue May 18, 2023 · 3 comments
Open

Errors when message & oneof share field names #835

wsp-repo opened this issue May 18, 2023 · 3 comments

Comments

@wsp-repo
Copy link

wsp-repo commented May 18, 2023

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; // !!!!!

@stephenh stephenh changed the title The integrity of the toJSON and FromJSON methods has been violated Errors when message & oneof share field names May 21, 2023
@stephenh
Copy link
Owner

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!

@wsp-repo
Copy link
Author

Push > ERROR: Permission to stephenh/ts-proto.git denied to wsp-repo

@stephenh
Copy link
Owner

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.

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

No branches or pull requests

2 participants