Skip to content

[aspnetcore] string enums are invalid #7947

@TomSelleck101

Description

@TomSelleck101
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
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions