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
I want to have the option of asynchronously call the api with the csharp generator. I am unable to use the generator csharp-netcore which has this feature.
Describe the solution you'd like
With the following document
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
This is what I changed in the old 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));});}
Describe alternatives you've considered
Tried to use the charp-netcore generator which has a version of this feature but it has to be compatible with .NET Framework 4.5. Tried to use the original swagger-codegen library which also does not have this feature.
The text was updated successfully, but these errors were encountered:
Gonna reopen, I could really use the Action callback variant instead of using Tasks. I am restricted in using all features of System.Threading directly in my code.
Is your feature request related to a problem? Please describe.
This is a dublicate issue from swagger-api/swagger-codegen#10424
I want to have the option of asynchronously call the api with the
csharp
generator. I am unable to use the generatorcsharp-netcore
which has this feature.Describe the solution you'd like
With the following document
This is what I changed in the old 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
Describe alternatives you've considered
Tried to use the charp-netcore generator which has a version of this feature but it has to be compatible with .NET Framework 4.5. Tried to use the original swagger-codegen library which also does not have this feature.
The text was updated successfully, but these errors were encountered: