Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Merge requests
  • !6288

[typescript-axios] Implement useSingleRequestParameter option

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/codeserk/feature/5549-added-named-params-to-typescript-axios into master May 13, 2020
  • Overview 0
  • Commits 7
  • Pipelines 0
  • Changes 24

Created by: codeserk

This is a follow-up story that completes this PR proposed before. This PR adds a new parameter that has default value to false to maintain retro-compatibility.

Problem

The current implementation expands all the parameters in the API methods:

        /**
         * 
         * @summary Logs user into the system
         * @param {string} username The user name for login
         * @param {string} password The password for login in clear text
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        loginUser(username: string, password: string, options?: any): AxiosPromise<string> {

This is especially problematic when adding more fields to existing endpoints, since the order of the parameters might change. This leads to a breaking changes in the generated client, even if the API introduced a non-breaking change (a new optional parameter).

Proposal

Adding a new parameter useSingleRequestParameter to combine all the request parameters in a single object. This is not a new solution, it has been implemented in other generators and there is already a proposed solution using this mechanism. This new option is disabled by default, to keep compatibility with previous versions

Interfaces for the requests

/**
 * Request parameters for loginUser operation in UserApi.
 * @export
 * @interface UserApiLoginUserRequest
 */
export interface UserApiLoginUserRequest {
    /**
     * The user name for login
     * @type {string}
     * @memberof UserApiLoginUser
     */
    readonly username: string

    /**
     * The password for login in clear text
     * @type {string}
     * @memberof UserApiLoginUser
     */
    readonly password: string
}

Changes in the methods to use the request interfaces

    /**
     * 
     * @summary Logs user into the system
     * @param {UserApiLoginUserRequest} requestParameters Request parameters.
     * @param {*} [options] Override http request option.
     * @throws {RequiredError}
     * @memberof UserApi
     */
    public loginUser(requestParameters: UserApiLoginUserRequest, options?: any) {
        return UserApiFp(this.configuration).loginUser(requestParameters.username, requestParameters.password, options).then((request) => request(this.axios, this.basePath));
    }

Review

I've split the changes in different commits to ease the review process. The last commit contains the highest number of changes: I've regenerated all the samples.

@macjohnny I believe you were the reviewer of the previous PR and asked for some changes in the previous proposal. Please let me know if there's something missing (I'm pretty new with mustache and this is my first contribution to this project so I might have messed up something :D)

@TiFu @taxpon @sebastianhaas @kenisteward @Vrolijkx @macjohnny @nicokoenig @topce @akehir @petejohansonxo @amakhrov

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/codeserk/feature/5549-added-named-params-to-typescript-axios