swagger-typescript-api icon indicating copy to clipboard operation
swagger-typescript-api copied to clipboard

Strange method name

Open RoXuS opened this issue 4 years ago • 14 comments
trafficstars

Several of our methods has a number after there name:

  searchConsumption1 = (data: { filters?: CreditOperationFilters; pageable?: Pageable }, params?: RequestParams) =>

Ok we have this method in another class but not in the same class. We generate API with modular.

RoXuS avatar Feb 12 '21 15:02 RoXuS

Hello @RoXuS
Can you share part of schema where contains original searchConsumption and "duplicate" searchConsumption ?
And which version of swagger schema are you using ?
Just currently I'm not see a problem with local version.

js2me avatar Feb 12 '21 15:02 js2me

@RoXuS did you see this message on console output ? Module "{moduleName}" already have method "{methodName}()" ?

js2me avatar Feb 12 '21 15:02 js2me

No we don't have this log. Our schema:

      "post": {
        "tags": [
          "credit-operation-api"
        ],
        "operationId": "searchConsumption",
        "parameters": [
          {
            "name": "organizationId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int64"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "filters": {
                    "$ref": "#/components/schemas/CreditOperationFilters"
                  },
                  "pageable": {
                    "$ref": "#/components/schemas/Pageable"
                  }
                }
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/hal+json": {
                "schema": {
                  "$ref": "#/components/schemas/CreditPageCreditConsumptionDto"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request"
          }
        }
      }
    },

RoXuS avatar Feb 12 '21 17:02 RoXuS

@RoXuS I hope that this problem was fixed in 5.0.0 :)
If not please reopen issue or ping me here

js2me avatar Feb 12 '21 23:02 js2me

hey,

with 5.0.0, the error remains, for example

  /**
   * No description
   *
   * @tags credit-operation-api
   * @name SearchConsumption1
   * @request POST:/me/organization/credits/search-consumption
   * @secure
   */
  searchConsumption1 = (
    data: CreditOperationFilters,
    query?: { page?: number; size?: number; sort?: string[] },
    params: RequestParams = {},
  ) => ...

For info our two different schema:

"/organizations/{organizationId}/credits/search-consumption": {
    "post": {
      "tags": [
        "credit-operation-api"
      ],
      "operationId": "searchConsumption",
      "parameters": [
        {
          "name": "organizationId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "integer",
            "format": "int64"
          }
        },
        {
          "name": "page",
          "in": "query",
          "description": "Zero-based page index (0..N)",
          "schema": {
            "type": "integer",
            "default": 0
          }
        },
        {
          "name": "size",
          "in": "query",
          "description": "The size of the page to be returned",
          "schema": {
            "type": "integer",
            "default": 20
          }
        },
        {
          "name": "sort",
          "in": "query",
          "description": "Sorting criteria in the format: property(,asc|desc). Default sort order is ascending. Multiple sort criteria are supported.",
          "schema": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      ],
      "requestBody": {
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/CreditOperationFilters"
            }
          }
        },
        "required": true
      },
      "responses": {
        "200": {
          "description": "OK",
          "content": {
            "application/hal+json": {
              "schema": {
                "$ref": "#/components/schemas/CreditPageCreditConsumptionDto"
              }
            }
          }
        },
        "400": {
          "description": "Bad Request"
        }
      }
    }
  }
  ```
  
  ```
  "/me/organization/credits/search-consumption": {
    "post": {
      "tags": [
        "credit-operation-api"
      ],
      "operationId": "searchConsumption_1",
      "parameters": [
        {
          "name": "page",
          "in": "query",
          "description": "Zero-based page index (0..N)",
          "schema": {
            "type": "integer",
            "default": 0
          }
        },
        {
          "name": "size",
          "in": "query",
          "description": "The size of the page to be returned",
          "schema": {
            "type": "integer",
            "default": 20
          }
        },
        {
          "name": "sort",
          "in": "query",
          "description": "Sorting criteria in the format: property(,asc|desc). Default sort order is ascending. Multiple sort criteria are supported.",
          "schema": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      ],
      "requestBody": {
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/CreditOperationFilters"
            }
          }
        },
        "required": true
      },
      "responses": {
        "200": {
          "description": "OK",
          "content": {
            "application/hal+json": {
              "schema": {
                "$ref": "#/components/schemas/CreditPageCreditConsumptionDto"
              }
            }
          }
        },
        "400": {
          "description": "Bad Request"
        }
      }
    }
  },
  ```
  
  Thx for your 5.0.0!

RoXuS avatar Feb 13 '21 10:02 RoXuS

other info image

seems to keep increment through the files.

RoXuS avatar Feb 13 '21 10:02 RoXuS

Hi @RoXuS !
Can you message all operations ids ("operationId" field) of this execureSearch operations ?

js2me avatar Feb 14 '21 18:02 js2me

Just I think ending number it is a part of "operationId" field
like searchConsumption_1

js2me avatar Feb 14 '21 20:02 js2me

Yeah we have

"/me/organization/credits/search-consumption": {
      "post": {
        "tags": [
          "credit-operation-api"
        ],
        "operationId": "searchConsumption_1",
        "parameters": [
          {
          ...

For example.

RoXuS avatar Feb 15 '21 08:02 RoXuS

So the issue is on our swagger generator ?

RoXuS avatar Feb 15 '21 08:02 RoXuS

@RoXuS If you don't see this message
image It means that the number endings goes from "operationId" field

I'll try to fix that at next release.
Definetely swagger-typescript-api codegenerator should crop _1, _2, _{n} in "operationId"

Currently, as quick solution you can customize route name with hook onCreateRouteName() (version 5.1.0)

js2me avatar Feb 15 '21 09:02 js2me

We will wait your new version, np.

Thx!!

RoXuS avatar Feb 15 '21 15:02 RoXuS

Here is my temporary solution as @js2me suggested

onCreateRouteName: (nameInfo, rawInfo) => {
  nameInfo.original = nameInfo.original.replace(/\d+$/, '')
  nameInfo.usage = nameInfo.usage.replace(/\d+$/, '')
},

amankkg avatar Apr 04 '21 12:04 amankkg