Skip to content
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

[REQ] csharp generators - Enable override of InterceptRequest and InterceptResponse #14609

Open
coloboxp opened this issue Feb 3, 2023 · 0 comments · May be fixed by #20015
Open

[REQ] csharp generators - Enable override of InterceptRequest and InterceptResponse #14609

coloboxp opened this issue Feb 3, 2023 · 0 comments · May be fixed by #20015

Comments

@coloboxp
Copy link

coloboxp commented Feb 3, 2023

Is your feature request related to a problem? Please describe.

To simplify message inteception, analysis or logging, and doing it in a centralized manner, would be ideal to be able to override the InterceptRequest and InterceptResponse methods on the ApiClient.cs generated code.

Describe the solution you'd like

Add the possibility to override the message interception

Describe alternatives you've considered

Using a public virtual method to do so; I've edited the mustache file to do it on my end, as the client is generated often and editing it each time is painful.

Additional context

This is what I ended up doing for now, better alternatives are welcome :)

Added the following on my mustache files

        /// <summary>
        /// Allows for extending request processing for <see cref="ApiClient"/> generated code.
        /// </summary>
        /// <param name="request">The RestSharp request object</param>
        //partial void InterceptRequest(RestRequest request);
        public virtual void InterceptRequest(RestRequest request)
        {
            
        }

        /// <summary>
        /// Allows for extending response processing for <see cref="ApiClient"/> generated code.
        /// </summary>
        /// <param name="request">The RestSharp request object</param>
        /// <param name="response">The RestSharp response object</param>
        public virtual void InterceptResponse(RestRequest request, RestResponse response)
        {

        }

Then on my inherited ApiClient, I can do :

    public class LocalApiClient : ApiClient
    {
        public override void InterceptRequest(RestRequest request)
        {
            // my custom analyitics here
        }

        public override void InterceptResponse(RestRequest request, RestResponse response)
        {
            // my custom analyitics here
        }
    }
@sbward sbward linked a pull request Nov 3, 2024 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant