-
Notifications
You must be signed in to change notification settings - Fork 31
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
Issue with Kiota typescript generator where a free flow dictionary object is treated incorrectly as AdditionalData in interface, Unable to consume the model as post request fails with 400. #1633
Comments
I have already seen couple of similar issues reported and were observed that they are prematurely closed as there was no response from the party. |
Hi @sandeep-tipparthi Can you please provide:
Let us know if you have any additional comments or questions. |
@baywet Thank you for your quick response on this. Here is the snippet where i am preparing the request body - > Note: I am unable to create request without having additionalData as that is something the generated typescript client by Kiota is additionally introducing for a free flow object. let createRequestBody: Api.createRequest = {
name: "TestRole",
description: "Test Role",
policies: {
additionalData: {
service: {
accounts: ["read"],
},
}
},
}
let response = await this.submitRequest(
client,
account,
createRequestBody
); Here is the payload that is sent by this request - > (Captured from the log) {"description":"TEST ROLE","name":"TEST ROLE","policies":{"additionalData": {"service":{"accounts":["read"]}}}} Here is what i expect it to send instead, reason the API does not recognize additionalData - > {"description":"TEST ROLE","name":"TEST ROLE","policies":{"service":{"accounts":["read"]}}} |
Thank you for the additional information. Can you also please share the For context the serialization is handled here |
Here are those code snippets generated - > /**
Let me know if this helps or if you needed anything. For security reasons, i have renamed some of the methods but the generated code is intact. |
Thank you for the additional information. I started investigating this issue and found another bug with additional data see #1639 But fixing that test demonstrated that the serialization part is working as expected. Or at least I'm not able to reproduce it. Can you please triple check which versions of the kiota packages are installed? |
@baywet The version which i had used for generating typescript client using kiota is - "kiotaVersion": "1.23.0", here is the lock file generated for your reference - { Also here is the dotnet tools configuration, where we have defined the version to consider - > What is the version you are suggesting for this change to reflect ? I see the PR is still in Open state and not yet merged to main. Can you please confirm. |
Thank you for the additional information. can you please run the following commands and report the result back npm list @microsoft/kiota-abstractions
npm list @microsoft/kiota-serialization-json
npm list @microsoft/kiota-http-fetchlibrary
npm list @microsoft/kiota-bundle |
@baywet Here is the outcome of the above command - > |
Thank you for the additional information. To answer your previous question, this has now been merged and released. For sanity, please upgrade and test again (preview number is 86) |
@baywet I just have tried upgrading to version preview.86. Although when i consume the model, it still adds additionalData in the request resulting in 400 bad request. I did npm list as well to ensure it is using the right version and it confirms i am using the right version. Kindly help with the same. Was the fix really to exclude additionalData when it serializes the request, because i currently still see additionalData included in the request - > INFO[0028] API Check 'Create Role ' Fail running Expected 201 from POST "{"description":"TEST ROLE","name":"TEST ROLE_32468732","policies":{"additionalData":{"account":{"accounts":["read"]}}}}" As this additionalData is something introduced by kiota generator, i would expect it should be serializing it properly with only including the internal parameters that are provided as part of additionalData but not send the additionalData element itself. In my case, this below request body would result in successful request with 201 response. POST "{"description":"TEST ROLE","name":"TEST ROLE_32468732","policies":{"account":{"accounts":["read"]}}}" |
Thank you for the additional information. As I mentioned earlier, I'm not able to reproduce the issue. Can you put together a draft pull request with a unit test that demonstrates the failure please? |
Hello Team,
Background of this issue -
I am using Kiota typescript generator to generate sdk code from a swagger definition. Kiota typescript generator when it tries to create models for the swagger, it is incorrectly created for case where element is of type object and is a free flow object.
Here is the sample swagger definition on how the complex object looks like -
Currently if you notice this policies object is a free flow where the end user is expected to completely send a blank list of properties or send single / multiple free flow parameters. There is no fixed list of properties which it can send.
Currently when i run the kiota generator with typescript, i am seeing the model class generated has interface for policies
If you notice in the above interfaces generated in the model class, it create an unwanted element called "additionalData", due to this when the typescript later in the consuming script where i plan to use this model for building the request. Creates / forms the request body with additionalData which is not something recognized by the API.
As additionalData is something not available or recognized by the API itself, so the server in this case is returning 400 bad request.
Issue to be fixed -
For any free flow object where a key and value pairs are accepted, please make sure that additionalData is not accounted.
The text was updated successfully, but these errors were encountered: