cyclosproject / ng-openapi-gen

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

Duplicated generated parameters when the same name is in both shared and specific parameters #297

Closed alex-aveva closed 11 months ago

alex-aveva commented 11 months ago

Here's my openapi: 3.0.1 JSON (it's rather big so only small portion shown below)

    "/api/account/{accountId}/identity/v1/Clients/{id}": {
      "get": {...},
      "put": {
        "tags": ["..."],
        "summary": "...",
        "description": "...",
        "operationId": "...",
        "parameters": [
          {
            "name": "accountId",
            "in": "path",
            "required": true,
            "style": "simple",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "style": "simple",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {...},
        "responses": {...}
      },
      "parameters": [
        {
          "name": "accountId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ]
    },

Client generated:

/* tslint:disable */
/* eslint-disable */
import { HttpClient, HttpContext, HttpResponse } from '@angular/common/http';
import { Observable } from 'rxjs';
import { filter, map } from 'rxjs/operators';
import { StrictHttpResponse } from '../../strict-http-response';
import { RequestBuilder } from '../../request-builder';

import { ClientCredentialClientResponse } from '../../models/client-credential-client-response';
import { UpdateClientCredentialClientRequest } from '../../models/update-client-credential-client-request';

export interface UpdateClientCredentialClient$Params {
  accountId: string;
  id: string;
  accountId: string;
  id: string;
  body: UpdateClientCredentialClientRequest;
}

export function updateClientCredentialClient(
  http: HttpClient,
  rootUrl: string,
  params: UpdateClientCredentialClient$Params,
  context?: HttpContext,
): Observable<StrictHttpResponse<ClientCredentialClientResponse>> {
  const rb = new RequestBuilder(rootUrl, updateClientCredentialClient.PATH, 'put');
  if (params) {
    rb.path('accountId', params.accountId, {});
    rb.path('id', params.id, {});
    rb.path('accountId', params.accountId, { style: 'simple' });
    rb.path('id', params.id, { style: 'simple' });
    rb.body(params.body, 'application/json');
  }

  return http.request(rb.build({ responseType: 'json', accept: 'application/json', context })).pipe(
    filter((r: any): r is HttpResponse<any> => r instanceof HttpResponse),
    map((r: HttpResponse<any>) => {
      return r as StrictHttpResponse<ClientCredentialClientResponse>;
    }),
  );
}

updateClientCredentialClient.PATH = '/api/account/{accountId}/identity/v1/Clients/{id}';

Notice that accountId and id params duplicated, I suspect this is due to presence of parameters under root entry /api/account/{accountId}/identity/v1/Clients/{id} and under get and put as well.

Other tools I've tried were able to deal with this case:

I trust provided JSON schema is correct, according to https://swagger.io/docs/specification/describing-parameters/#common-for-path

Specific path-level parameters can be overridden on the operation level, but cannot be removed. Since params in above case have same name they should not be stacked by overrided instead.