NSwag icon indicating copy to clipboard operation
NSwag copied to clipboard

Class Style - Add EnumDataType Attribute on Enum to Allow ValidationContext

Open QzLP2P opened this issue 9 months ago • 0 comments

I need to validate that enum is defined. Can you add support for EnumDataType

Exemple below :

   [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.0.7.0 (NJsonSchema v11.0.0.0 (Newtonsoft.Json v13.0.0.0))")]
    public enum BeerType
    {

        [System.Runtime.Serialization.EnumMember(Value = @"Aromatique")]
        Aromatique = 0,

        [System.Runtime.Serialization.EnumMember(Value = @"Doux")]
        Doux = 1,

        [System.Runtime.Serialization.EnumMember(Value = @"Ambre")]
        Ambre = 2,
        // ...
    }

    [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.0.7.0 (NJsonSchema v11.0.0.0 (Newtonsoft.Json v13.0.0.0))")]
    public partial class SetBeerInput
    {

        [System.Text.Json.Serialization.JsonPropertyName("type")]
        [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)]
        [System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.JsonStringEnumConverter))]
        // TODO : Add  [EnumDataType(typeof(BeerType))] To Allow ValidationContext
        public BeerType Type { get; set; } = default!;

        [System.Text.Json.Serialization.JsonPropertyName("name")]
        [System.ComponentModel.DataAnnotations.Required]
        [System.ComponentModel.DataAnnotations.StringLength(30, MinimumLength = 7)]
        public string Name { get; set; } = default!;

    }

QzLP2P avatar May 07 '24 08:05 QzLP2P