-
Notifications
You must be signed in to change notification settings - Fork 210
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 #5461
Conversation
8b7c090
to
070f0ac
Compare
Sample builder /* 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 {string[] | string}
*/
// @ts-ignore
export function createSuccessFromDiscriminatorValue(parseNode: ParseNode | 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: Partial<Parsable | string[] | string> | undefined = {}) : Record<string, (node: ParseNode) => void> {
return {
"" : n => { success = n.getCollectionOfPrimitiveValues<string>() ?? 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<string[] | string>}
*/
post(requestConfiguration?: RequestConfiguration<object> | undefined) : Promise<string[] | string | 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> | 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: Partial<string[] | string> | undefined | null = {}) : void {
if (success === undefined || success === null) return;
switch (true) {
case Array.isArray(success) && (success).every(item => typeof item === 'string') :
writer.writeCollectionOfPrimitiveValues<string>(undefined, success as string[]);
break;
case typeof success === "string":
writer.writeStringValue(undefined, success as string);
break;
}
}
export type Success = string[] | string;
/**
* 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 */
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also enable the intergration test at
Line 234 in 01710c8
"Rationale": "https://github.com/microsoft/kiota/issues/5256" |
7971456
to
58de04a
Compare
9d28f6d
to
a5db8e9
Compare
tests/Kiota.Builder.Tests/Writers/TypeScript/CodeFunctionWriterTests.cs
Outdated
Show resolved
Hide resolved
a5db8e9
to
bb6b467
Compare
src/Kiota.Builder/Writers/TypeScript/CodeFileDeclarationWriter.cs
Outdated
Show resolved
Hide resolved
9284c40
to
87585ef
Compare
src/Kiota.Builder/Writers/TypeScript/TypeScriptConventionService.cs
Outdated
Show resolved
Hide resolved
aaffa8e
to
6d45335
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we still need to remove this line from the integration tests....
Line 214 in 6a59a01
"Rationale": "https://github.com/microsoft/kiota/issues/5353" |
Any chance we can double check the failing intergration test? |
0daf6b8
to
b77ac28
Compare
Quality Gate passed for 'kiota'Issues Measures |
src/Kiota.Builder/Writers/TypeScript/CodeFileDeclarationWriter.cs
Outdated
Show resolved
Hide resolved
Fix import statements fix - rewrite to if statements
437745e
to
746ff2d
Compare
Quality Gate passed for 'microsoft_kiota_frontend'Issues Measures |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for making the changes!
Fix serialization and deserialization of composed types in TS
fixes #5353
Changes made to fix the serializer will include writing an undefined value for the string and and the collection of string
changes made to fix thd deserializer. since
undefined
is not an acceptable key in a record, the serializers will have to invoke the method with an empty key i.e "" to as the assign the value of success to the node