Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for OneOf Subtyping - Generators were failing to generate proper discriminators #90

Merged

Conversation

pixellos
Copy link
Contributor

@pixellos pixellos commented Mar 7, 2021

Tested on generators:

  • TypeScript
  • TypeScript-fetch

Given:

  • User is using subTypes to create polymorphic ode

Whe:

  • Code is generated

Then

  • Discriminators are not taken into account

Should:

  • Code should be discriminators aware

Old behavior:
Generated code with discriminators not compiling
image

No discriminators:


export class Base {
    'str': string;
    'i': number;

    static readonly discriminator: string | undefined = undefined;

    static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string, format: string}> = [
        {
            "name": "str",
            "baseName": "str",
            "type": "string",
            "format": ""
        },
        {
            "name": "i",
            "baseName": "i",
            "type": "number",
            "format": "int32"
        }    ];

    static getAttributeTypeMap() {
        return Base.attributeTypeMap;
    }
    
    public constructor() {
    }
}

export class A {
    'str': string;

    static readonly discriminator: string | undefined = undefined;

    static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string, format: string}> = [
        {
            "name": "str",
            "baseName": "str",
            "type": "string",
            "format": ""
        }    ];

    static getAttributeTypeMap() {
        return A.attributeTypeMap;
    }
    
    public constructor() {
    }
}


Expected Behavior (current):


export class Base {
    'type'?: string;
    'i': number;
    'l': number;

    static readonly discriminator: string | undefined = "type";

    static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string, format: string}> = [
        {
            "name": "type",
            "baseName": "type",
            "type": "string",
            "format": "string"
        },
        {
            "name": "i",
            "baseName": "i",
            "type": "number",
            "format": "int32"
        },
        {
            "name": "l",
            "baseName": "l",
            "type": "number",
            "format": "int64"
        }    ];

    static getAttributeTypeMap() {
        return Base.attributeTypeMap;
    }
    
    public constructor() {
        this.type = "Base";
    }
}


export class B {
    'i': number;
    'type'?: string;

    static readonly discriminator: string | undefined = "type";

    static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string, format: string}> = [
        {
            "name": "i",
            "baseName": "i",
            "type": "number",
            "format": "int32"
        },
        {
            "name": "type",
            "baseName": "type",
            "type": "string",
            "format": "string"
        }    ];

    static getAttributeTypeMap() {
        return B.attributeTypeMap;
    }
    
    public constructor() {
        this.type = "B";
    }
}

@pixellos
Copy link
Contributor Author

pixellos commented Mar 7, 2021

@Wicpar
Can U throw an eye?

@Wicpar
Copy link
Collaborator

Wicpar commented Mar 8, 2021

Looks good to me, not too happy about the formatting changes though as it makes it harder to see the actual changes, but that's ok.

@Wicpar Wicpar merged commit f94a2f6 into papsign:master Mar 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants