-
Notifications
You must be signed in to change notification settings - Fork 30
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
Serialization and Deserialization of Guid[] fields is incorrectly handled #1478
Comments
Thanks for raising this @TheDusty01 With the changes in #1475 as well as the latest release of the generator, any chance you can confirm this is still an issue with the latest versions of the packages? |
Hey, we tried it out with the new Kiota v1.20.0 release and kiota TS preview 74 but when trying to send the Guid array we now get a request generated like this: Click to expand
Seems to be an error in the kiota json parser. This is the generated code for parsing the request object to json: /**
* Serializes information the current object
* @param writer Serialization writer to use to serialize this model
*/
// @ts-ignore
export function serializeUpdatePlanRequest(writer: SerializationWriter, updatePlanRequest: Partial<UpdatePlanRequest> | undefined | null = {}) : void {
if (updatePlanRequest) {
writer.writeCollectionOfPrimitiveValues<Guid>("scheduleIds", updatePlanRequest.scheduleIds);
writer.writeTimeOnlyValue("endTime", updatePlanRequest.endTime);
writer.writeStringValue("name", updatePlanRequest.name);
writer.writeCollectionOfObjectValues<PlanConfigurationRequest>("planConfigurations", updatePlanRequest.planConfigurations, serializePlanConfigurationRequest);
writer.writeCollectionOfObjectValues<PlanDataRequest>("planDatas", updatePlanRequest.planDatas, serializePlanDataRequest);
writer.writeGuidValue("projectId", updatePlanRequest.projectId);
}
} Even if I comment out everything apart from the simple string |
Hi @TheDusty01 |
Thanks for clarifying. This issue got fixed by #1475. Could you possibly link/share some details on how to setup a default kiota client with the request compression disabled? Creating a new http client by manually adding the default middleware seems weird: const http = KiotaClientFactory.create(undefined, [
new RetryHandler(), new RedirectHandler(), new ParametersNameDecodingHandler(), new UserAgentHandler(), new HeadersInspectionHandler()
]);
const adapter = new FetchRequestAdapter(undefined, undefined, undefined, http);
const client = createApiClient(adapter); |
Thanks for confirming this is solved. |
What are you generating using Kiota, clients or plugins?
API Client
In what context or format are you using Kiota?
Nuget Tool
Describe the bug
When fetching a response with a
Guid[]
field, Kiota serializes it as astring[]
at runtime, even though it's defined asGuid[]
. Similarly, when sending a request containing aGuid[]
field, the generated JSON is malformed, causing a server-side parse error. See examples below.Actual behavior
Serialization
The current generated request:
The payload sent to the server is malformed (generated by the call to the resource's
post
method on the Kiota generated api client). ThescheduleIds
field is incorrectly serialized as an object array instead of astring[]
. Meanwhile, theprojectId
field is correctly serialized as astring
:Deserialization
This generated response:
At runtime, the
scheduleIds
field is incorrectly deserialized as astring[]
, whileGuid
fields likeid
andprojectId
are correctly deserialized as objects:TL;DR:
The
scheduleIds
field is defined asGuid[]
in the model, but is treated asstring[]
at runtime.Expected behavior
Serialization
The resulting JSON should be well-formed with the
scheduleIds
field serialized as an array of strings, not as an array of objects.Deserialization
The
scheduleIds
field should be deserialized as an array ofGuid
objects, not as an array of strings.How to reproduce
Open API description file
Click to expand Open API description file
Kiota Version
Kiota Version:
1.19.1+d294e04ba7f756896878a7015df1648f9dc0bcde
Kiota TS package version:
"@microsoft/kiota-bundle": "^1.0.0-preview.69"
Known Workarounds
Serialization
Use the following workaround to send
Guid[]
asstring[]
during runtime:Deserialization
TypeScript treats
scheduleIds
as aGuid[]
, while Kiota assigns it as astring[]
. Consequently, we must iterate over the array to parse each element into aGuid
. However, since TypeScript assumes every element is already aGuid
, we first need to cast each element to astring
. SinceGuid
cannot be directly cast to a string, we first cast it tounknown
and then tostring
.TypeScript expects each element of
scheduleIds
to already be aGuid
, but Kiota assigns it as astring[]
. To handle this, we need to convert each element to aGuid
. Since TypeScript assumes the elements are alreadyGuid
s, we first cast them tostring
by casting tounknown
and then tostring
.Configuration
Other information
Could be related to #1467 and potentially fixed by #1475
The text was updated successfully, but these errors were encountered: