cyclosproject / ng-openapi-gen

An OpenAPI 3.0 codegen for Angular
MIT License
397 stars 132 forks source link

Ignore headers #194

Closed scurk1415 closed 1 year ago

scurk1415 commented 2 years ago

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

luisfpg commented 2 years ago

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.

Rasmus715 commented 1 year ago

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

luisfpg commented 1 year ago

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