OpenAPITools / OpenAPITools/openapi-generator

[REQ][typescript-axios] Disable factory when not needed

Open
#14,952 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Is your feature request related to a problem? Please describe.

Code coverage on generated api client is failing because of unused factory functions.

Describe the solution you'd like

To have a parameter which switches factory functions through mustache

Describe alternatives you've considered

Modifying the generated api.ts file post generation. Currently using a local templates but seems like a feature others can use.

Additional context

The default should be true to avoid any backwards compatibility issues
modules/openapi-generator/src/main/resources/typescript-axios/apiInner.mustache

{{withFactory}}
/**
 * {{classname}} - factory interface{{#description}}
 * {{&description}}{{/description}}
 * @export
 */
export const {{classname}}Factory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) {
    const localVarFp = {{classname}}Fp(configuration)
    return {
    {{#operation}}
        /**
         * {{&notes}}
         {{#summary}}
         * @summary {{&summary}}
         {{/summary}}
        {{#useSingleRequestParameter}}
         {{#allParams.0}}
         * @param {{=<% %>=}}{<%& classname %><%& operationIdCamelCase %>Request}<%={{ }}=%> requestParameters Request parameters.
         {{/allParams.0}}
        {{/useSingleRequestParameter}}
        {{^useSingleRequestParameter}}
         {{#allParams}}
         * @param {{=<% %>=}}{<%&dataType%>}<%={{ }}=%> {{^required}}[{{/required}}{{paramName}}{{^required}}]{{/required}} {{description}}
         {{/allParams}}
        {{/useSingleRequestParameter}}
         * @param {*} [options] Override http request option.{{#isDeprecated}}
         * @deprecated{{/isDeprecated}}
         * @throws {RequiredError}
         */
        {{#useSingleRequestParameter}}
        {{nickname}}({{#allParams.0}}requestParameters: {{classname}}{{operationIdCamelCase}}Request{{^hasRequiredParams}} = {}{{/hasRequiredParams}}, {{/allParams.0}}options?: AxiosRequestConfig): AxiosPromise<{{{returnType}}}{{^returnType}}void{{/returnType}}> {
            return localVarFp.{{nickname}}({{#allParams.0}}{{#allParams}}requestParameters.{{paramName}}, {{/allParams}}{{/allParams.0}}options).then((request) => request(axios, basePath));
        },
        {{/useSingleRequestParameter}}
        {{^useSingleRequestParameter}}
        {{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}options?: any): AxiosPromise<{{{returnType}}}{{^returnType}}void{{/returnType}}> {
            return localVarFp.{{nickname}}({{#allParams}}{{paramName}}, {{/allParams}}options).then((request) => request(axios, basePath));
        },
        {{/useSingleRequestParameter}}
    {{/operation}}
    };
};

{{/withFactory}}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with modules/openapi-generator/src/main/resources/typescript-axios/apiInner.mustache and inspect how existing Mustache parameters control generated sections. Add the requested parameter around the factory output, with a default of true for compatibility. Done means the factory can be disabled during generation without removing other generated client code.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, typescript
Domain
tooling
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.