-
Notifications
You must be signed in to change notification settings - Fork 284
Description
What are you generating using Kiota, clients or plugins?
API Client/SDK
In what context or format are you using Kiota?
Windows executable
Client library/SDK language
Csharp
Describe the bug
The Microsoft.Kiota.Abstractions.RequestInformation class has a SetResponseHandler method that sets an IResponseHandler instance and sets the ResponseHandlerOption to the request options.
As far as I understand, you should use code like this to use it:
PackagesRequestBuilder packagesRequestBuilder = vbusOrg.Packages;
RequestInformation packagesRequestInfo = packagesRequestBuilder.ToGetRequestInformation();
packagesRequestInfo.SetResponseHandler(adapter); // adapter implements IResponseHandler
var packageListResponse = await packagesRequestBuilder.GetAsync(requestConfiguration =>
{
requestConfiguration.QueryParameters.PackageType = GetPackage_typeQueryParameterType.Nuget;
requestConfiguration.QueryParameters.PerPage = 5;
});But the problem is that the GetAsync method is generated with the following content:
public async Task<List<global::GitHub.Models.Package>?> GetAsync(Action<RequestConfiguration<global::GitHub.Orgs.Item.Packages.PackagesRequestBuilder.PackagesRequestBuilderGetQueryParameters>>? requestConfiguration = default, CancellationToken cancellationToken = default)
{
var requestInfo = ToGetRequestInformation(requestConfiguration);
var errorMapping = new Dictionary<string, ParsableFactory<IParsable>>
{
{ "401", global::GitHub.Models.BasicError.CreateFromDiscriminatorValue },
{ "403", global::GitHub.Models.BasicError.CreateFromDiscriminatorValue },
};
var collectionResult = await RequestAdapter.SendCollectionAsync<global::GitHub.Models.Package>(requestInfo, global::GitHub.Models.Package.CreateFromDiscriminatorValue, errorMapping, cancellationToken).ConfigureAwait(false);
return collectionResult?.AsList();
}As seen, the method generates a new RequestInformation, and I cannot see any methods that actually allow the one generated before the call to GetAsync to be passed into the method.
This means that it (as far as I can see) in practice is impossible to use your own IResponseHandler implementation.
Expected behavior
When setting a custom IResponseHandler instance to the RequestInformation instance, I would expect it to be utilized.
How to reproduce
- Generate an API client of any kind (I'm using github api).
- Create a class implementing
IResponseHandler. - Set a breakpoint in the
HandleResponseAsyncmethod. - Execute the
GetAsynccode as shown in bug description. - Notice that tghe breakpoint from (3) is not hit
Open API description file
No response
Kiota Version
1.28.0+57130b1b1db3bc5c060498682f41e20c8ae089f2
Latest Kiota version known to work for scenario above?(Not required)
No response
Known Workarounds
No response
Configuration
- OS: Windows 11 and Linux Mint 22.2 (based on Ubuntu 24.04)
- Architecture x64 (both)
Debug output
Click to expand log
Other information
As far as I can see, the issue is that the RequestInformation instance generated before the call to GetAsync is simply not passed into the GetAsync method or the RequestBuilder instance in any way.
I see some ways of resolving this:
- Create an overload of all the
Send*methods that pass aRequestInformationinstanse to be used instead of creating a new one. - Add an optional
RequestInformationparameter to all theSend*methods and use that instead of creating a new one. - Add a
RequestInformationfield to theRequestBuilderclass and use that if set instead of creating a new one. - Create an event handler on
RequestBuilderclass that can be subscribed to in order to provide theRequestInformation.
Note that these would need to be done on the IRequestAdapter interface also as the RequestBuilder calls further to the RequestAdapter member.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status