Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

717 B
Raw Blame
using Microsoft.AspNetCore.OpenApi;
using Microsoft.OpenApi;

namespace Grand.Module.Api.Infrastructure.Transformers;

public class EnumSchemaTransformer : IOpenApiSchemaTransformer
{
    public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext context, CancellationToken cancellationToken)
    {
        if (context.JsonTypeInfo.Type.IsEnum)
        {
            var enumValues = Enum.GetValues(context.JsonTypeInfo.Type);
            foreach (var item in enumValues)
            {
                var name = Enum.GetName(context.JsonTypeInfo.Type, item);
                schema.Description += $"{(int)item} - {name}; ";
            }
        }
        return Task.CompletedTask;
    }
}