swagger-codegen-generators icon indicating copy to clipboard operation
swagger-codegen-generators copied to clipboard

chore: reduce generated code by reusing the already existing classes (typescript-fetch)

Open onhate opened this issue 4 years ago • 0 comments

The Factory should be just a factory and not repeat the same implementation of the Api class

from

/**
 * UsersApi - factory interface
 * @export
 */
export const UsersApiFactory = function (configuration?: Configuration, fetch?: FetchAPI, basePath?: string) {
    return {
        /**
         * 
         * @param {CreateUserDto} body 
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        create(body: CreateUserDto, options?: any) {
            return UsersApiFp(configuration).create(body, options)(fetch, basePath);
        },
        /**
         * 
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        findAll(options?: any) {
            return UsersApiFp(configuration).findAll(options)(fetch, basePath);
        },
        /**
         * 
         * @param {string} id 
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        findOne(id: string, options?: any) {
            return UsersApiFp(configuration).findOne(id, options)(fetch, basePath);
        },
        /**
         * 
         * @param {string} id 
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        remove(id: string, options?: any) {
            return UsersApiFp(configuration).remove(id, options)(fetch, basePath);
        },
        /**
         * 
         * @param {UpdateUserDto} body 
         * @param {string} id 
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        update(body: UpdateUserDto, id: string, options?: any) {
            return UsersApiFp(configuration).update(body, id, options)(fetch, basePath);
        },
    };
};

to

/**
 * UsersApi - factory interface
 * @export
 */
export const UsersApiFactory = function (configuration?: Configuration, fetch?: FetchAPI, basePath?: string) {
    return new UsersApi(configuration, basePath, fetch);
};

onhate avatar Oct 20 '21 12:10 onhate