Skip to content

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

@coloboxp

Description

@coloboxp

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
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions