-
-
Notifications
You must be signed in to change notification settings - Fork 540
Updated to support Forcing ENUM to be bitwise #713
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
Conversation
Thanks for the PR. Having a global option is nice, but I really want to solve this also on a per enum basis somehow... what do you think about that? Ref: |
Agreed a better solution that is driven by the schema would be best but like the expert (you) I couldn't find any agreed upon approach. |
What if we rename your setting to EnforceEnumFlags and add a new custom extension x-enumFlags=true so that we can at least support it in the njs toolchain? |
/cc @martinholden-skillsoft @paulomorgado @simonlaszcz @FranzP what do you think of these additions/the solution/this PR? |
Looks good to me for c#. I am not great on TypeScript but from what I have read the exact same logic should be fine - the bitwise progression is the important bit (i.e. 1, 2,4,8 etc) https://basarat.gitbooks.io/typescript/content/docs/enums.html#enums-as-flags |
TypeScript: But that's probably only working in the JS "process" - the bigger problem is that the serialization does not work... So it has to be implemented/done manually for flag enums. How is serialization of flag enums handled in C# with Newtonsoft.Json? |
How about |
Maybe there is a non-C# name for this concept? |
Bitwise? |
BinaryFlags? |
BTW: |
Bitwise and Binary sounds a little bit too low-level :-) and EnforceFlagsEnums sounds weird because of the two plurals... would be EnforceFlagEnums ok and correct? Because of the special and C#/Newtonsoft only serialization of flags enums, I'd strongly recommend against using them anyway, but we will merge this... :-) |
+1 from me |
@martinholden-skillsoft somehow your merge didnt work very well, we now have too many changes in this PR. |
Ok, if we call the custom JSON Schema extension |
@RSuter What do you need me to do? |
Ill just merge and see what happens :) |
The OpenApi/Swagger specs don't lend themselves easily to BITWISE ENUMS.
Updated the CSharpGeneratorSettings to add a flag (default:false) to allow creating ENUMs that are BITWISE flags