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

using --ts_proto_opt=useJsonName=true breaks generated code for google/protobuf/struct.proto #1125

Open
srliao opened this issue Oct 21, 2024 · 1 comment

Comments

@srliao
Copy link

srliao commented Oct 21, 2024

We rely on --ts_proto_opt=useJsonName=true option so that the generated typing for our types has the correct casing. However, using this option causes the generated code for google/protobuf/struct.proto to be incorrect like so:

  wrap(value: any): Value {
    const result = createBaseValue();
    if (value === null) {
      result.null_value = NullValue.NULL_VALUE;
    } else if (typeof value === "boolean") {
      result.bool_value = value;
    } else if (typeof value === "number") {
      result.number_value = value;
    } else if (typeof value === "string") {
      result.string_value = value;
    } else if (globalThis.Array.isArray(value)) {
      result.list_value = value;
    } else if (typeof value === "object") {
      result.struct_value = value;
    } else if (typeof value !== "undefined") {
      throw new globalThis.Error("Unsupported any value type: " + typeof value);
    }
    return result;
  },

But the actual fields are named nullValue, boolValue etc... as can be seen as follows:

function createBaseValue(): Value {
  return {
    nullValue: undefined,
    numberValue: undefined,
    stringValue: undefined,
    boolValue: undefined,
    structValue: undefined,
    listValue: undefined,
  };
}

Disabling --ts_proto_opt=useJsonName=true will result in all the field being named snake case for the generated google/protobuf/struct.proto code and the issues goes away but we are left with incorrect casing for our own definitions.

@stephenh
Copy link
Owner

Hi @srliao ; it looks like this code:

result.${fieldNames.nullValue} = NullValue.NULL_VALUE;

Is not respecting the useJsonName flag--if you could submit a PR that fixes that, and ideally add a Struct usage to one of our integration/* tests that sets useJsonName=true, that would be great! Thank you!

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