You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add an option which allows to generate asynchronous API calls instead of the current synchronous calls for the csharp/dotnet client. I haven't been able to find any options which enables this feature, if it exists somewhere please let me know 😄
Swagger declaration file content or url
Example declaration file used in suggestion to how to implement it.
swagger: '2.0'tags:
- name: Serverdescription: Operations available to retrieve information about a serverpaths:
/servers/{server_id}:
get:
tags:
- Serversummary: Get basic server informationoperationId: getServerdescription: | This returns basic information about a specific serverparameters:
- name: server_idin: pathdescription: The server id to retrieve the basic information abouttype: integerrequired: true
Tried keywords such as .net, dotnet, csharp, callbacks, asynchronous, async
Suggest a fix/enhancement
This is what I currently change on the generated code and what could be generated alongside/in replacement.
Add a method called CallApiAsync to the generated ApiClient
publicvoidCallApiAsync(Stringpath,RestSharp.Methodmethod,Dictionary<String,String>queryParams,StringpostBody,Dictionary<String,String>headerParams,Dictionary<String,String>formParams,Dictionary<String,FileParameter>fileParams,String[]authSettings,Action<IRestResponse>callback){varrequest=newRestRequest(path,method);UpdateParamsForAuth(queryParams,headerParams,authSettings);// add default header, if anyforeach(vardefaultHeaderin_defaultHeaderMap)request.AddHeader(defaultHeader.Key,defaultHeader.Value);// add header parameter, if anyforeach(varparaminheaderParams)request.AddHeader(param.Key,param.Value);// add query parameter, if anyforeach(varparaminqueryParams)request.AddParameter(param.Key,param.Value,ParameterType.GetOrPost);// add form parameter, if anyforeach(varparaminformParams)request.AddParameter(param.Key,param.Value,ParameterType.GetOrPost);// add file parameter, if anyforeach(varparaminfileParams)request.AddFile(param.Value.Name,param.Value.Writer,param.Value.FileName,param.Value.ContentType);if(postBody!=null)// http body (model) parameterrequest.AddParameter("application/json",postBody,ParameterType.RequestBody);RestClient.ExecuteAsync(request,callback);}
publicServerGetServer(int?serverId){// verify the required parameter 'serverId' is setif(serverId==null)thrownewApiException(400,"Missing required parameter 'serverId' when calling GetServer");varpath="/servers/{server_id}";path=path.Replace("{format}","json");path=path.Replace("{"+"server_id"+"}",ApiClient.ParameterToString(serverId));varqueryParams=newDictionary<String,String>();varheaderParams=newDictionary<String,String>();varformParams=newDictionary<String,String>();varfileParams=newDictionary<String,FileParameter>();StringpostBody=null;// make the HTTP requestIRestResponseresponse=(IRestResponse)ApiClient.CallApi(path,Method.GET,queryParams,postBody,headerParams,formParams,fileParams,authSettings);if(((int)response.StatusCode)>=400)thrownewApiException((int)response.StatusCode,"Error calling GetServer: "+response.Content,response.Content);elseif(((int)response.StatusCode)==0)thrownewApiException((int)response.StatusCode,"Error calling GetServer: "+response.ErrorMessage,response.ErrorMessage);return(Server)ApiClient.Deserialize(response.Content,typeof(Server),response.Headers);}
to
publicvoidGetServer(int?serverId,Action<ApiException,Server>callback){// verify the required parameter 'serverId' is setif(serverId==null)thrownewApiException(400,"Missing required parameter 'serverId' when calling GetServer");varpath="/servers/{server_id}";path=path.Replace("{format}","json");path=path.Replace("{"+"server_id"+"}",ApiClient.ParameterToString(serverId));varqueryParams=newDictionary<String,String>();varheaderParams=newDictionary<String,String>();varformParams=newDictionary<String,String>();varfileParams=newDictionary<String,FileParameter>();StringpostBody=null;// make the HTTP requestApiClient.CallApiAsync(path,Method.GET,queryParams,postBody,headerParams,formParams,fileParams,authSettings,(response)=>{ApiExceptionexception=null;if(((int)response.StatusCode)>=400)exception=newApiException((int)response.StatusCode,"Error calling GetServer: "+response.Content,response.Content);elseif(((int)response.StatusCode)==0)exception=newApiException((int)response.StatusCode,"Error calling GetServer: "+response.ErrorMessage,response.ErrorMessage);callback(exception,(Server)ApiClient.Deserialize(response.Content,typeof(Server),response.Headers));});}
The text was updated successfully, but these errors were encountered:
jonaslagoni
changed the title
[Csharp/DotNet client] Feature request - option to use asynchronous callbacks with Csharp DotNet client
[Csharp/DotNet client] Feature request - option to use asynchronous callbacks
Aug 9, 2020
Description
Add an option which allows to generate asynchronous API calls instead of the current synchronous calls for the csharp/dotnet client. I haven't been able to find any options which enables this feature, if it exists somewhere please let me know 😄
Swagger declaration file content or url
Example declaration file used in suggestion to how to implement it.
Related issues/PRs
Tried keywords such as .net, dotnet, csharp, callbacks, asynchronous, async
Suggest a fix/enhancement
This is what I currently change on the generated code and what could be generated alongside/in replacement.
Add a method called
CallApiAsync
to the generated ApiClientChange the generated client interface form from
to
Change the generated client methods from:
to
The text was updated successfully, but these errors were encountered: