unchase / Unchase.Swashbuckle.AspNetCore.Extensions

:hammer: A library contains a bunch of extensions (filters) for Swashbuckle.AspNetCore.
https://www.nuget.org/packages/Unchase.Swashbuckle.AspNetCore.Extensions
Apache License 2.0
115 stars 16 forks source link

Imposible to use AddEnumValuesDescriptions with enums to string mapping #6

Closed ketovdk closed 4 years ago

ketovdk commented 4 years ago

AddEnumValuesDescription with System.InvalidCastException: Unable to cast object of type 'Microsoft.OpenApi.Any.OpenApiString' to type 'Microsoft.OpenApi.Any.OpenApiInteger'.

To reproduce: Use json enumToStringMapping with .AddJsonOptions( options => options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter())) Use options.AddEnumsWithValuesFixFilters(true); in AddSwaggerGen

unchase commented 4 years ago

Hi, @ketovdk Using AddEnumsWithValuesFixFilters becomes useless if you use JsonStringEnumConverter. But I agree that the error must be fixed.

It can display the following (after fix): enum

for:

    /// <summary>
    /// Tag for TodoItem.
    /// </summary>
    [Description("Tag enum")]
    public enum Tag
    {
        /// <summary>
        /// None.
        /// </summary>
        [Description("Default tag")]
        None = 0,

        /// <summary>
        /// Task.
        /// </summary>
        [Description("Some task")]
        Task = 1,

        /// <summary>
        /// Workout.
        /// </summary>
        [Description("Periodical job")]
        Workout = 2
    }