Skip to content

[aspnetcore] string enums are invalid #7947

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

Open
TomSelleck101 opened this issue Mar 31, 2018 · 1 comment
Open

[aspnetcore] string enums are invalid #7947

TomSelleck101 opened this issue Mar 31, 2018 · 1 comment

Comments

@TomSelleck101
Copy link

Description

C# auto generated aspnetcore project contains invalid enums

Swagger-codegen version

2.3.1

Swagger declaration file content or url

Gist here

yaml code

  status:
	type: "string"
	description: "pet status in the store"
	enum:
	- "available"
	- "pending"
	- "sold"
Command line used for generation

editor.swagger.io

Steps to reproduce
  1. Take code from gist
  2. Paste into editor.swagger.io (http, not https)
  3. Generate an aspnetcore server
  4. Model generated looks like the following:
        public enum StatusEnum
        { 
            /// <summary>
            /// Enum AvailableEnum for available
            /// </summary>
            [EnumMember(Value = available)]
            AvailableEnum = 1,
            
            /// <summary>
            /// Enum PendingEnum for pending
            /// </summary>
            [EnumMember(Value = pending)]
            PendingEnum = 2,
            
            /// <summary>
            /// Enum SoldEnum for sold
            /// </summary>
            [EnumMember(Value = sold)]
            SoldEnum = 3
        }

This is invalid C#, the Value = x should be Value = "x".

Related issues/PRs

Possibly related

Suggest a fix/enhancement

Generated model should look like the following:

    public enum StatusEnum
    { 
        /// <summary>
        /// Enum AvailableEnum for available
        /// </summary>
        [EnumMember(Value = "available")]
        AvailableEnum = 1,
        
        /// <summary>
        /// Enum PendingEnum for pending
        /// </summary>
        [EnumMember(Value = "pending")]
        PendingEnum = 2,
        
        /// <summary>
        /// Enum SoldEnum for sold
        /// </summary>
        [EnumMember(Value = "sold")]
        SoldEnum = 3
    }
@jages
Copy link
Contributor

jages commented Apr 27, 2018

i suggest updating src/main/resources/csharp/enumClass.mustache @ line 14, see #8027 for reference

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

No branches or pull requests

2 participants