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

stringEnums removeEnumPrefix not working together #897

Closed
cs-clarence opened this issue Aug 5, 2023 · 2 comments
Closed

stringEnums removeEnumPrefix not working together #897

cs-clarence opened this issue Aug 5, 2023 · 2 comments

Comments

@cs-clarence
Copy link

cs-clarence commented Aug 5, 2023

The generated code when both stringEnums and removeEnumPrefix set to true sometimes conflicts.

For example, the generated code for the enum:

export enum Gender {
  UNSPECIFIED = "GENDER_UNSPECIFIED",
  MALE = "GENDER_MALE",
  FEMALE = "GENDER_FEMALE",
  OTHER = "GENDER_OTHER",
}

However, somewhere in the generated code, they reference GENDER_UNSPECIFIED key that doesn't exist, instead of unprefixed one.

function createBaseChangeGenderRequest(): ChangeGenderRequest {
  return { gender: Gender.GENDER_UNSPECIFIED, other_gender: undefined };
}

encode(message: ChangeGenderRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
  if (message.gender !== Gender.GENDER_UNSPECIFIED) {
    writer.uint32(8).int32(genderToNumber(message.gender));
  }
  if (message.other_gender !== undefined) {
    writer.uint32(18).string(message.other_gender);
  }
  return writer;
},
@stephenh
Copy link
Owner

Ah shoot. Fwiw the PR that introduced removeEnumPrefix was this one:

https://github.com/stephenh/ts-proto/pull/779/files

And that "not default" check is from around in here:

if (${notDefaultCheck(ctx, field, messageDesc.options, `message.${fieldName}`)}) {

So notDefaultCheck should probably be using the remove-prefix-aware helper method from #779.

If you'd like to work on at PR @cs-clarence , that'd be great! Thanks!

@stephenh
Copy link
Owner

Fixed in #902 , thanks @buzap !

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