Ends in:
3 DAYS
5 HRS
35 MIN
0 SEC
Ends in:
3 D
5 H
35 M
0 S
Open Closed

Configure ABP & Swashbuckle to represent enums as strings #2360


User avatar
0
alex@livemobility.com created
  • ABP Framework version: v4.4
  • UI type: Angular
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no
  • Exception message and stack trace:
  • Steps to reproduce the issue:

Hello ABP team. I want to change the configuration of swashbuckle to represent enums as strings in the swagger UI. I couldn't find any up to date documentation about this. Also, if possible, can you confirm that string values are already converted to enums? I checked the available converters in AbpSystemTextJsonSerializerOptions and spotted this converted: AbpStringToEnumConverter

Thanks Alex


3 Answer(s)
  • User Avatar
    0
    EngincanV created
    Support Team .NET Developer

    Hi, actually this is not related to ABP but Swashbuckle/Swagger. But I want to give you some instructions to how to do this,

    • You can use the Unchase.Swashbuckle.AspNetCore.Extensions package and follow these steps.
    • If you don't want to use external package, you can create a new SchemaFilter and define it in your configuration. Check this Stackoverflow answer for this.
  • User Avatar
    0
    alex@livemobility.com created

    Hey ,

    Thanks for the pointers. I installed the mentioned extension and now it works. From my understanding, this should have worked out of the box if there is a StringToEnum converter involved. Maybe it would be good to add this pointers to your documenation, under json.

    In the end, I ended up adding the following line options.AddEnumsWithValuesFixFilters(); , under context.Services.AddAbpSwaggerGenWithOAuth

  • User Avatar
    0
    EngincanV created
    Support Team .NET Developer

    Hi again @alex@livemobility.com, thanks for your suggestion. I will update the documentation.

    I close the question since it seems your problem is resolved. Thanks again.

Made with ❤️ on ABP v9.1.0-preview. Updated on December 02, 2024, 12:35