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

Fix generating and parsing enums #374

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

admund
Copy link

@admund admund commented Nov 17, 2021

Issue #, if available:
#349

Description of changes:
When somebody will add a new value for any Enum in the schema and will start sending it, apps will older schema will crash. I fixed the code generator to handle empty or unknown Enum values.
Fix:

  1. I added UNKNOWN enum value to every generated enum.
  2. UKNOWN will be set when the enum value is null (to by safe for kotlin) or some new one.

Old generated code:

final MyEnum something;
if (somethingStr != null) {
  something = MyEnum.valueOf(somethingStr);
} else {
  something = null;
}

New generated code:

MyEnum something;
if (somethingStr != null) {
  try {
    something = MyEnum.valueOf(somethingStr);
  } catch (IllegalArgumentException exception) {
    something = MyEnum.UNKNOWN;
  }
} else {
  something = MyEnum.UNKNOWN;
}

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@admund admund changed the title Fix generating enums Fix generating and parsing enums Nov 17, 2021
@leffsu
Copy link

leffsu commented Nov 17, 2022

Any chance this PR could be reviewed? I really don't want to write custom bash scripts to fix this simple issue

@paigeyahnke
Copy link

paigeyahnke commented Feb 9, 2023

I would also be curious if there's any possibility this could be reviewed? Confirmed that the iOS version of the repo uses an unknown case to handle unknown enum values.

@leffsu
Copy link

leffsu commented Feb 10, 2023

In the meanwhile you can use these gradle tasks on Android while we have no fix coming soon
https://gist.github.com/leffsu/c596197eb231f746303fa216a0a81486

@paigeyahnke
Copy link

In the meanwhile you can use these gradle tasks on Android while we have no fix coming soon https://gist.github.com/leffsu/c596197eb231f746303fa216a0a81486

Thanks! I appreciate the snippet. We'll give that a shot in the meantime.

@gpanshu gpanshu added the pending-triage Issue is pending triage label May 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending-triage Issue is pending triage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants