microsoft / kiota-typescript

TypeScript libraries for Kiota-generated API clients.
https://aka.ms/kiota/docs
MIT License
32 stars 25 forks source link

Add a method to get the raw value of the node #1204

Closed koros closed 1 month ago

koros commented 1 month ago

This will be used to support the generation of composed type which is made up of primitives:

/**
 * Creates a new instance of the appropriate class based on discriminator value
 * @param parseNode The parse node to use to read the discriminator value and create the object
 * @returns {Primitives}
 */
export function createPrimitivesFromDiscriminatorValue(parseNode: ParseNode | undefined) : number | string | undefined {
    const nodeValue = parseNode?.getNodeValue();
    switch (typeof nodeValue) {
        case "number":
        case "string":
            return nodeValue;
        default:
            return undefined;
    }
}