Swagger keep names in number enum

Viewed 240

I am working with an ASP .Net Core Entity Framework backend and an angular frontend and since they are communicating via RESTful services, I need the models of my backend in my frontend, which I am doing with the ASP.Swashbuckle Package.

Unfortunately when I have an enum in my backend and I am generation it for the frontend, the names of the enum get lost.

C#:

 public enum AttachmentTypes
    {
        [Display(Name = "USER_PROFILE_PICTURE", Description = "Profile picture for User")]
        USER_PROFILE_PICTURE = 1,

        [Display(Name = "GROUP_PROFILE_PICTURE", Description = "Profile picture for Group")]
        GROUP_PROFILE_PICTURE = 2
  
    }

Typescript result:

export type AttachmentTypes = 1 | 2;

export const AttachmentTypes = {
    NUMBER_1: 1 as AttachmentTypes,
    NUMBER_2: 2 as AttachmentTypes
};

I have read a few articles concerning that issue in which was written, that this is an issue with swagger. Since the articles where only up to 2017/18 I hope that there now is a solution for this problem.

PS: I cant use a string enum, because the enum values should represent the primary keys in the DB and since these enums are only lookup tables I dont want to change their primary key to GUIDs

0 Answers
Related