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

[C#] allow customization of generated enum suffixes #4301

Conversation

scottdallamura
Copy link
Contributor

@scottdallamura scottdallamura commented Oct 28, 2019

allows customization of enum suffixes for C#
addresses #4275

{
    "apiPackage": "RestApi.Controllers",
    "modelPackage": "RestApi.Models",
    "packageName": "RestApi",
    "enumNameSuffix": "aaa",
    "enumValueNameSuffix": "bbb"
}

generates stuff like (not that i would ever want 'aaa' or 'bbb' suffixes, but it's a fine example...)

        /// <summary>
        /// Gets or Sets Status
        /// </summary>
        [TypeConverter(typeof(CustomEnumConverter<Statusaaa>))]
        [JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
        public enum Statusaaa
        {
            
            /// <summary>
            /// Enum Activebbb for Active
            /// </summary>
            [EnumMember(Value = "Active")]
            Activebbb = 1,
            
            /// <summary>
            /// Enum Disabledbbb for Disabled
            /// </summary>
            [EnumMember(Value = "Disabled")]
            Disabledbbb = 2
        }

PR checklist

  • Read the contribution guidelines.
  • If contributing template-only or documentation-only changes which will change sample output, build the project before.
  • Run the shell script(s) under ./bin/ (or Windows batch scripts under.\bin\windows) to update Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit, and these must match the expectations made by your contribution. You only need to run ./bin/{LANG}-petstore.sh, ./bin/openapi3/{LANG}-petstore.sh if updating the code or mustache templates for a language ({LANG}) (e.g. php, ruby, python, etc).
  • File the PR against the correct branch: master, 4.1.x, 5.0.x. Default: master.
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language.

@auto-labeler
Copy link

auto-labeler bot commented Oct 28, 2019

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

@scottdallamura
Copy link
Contributor Author

copying the technical committee ...
@mandrean @jimschubert @frankyjuang

@scottdallamura
Copy link
Contributor Author

so i think i figured out how to run the scripts, and indeed a bunch of files were generated. i expected the aspnetcore one (and i've committed the updated version) but it's unclear to me why so many samples for other languages were generated. i'm trying it without my changes now.

@scottdallamura
Copy link
Contributor Author

looks ready to go? let's do it

@wing328
Copy link
Member

wing328 commented Nov 3, 2019

Thanks for the PR but your commit (as shown in the Commits tab) is not linked to your Github account, which means this PR won't count as your contribution in https://github.com/OpenAPITools/openapi-generator/graphs/contributors.

Let me know if you need help fixing it.

Ref: https://github.com/OpenAPITools/openapi-generator/wiki/FAQ#how-can-i-update-commits-that-are-not-linked-to-my-github-account

@scottdallamura scottdallamura force-pushed the users/scottdallamura/customizeenums branch from 87b6647 to fb5cc75 Compare November 3, 2019 14:18
@scottdallamura
Copy link
Contributor Author

oops. fixed it!

@@ -27,6 +27,8 @@ sidebar_label: aspnetcore
|useNewtonsoft|Uses the Newtonsoft JSON library.| |true|
|newtonsoftVersion|Version for Microsoft.AspNetCore.Mvc.NewtonsoftJson for ASP.NET Core 3.0+| |3.0.0-preview5-19227-01|
|useDefaultRouting|Use default routing for the ASP.NET Core version. For 3.0 turn off default because it is not yet supported.| |true|
|enumNameSuffix|Suffix that will be appended to all enum names.| |Enum|
|enumValueNameSuffix|Suffix that will be appended to all enum value names.| |Enum|
Copy link
Member

Choose a reason for hiding this comment

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

What is the use case for this? Why wouldn't someone just put the expected value in the enum text field in the specification document?

Copy link
Contributor Author

@scottdallamura scottdallamura Nov 11, 2019

Choose a reason for hiding this comment

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

The behavior before my change is to append Enum to both the name of the enum type and each value. So you end up with

enum MyEnum {
  Value1Enum,
  Value2Enum
}

I didn't want to break the existing default behavior, so I made that suffix customizable too.

If you have suggestions I'd be happy to change it :)

Copy link
Member

Choose a reason for hiding this comment

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

Sorry for the delay in response. The holidays were pretty hectic for me.

I think we'll want to call the value one enumValueSuffix. I'll do that in a separate commit.

@jimschubert jimschubert merged commit 9b893ef into OpenAPITools:master Jan 5, 2020
@jimschubert jimschubert added this to the 4.2.3 milestone Jan 5, 2020
jimschubert added a commit to jimschubert/openapi-generator that referenced this pull request Jan 11, 2020
* master: (187 commits)
  [core] Initial FeatureSet structures and definitions (OpenAPITools#3614)
  Add Cisco to the user list (OpenAPITools#4971)
  comment out php slim4 in ensure-up-to-date
  update samples
  [Python] Allow models to have properties of type self (OpenAPITools#4888)
  Add npmRepository option to javascript generators (OpenAPITools#4956)
  [Slim4] Add ref support to Data Mocker (OpenAPITools#4932)
  Fix auto-labeler for jax-rs (OpenAPITools#4943)
  [doc] full generator details (OpenAPITools#4941)
  comment out python flask 2 test (OpenAPITools#4949)
  [jaxrs-spec][quarkus] update to version 1.1.1.Final (OpenAPITools#4935)
  [cli] Full config help details (OpenAPITools#4928)
  Add RequestFile to typescript-node model template (OpenAPITools#4903)
  [csharp] enum suffix changes enumValueNameSuffix to enumValueSuffix (OpenAPITools#4927)
  [C#] allow customization of generated enum suffixes (OpenAPITools#4301)
  [Kotlin] Correct isInherited flag for Kotlin generators (OpenAPITools#4254)
  [Rust Server] Fix panic handling headers (OpenAPITools#4877)
  Initial CODEOWNERS (OpenAPITools#4924)
  [scala] Support for Set when array has uniqueItems=true (OpenAPITools#4926)
  remove nodejs server samples, scripts (OpenAPITools#4919)
  ...
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.

3 participants