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 serialization and deserialization of composed types in TS #5358

Closed
wants to merge 6 commits into from

Conversation

rkodev
Copy link
Contributor

@rkodev rkodev commented Sep 8, 2024

Fix serialization and deserialization of composed types in TS #5353

Adds a wrapper class for composed types and passes it for deserialization

Here is an example for the changes

/* tslint:disable */
/* eslint-disable */
// Generated by Microsoft Kiota
// @ts-ignore
import { type BaseRequestBuilder, type Parsable, type ParsableFactory, type ParseNode, type RequestConfiguration, type RequestInformation, type RequestsMetadata, type SerializationWriter } from '@microsoft/kiota-abstractions';

/**
 * 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 {Success}
 */
// @ts-ignore
export function createSuccessFromDiscriminatorValue(parseNode: ParseNode | null | undefined) : ((instance?: Parsable) => Record<string, (node: ParseNode) => void>) {
    return deserializeIntoSuccess;
}
/**
 * The deserialization information for the current model
 * @returns {Record<string, (node: ParseNode) => void>}
 */
// @ts-ignore
export function deserializeIntoSuccess(success: Success | null | undefined = {} as Success) : Record<string, (node: ParseNode) => void> {
    if (!success) return {};
    return {
        "string": n => { success.string = n.getCollectionOfPrimitiveValues<string>(); },
        "successString": n => { success.successString = n.getStringValue(); },
    }
}
/**
 * Builds and executes requests for operations under /example1
 */
export interface Example1RequestBuilder extends BaseRequestBuilder<Example1RequestBuilder> {
    /**
     * Test generating error with message property.
     * @param requestConfiguration Configuration for the request such as headers, query parameters, and middleware options.
     * @returns {Promise<Success>}
     */
     post(requestConfiguration?: RequestConfiguration<object> | null | undefined) : Promise<Success | undefined>;
    /**
     * Test generating error with message property.
     * @param requestConfiguration Configuration for the request such as headers, query parameters, and middleware options.
     * @returns {RequestInformation}
     */
     toPostRequestInformation(requestConfiguration?: RequestConfiguration<object> | null | undefined) : RequestInformation;
}
/**
 * Serializes information the current object
 * @param writer Serialization writer to use to serialize this model
 */
// @ts-ignore
export function serializeSuccess(writer: SerializationWriter, success: Success | null | undefined = {} as Success) : void {
    if (success === undefined || success === null) return;
    if(success.string){
      writer.writeCollectionOfPrimitiveValues<string>(undefined, success.string);
    } else if(success.successString){
      writer.writeStringValue(undefined, success.successString);
    }
}
/**
 * Composed type wrapper for classes {@link string[]}, {@link string}
 */
export interface Success extends Parsable {
    /**
     * Composed type representation for type {@link string[]}
     */
    string?: string[] | null;
    /**
     * Composed type representation for type {@link string}
     */
    successString?: string | null;
}
/**
 * Uri template for the request builder.
 */
export const Example1RequestBuilderUriTemplate = "{+baseurl}/example1";
/**
 * Metadata for all the requests in the request builder.
 */
export const Example1RequestBuilderRequestsMetadata: RequestsMetadata = {
    post: {
        uriTemplate: Example1RequestBuilderUriTemplate,
        responseBodyContentType: "application/json",
        adapterMethodName: "send",
        responseBodyFactory:  createSuccessFromDiscriminatorValue,
    },
};
/* tslint:enable */
/* eslint-enable */

@rkodev rkodev requested a review from a team as a code owner September 8, 2024 22:07
@rkodev rkodev marked this pull request as draft September 9, 2024 04:37
Copy link

sonarcloud bot commented Sep 9, 2024

@rkodev rkodev marked this pull request as ready for review September 9, 2024 07:17
Copy link
Member

@baywet baywet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blocking until we reach a resolution on the issue.

@rkodev
Copy link
Contributor Author

rkodev commented Oct 8, 2024

Closing this as it precedes #5461

@rkodev rkodev closed this Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants