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
  • Issues
  • #6844
Closed
Open
Issue created Jul 02, 2020 by Administrator@rootContributor

[REQ] Support parameter objects for apis and clients.

Created by: yuatpocketgems

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

There are 2 major issues blocking us from adopting openapi-generator.

  1. For languages that lack named parameters support, the generated SDKs are prune to errors during API upgrades.

    Consider a case where we decided to make some changes to our pre-existing API. Previously:

    class DefaultApi {
      myAPI (paramBoo, paramFoo, opts) { }
    }

    now becomes

    class DefaultApi {
      myAPI (paramBar, paramFoo, opts) { }
    }

    The code works "fine", as parameter paramBoo and paramBar have the same semantics, thus pass validations. But they actually have different meanings and may cause subtle errors in the backend. Users of the SDK will most likely fail to catch one or two calls like this and only realize problems down the line.

  2. Generated SDK clients don't support session parameters. For example, my backend may require a region field from all my client's requests, which stays constant for each user / session. The current SDKs (cpp and js at least) require these fields to be passed into each operation.

    class DefaultApi {
       myAPI (region, paramBoo, opts) { }
       myAPI2 (region, paramFoo, opts) { }
       myAPI3 (region, paramZoo, opts) { }
    }

    This is tedious for devs and also creates opportunities for human error.

Describe the solution you'd like

  1. I would like an option to put all api parameters into the opts field. For example, I generate my SDK with

    docker run --rm -v ${PWD}:/local 
        openapitools/openapi-generator-cli generate \
        -i /local/spec.json \
        -g javascript \
        --additional-properties useParameterObjects=true \
        -o /local/js-sdk

    The Api.js in the generated SDK will have something like:

    class DefaultApi {
       myAPI (opts) { }
    }

    and I call the api with

    myClient.myApi({ paramBar: 'xyz', paramFoo: 'abc' })
    // myClient.myApi({ paramBoo: 'xyz', paramFoo: 'abc' }) // Throws
  2. I would like a parameter added to SDK clients to support default parameters for all requests, so I could use the SDK like below:

    const myClient = new DefaultApi(new APIClient(), { region: 'NA' })
    myClient.myAPI({ paramFoo: 123 })

    or for one-offs do

    myClient.myAPI({ paramFoo: 123, region: 'EU' })

But if we add support for 1 above, support for 2 can be implemented by callers too. The solution would just be less nice.

Describe alternatives you've considered

Obviously, I can achieve these with customizations / providing my own templates, but these features seem to be useful in general.

Assignee
Assign to
Time tracking