openapistack / openapi-client-axios

JavaScript client library for consuming OpenAPI-enabled APIs with axios
https://openapistack.co
MIT License
550 stars 67 forks source link

Starting with 4.2.0, typegen does not generate parameters. #92

Closed mat813 closed 2 years ago

mat813 commented 2 years ago

Given this openapi definition:

{
  "components": {
    "parameters": {
      "organisationId": {
        "description": "Id de l'organisation",
        "in": "path",
        "name": "organisationId",
        "required": true,
        "schema": {
          "format": "int64",
          "type": "integer"
        }
      }
    }
  },
  "info": {
    "description": "API",
    "title": "API",
    "version": "1.3.5"
  },
  "openapi": "3.0.3",
  "paths": {
    "/organisations/{organisationId}": {
      "delete": {
        "description": "Suppression d'une organisation",
        "operationId": "organisations.destroy",
        "parameters": [
          {
            "description": "Id de l'organisation",
            "in": "path",
            "name": "organisationId",
            "required": true,
            "schema": {
              "format": "int64",
              "type": "integer"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Supprimé"
          }
        }
      }
    }
  }
}

When using openapi-client-axios-typegen@3.14.1 will generate :+1:

export interface OperationMethods {
  /**
   * organisations.destroy - Suppression d'une organisation
   */
  'organisationsDestroy'(
    parameters?: Parameters<Paths.OrganisationsDestroy.PathParameters> | null,
    data?: any,
    config?: AxiosRequestConfig
  ): OperationResponse<any>;
}

export interface PathsDictionary {
  ['/organisations/{organisationId}']: {
    /**
     * organisations.destroy - Suppression d'une organisation
     */
    'delete'(
      parameters?: Parameters<Paths.OrganisationsDestroy.PathParameters> | null,
      data?: any,
      config?: AxiosRequestConfig
    ): OperationResponse<any>;
  };
}

But starting with 4.2.0, it generates parameters that are not typed any more:

export interface OperationMethods {
  /**
   * organisations.destroy - Suppression d'une organisation
   */
  'organisationsDestroy'(
    parameters?: Parameters<UnknownParamsObject> | null,
    data?: any,
    config?: AxiosRequestConfig
  ): OperationResponse<any>;
}

export interface PathsDictionary {
  ['/organisations/{organisationId}']: {
    /**
     * organisations.destroy - Suppression d'une organisation
     */
    'delete'(
      parameters?: Parameters<UnknownParamsObject> | null,
      data?: any,
      config?: AxiosRequestConfig
    ): OperationResponse<any>;
  };
}

Though, it still generates the correct Components and Paths namespaces though.

anttiviljami commented 2 years ago

A guess, but could it be the . in operationId? If you remove it do the params get generated correctly?

mat813 commented 2 years ago

Mmmmm, right, if I remove the . in the operationId it fixes the issue. The thing is, I can't remove those, I use them on the server side with express-openapi-validator to map the operations to methods.

I forgot to say that I use a transform operation with typegen, in a transformApi.js file:

module.exports = {
  camelize: (operationId) => {
    // An example where operationId follows a pattern of
    // {controller}.{action}
    return operationId.replace(/[_.-](\w|$)/g, function (_, x) {
      return x.toUpperCase();
    });
  },
};

and then run typegen -t transformApi.camelize test.json to get OperationMethods without the dot in them.

anttiviljami commented 2 years ago

Yep. Seems like a bug in the typegen package. PRs accepted!

dkreuer commented 2 years ago

From what I could debug in my case (having the same issue), the DtsGenerator does not provide the necessary exported types. At least I could not find things like { schemaRef:#/paths/${normalizedOperationId}/pathParameters} in the types.