swagger-codegen icon indicating copy to clipboard operation
swagger-codegen copied to clipboard

Enum support for csharp-dotnet2

Open mantasg opened this issue 6 years ago • 2 comments

Description

The language csharp-dotnet2 does not generate valid enum definitions. Enum support was implemented for csharp, but still doesn't exist for csharp-dotnet2.

Swagger-codegen version

2.4.0

Swagger declaration file content or url
        "Portion": {
            "enum": [
                "T",
                "F",
                "R",
                "M"
            ],
            "type": "string"
        }

And the resulting type is

using System;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization;
using Newtonsoft.Json;

namespace IO.Swagger.Model {

  /// <summary>
  /// 
  /// </summary>
  [DataContract]
  public class Portion {

    /// <summary>
    /// Get the string presentation of the object
    /// </summary>
    /// <returns>String presentation of the object</returns>
    public override string ToString()  {
      var sb = new StringBuilder();
      sb.Append("class Portion {\n");
      sb.Append("}\n");
      return sb.ToString();
    }

    /// <summary>
    /// Get the JSON string presentation of the object
    /// </summary>
    /// <returns>JSON string presentation of the object</returns>
    public string ToJson() {
      return JsonConvert.SerializeObject(this, Formatting.Indented);
    }

}
}
Command line used for generation
java -jar swagger-codegen-cli.jar generate -i swagger.json -o gen -l csharp-dotnet2
Related issues/PRs

#2429

Suggest a fix/enhancement

Could probably re-use same mustache template (e.g. modelEnum) as for csharp

mantasg avatar Jan 04 '19 11:01 mantasg

Hey, I've just got hit by this issue using generator.swagger.io. Are there any plans to fix that? Most of real world APIs include enums in their definitions so it's a real problem.

queil avatar May 10 '19 07:05 queil

I am finding this issue this week, my clients are not generating enums. If I take the same YAML file and use csharp generator it generates the valid enum.

TimZander avatar Nov 14 '23 18:11 TimZander