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

Updated to support Forcing ENUM to be bitwise #713

Merged
merged 16 commits into from
Jun 19, 2018
Merged

Updated to support Forcing ENUM to be bitwise #713

merged 16 commits into from
Jun 19, 2018

Conversation

martinholden-skillsoft
Copy link

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

@RicoSuter
Copy link
Owner

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:

@martinholden-skillsoft
Copy link
Author

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.

@RicoSuter
Copy link
Owner

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?

@RicoSuter
Copy link
Owner

  • Renamed setting to EnforceFlaggedEnums
  • Added IsFlaggedEnumerable to JsonSchema4 => x-enumFlags (consistent with existing x-enumNames property)
  • Open question: How to handle this flag in TypeScript?

/cc @martinholden-skillsoft @paulomorgado @simonlaszcz @FranzP what do you think of these additions/the solution/this PR?

@martinholden-skillsoft
Copy link
Author

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

@RicoSuter
Copy link
Owner

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?

@paulomorgado
Copy link
Contributor

How about EnforceFlagsEnum instead? They are flags enums, not flagged enums.

@RicoSuter
Copy link
Owner

Maybe there is a non-C# name for this concept?

@paulomorgado
Copy link
Contributor

Bitwise?

@martinholden-skillsoft
Copy link
Author

BinaryFlags?

@RicoSuter
Copy link
Owner

BTW: EnumWithFlags.Bar | EnumWithFlags.Baz is serialized to "Bar, Baz"

@RicoSuter
Copy link
Owner

RicoSuter commented Jun 18, 2018

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... :-)

@martinholden-skillsoft
Copy link
Author

+1 from me

@RicoSuter
Copy link
Owner

@martinholden-skillsoft somehow your merge didnt work very well, we now have too many changes in this PR.

@RicoSuter
Copy link
Owner

RicoSuter commented Jun 19, 2018

Ok, if we call the custom JSON Schema extension x-flagEnum (boolean, default: false)?

@RicoSuter
Copy link
Owner

@martinholden-skillsoft
Copy link
Author

@RSuter What do you need me to do?

@RicoSuter
Copy link
Owner

Ill just merge and see what happens :)

@RicoSuter RicoSuter merged commit f5ed433 into RicoSuter:master Jun 19, 2018
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

Successfully merging this pull request may close these issues.

None yet

3 participants