ng-openapi-gen icon indicating copy to clipboard operation
ng-openapi-gen copied to clipboard

Ignore headers

Open scurk1415 opened this issue 3 years ago • 1 comments

Is it possible to set headers which i want to be ignored by the generator? The problem is that most of my requests have the Accept-Language header (and some others) and I set these headers with an interceptor. The code generator automatically adds them as parameters in the service method which forces me as the developer to fetch the data from other services, for basically every request endpoint.

Is there a way to ignore these parameters? If not then consider this issue as a feature request

scurk1415 avatar Jan 04 '22 12:01 scurk1415

Sorry, but I don't quite get... "The code generator automatically adds them as parameters in the service method" Actually, the headers appended by RequestBuilder are Accept (according to the content in the specification) and Content-Type when it posts some body.

luisfpg avatar Jan 20 '22 16:01 luisfpg

What OP wants is to remove some specific parameters from being added to the autogenerated services. Let's say we have a Swagger schema with the required Accept-Language header in it. If we run the command to generate services, we'll get something like this:

  createEntityEndpoint$Response(params: { id: string; 'Accept-Language': string; context?: HttpContext }): Observable<StrictHttpResponse<void>> {
    const rb = new RequestBuilder(this.rootUrl, MyApiService.CreateEntityEndpointPath, 'post');
    if (params) {
      rb.path('id', params.id, {});
      rb.header('Accept-Language', params['Accept-Language'], {});
    }
// return http.request...

What @scurk1415 (and I) want, is to ignore the generation of the Accept-Language parameter in this case, because the logic that sets this parameter resides in another place.

Expected result:

  createEntityEndpoint$Response(params: { id: string; context?: HttpContext }): Observable<StrictHttpResponse<void>> {
    const rb = new RequestBuilder(this.rootUrl, MyApiService.CreateEntityEndpointPath, 'post');
    if (params) {
      rb.path('id', params.id, {});
    }
// return http.request...

UPD: This can be achieved by executing the command with --exclude-parameters parameter. e.g. --exclude-parameters Accept-Language will do the trick

Rasmus715 avatar Sep 25 '23 12:09 Rasmus715

As @Rasmus715 noted, there's already a config option to ignore parameters.

luisfpg avatar Oct 12 '23 01:10 luisfpg