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

Add isEnumRef, isEnumOrRef to CodegenProperty #13880

Merged
merged 5 commits into from
Nov 8, 2022

Conversation

wing328
Copy link
Member

@wing328 wing328 commented Nov 2, 2022

To address the bug that isEnum is not set properly when the enum is a reference (instead of an inline schema) in a codegen property, I've added isEnumRef and also isEnumOrRef mustache tags to provide a migration path to address the issue.

Why not simply just fix it like #9526? We appreciate the fix but the problem is that it impacts lots of generators and some output won't even compile/work any more: https://gist.github.com/wing328/d8ef17e0b884ea821f2c7a1218ab368f

isEnumRef is set to true if the it's a $ref and the $ref is an enum.
isEnumOrRef is set to true if isEnumRef or isEnum is set to true

I've updated r templates to use isEnumOrRef and there's no change in the output.

I've updated powershell templates to use isEnumOrRef, which results in a fix.

Some tests in this PR comes from #13389 (credit @rivancic)

After this PR is merged, users can update the template and/or generator accordingly to ensure the output works using isEnumOrRef or isEnumRef and of course we welcome PRs to apply these fix upstream in this official repo.

Related PRs/issues:

cc @aymanbagabas @questionableque @snowe2010 @oszust002 @rivancic @flowstef @LukeMarlin

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master (6.1.0) (minor release - breaking changes with fallbacks), 7.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

cc @OpenAPITools/generator-core-team

@wing328 wing328 changed the title Property enum enhancement Add isEnumRef to CodegenProperty Nov 2, 2022
@wing328 wing328 added this to the 6.3.0 milestone Nov 2, 2022
@wing328 wing328 marked this pull request as ready for review November 2, 2022 02:40
Copy link
Contributor

@4brunu 4brunu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, and I think it's a good solution that doesn't break all the generators 👍

@devhl-labs
Copy link
Contributor

Consider finding all isEnum and replace with something like isEnum_Deprecated then properly fix isEnum. This would make it obvious to mustache authors there is something wrong with the enum property they are using.

@wing328
Copy link
Member Author

wing328 commented Nov 6, 2022

@devhl-labs to be clear, isEnum will not be deprecated as there are generators that need a way to tell if the enum is defined inline.

@devhl-labs
Copy link
Contributor

I'm not suggesting you deprecate isEnum.

To address the bug that isEnum is not set properly when the enum is a reference

This says that the current implementation is bugged, so deprecate that bugged version. Then make 'new' isEnum (which can still be called isEnum since the bugged version was renamed) which is fixed. Also, there is isInnerEnum which is true for inline enums.

The benefit here is that templates using the bugged version will be very obvious, plus isEnum can be true for all enums as you would expect.

@snowe2010
Copy link
Contributor

From a software engineering perspective I agree with @devhl-labs. Do it right, now, or you'll be stuck with some decision that might not be best for the codebase, will result in confusion among contributors, will result in tech debt, and doesn't really solve the underlying issue.

From a consumer perspective. I don't care which as long as it gets fixed 😂

@wing328
Copy link
Member Author

wing328 commented Nov 8, 2022

Thanks for all the feedback.

We definitely want to fix the issue and there were already several attempts (PRs) from the community before to fix it but no one has the time to fix all the generators (at least 10+) impacted by the fix.

We can leave this PR opened and ask the community to fix the generator one by one but this will result in a lot of overhead (e.g. rebase) and it will become a giant PR that is hard to review and work on so I would rather update the default codegen with isEnumRef, isEnumOrRef and let the community of each generator to update the templates accordingly.

@wing328 wing328 changed the title Add isEnumRef to CodegenProperty Add isEnumRef, isEnumOrRef to CodegenProperty Nov 8, 2022
@wing328 wing328 merged commit ca5d9b5 into master Nov 8, 2022
@wing328 wing328 deleted the property-enum-enhancement branch November 8, 2022 03:16
@devhl-labs
Copy link
Contributor

devhl-labs commented Nov 8, 2022 via email

@aymanbagabas
Copy link
Contributor

I agree with @devhl-labs, isEnum is the bugged one and should be fixed. Replacing the current isEnum with isEnum_Deprecated and fixing the actual bug is the right approach to me.

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

Successfully merging this pull request may close these issues.

None yet

5 participants