Base solution for your next web application
Open Closed

about nswag automatically refreshes service-proxies #3646


User avatar
0
jaylan created

Why do I generate enum that are not the same as yours? Your:

export enum IsTenantAvailableOutputState {
    _1 = 1,
    _2 = 2,
    _3 = 3,
}

export enum FriendDtoState {
    _1 = 1,
    _2 = 2,
}

My:

export enum StudentDtoGender {
    Unknown = <any>"Unknown",
    Secrecy = <any>"Secrecy",
    Man = <any>"Man",
    Woman = <any>"Woman",
}

And another question, there is a appenums. ts file in the project, encapsulation of service-proxies enum, why not use enum directly?

export class AppTenantAvailabilityState {
    static Available: number = IsTenantAvailableOutputState._1;
    static InActive: number = IsTenantAvailableOutputState._2;
    static NotFound: number = IsTenantAvailableOutputState._3;
}

Thank you. Have a nice day.


4 Answer(s)
  • User Avatar
    0
    alper created
    Support Team

    If you changed nswag DefaultEnumHandling to EnumHandling.String then it might result different proxy generation. <a class="postlink" href="https://github.com/RSuter/NSwag/issues/14">https://github.com/RSuter/NSwag/issues/14</a>

    For the second question, the encapsulation improves readability. When you request data from host, let's say you want to get Available tenants with proxy generated enum: _.getTenants( IsTenantAvailableOutputState.1);

    with encapsulated enum: .getTenants( AppTenantAvailabilityState .Available);

  • User Avatar
    0
    jaylan created

    why not generated enum like thiis:

    export enum IsTenantAvailableOutputState {
        Available = 1, 
        InActive = 2, 
        NotFound = 3, 
    }
    

    then ,use like this .getTenants( IsTenantAvailableOutputState.Available );

    I'm confused.

  • User Avatar
    0
    jaylan created

    I didn't changed nswag DefaultEnumHandling to EnumHandling.String .I used the default service.config.nswag in our angular projecet .But the proxy generated enum not like yours.

  • User Avatar
    0
    alper created
    Support Team

    nswag produces enums like this as you mentioned. without enum values aspnet cannot handle request

    export enum StudentDtoGender { Unknown = <any>"Unknown", Secrecy = <any>"Secrecy", Man = <any>"Man", Woman = <any>"Woman", }