OpenAPITools / OpenAPITools/openapi-generator

[JavaScript] Parameters naming in functions, documentation and file name is wrong

Open
#1,435 22 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: JavaScript/Node.js Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

Code generated creates some parameters as inline objects, some with bad names like NULLUNIQUENAME, and with parameter names in functions called "opts" instead of their proper name.

openapi-generator version

openapi-generator-cli-3.3.3-20181113.090410-41.jar

OpenAPI declaration file content or url

Not complete, but you get the point:

  /companies/{companyId}/oath_groto/integration:

    parameters:
      - $ref: '#/parameters/companyId'

    post:
      x-swagger-router-controller: api.companies
      operationId: addCompanyOathGrotoIntegration
      summary: Adds the Oath Groto integration for a company account.
      description: Adds the Oath Groto integration for a company account.
      parameters:
        - $ref: '#/parameters/oathIntegrationSettings'
      responses:
        '201':
          description: An Integration object
          schema:
            $ref: '#/definitions/Integration'
        '404':
          $ref: '#/responses/EntityDoesNotExistWithError'
        '400':
          $ref: '#/responses/BadRequest'
        '403':
          $ref: '#/responses/Forbidden'
        '500':
          $ref: '#/responses/InternalServerError'
        default:
          $ref: '#/responses/TotallyUnexpectedResponse'

  oathIntegrationSettings:
    name: oathIntegrationSettings
    in: body
    required: true
    description: Settings of the Oath integration.
    schema:
      type: object
      required:
        - oathAuthCode
      properties:
        oathAuthCode:
          description: The Oath auth code to use for the integration, as returned from Oath OAuth.
          type: string

--

Now, diffing, compared to swagger-codegen-cli-2.4.0-20181113.142213-347.jar (which I treat as the reference implementation) shows:

DefaultApi.md

 <a name="addCompanyOathGrotoIntegration"></a>
 # **addCompanyOathGrotoIntegration**
-> Integration addCompanyOathGrotoIntegration(companyId, oathIntegrationSettings)
+> Integration addCompanyOathGrotoIntegration(companyId, opts)
 
... more stuff

-var oathIntegrationSettings = new Fizzle.OathIntegrationSettings(); // OathIntegrationSettings | Settings of the Oath integration.
-
-apiInstance.addCompanyOathGrotoIntegration(companyId, oathIntegrationSettings).then(function(data) {
+var opts = {
+  'inlineObject3': new Fizzle.InlineObject3() // InlineObject3 | 
+};
+apiInstance.addCompanyOathGrotoIntegration(companyId, opts).then(function(data) {

DefaultApi.js

@@ -234,22 +232,19 @@
      * Adds the Oath Groto integration for a company account.
      * Adds the Oath Groto integration for a company account.
      * @param {Number} companyId A company identifier
-     * @param {module:model/OathIntegrationSettings} oathIntegrationSettings Settings of the Oath integration.
+     * @param {Object} opts Optional parameters
+     * @param {module:model/InlineObject3} opts.inlineObject3 
      * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:model/Integration} and HTTP response
      */
-    this.addCompanyOathGrotoIntegrationWithHttpInfo = function(companyId, oathIntegrationSettings) {
-      var postBody = oathIntegrationSettings;
+    this.addCompanyOathGrotoIntegrationWithHttpInfo = function(companyId, opts) {
+      opts = opts || {};
+      var postBody = opts['inlineObject3'];
 
       // verify the required parameter 'companyId' is set
       if (companyId === undefined || companyId === null) {
         throw new Error("Missing the required parameter 'companyId' when calling addCompanyOathGrotoIntegration");
       }
 
-      // verify the required parameter 'oathIntegrationSettings' is set
-      if (oathIntegrationSettings === undefined || oathIntegrationSettings === null) {
-        throw new Error("Missing the required parameter 'oathIntegrationSettings' when calling addCompanyOathGrotoIntegration");
-      }
-
 
       var pathParams = {
         'companyId': companyId
@@ -279,11 +274,12 @@
      * Adds the Oath Groto integration for a company account.
      * Adds the Oath Groto integration for a company account.
      * @param {Number} companyId A company identifier
-     * @param {module:model/OathIntegrationSettings} oathIntegrationSettings Settings of the Oath integration.
+     * @param {Object} opts Optional parameters
+     * @param {module:model/InlineObject3} opts.inlineObject3 
      * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/Integration}
      */
-    this.addCompanyOathGrotoIntegration = function(companyId, oathIntegrationSettings) {
-      return this.addCompanyOathGrotoIntegrationWithHttpInfo(companyId, oathIntegrationSettings)
+    this.addCompanyOathGrotoIntegration = function(companyId, opts) {
+      return this.addCompanyOathGrotoIntegrationWithHttpInfo(companyId, opts)
         .then(function(response_and_data) {
           return response_and_data.data;
         });

The files /model/OathIntegrationSettings.js and /model/OathIntegrationSettings.spec.js have been deleted. Instead, you have many InlineObject1.spec.js and InlineObject1.js files.

You can clearly see above that instead of:

this.addCompanyOathGrotoIntegration = function(companyId, oathIntegrationSettings) {

you now have:

this.addCompanyOathGrotoIntegration = function(companyId, opts) {

Also, there are several NULLUNIQUENAME.spec.js and NULLUNIQUENAM.js files which were generated by the inline part of the array in this YAML:
(i.e. the element inside the items key)

  oathGrotoAssetsForLarping:
    name: oathGrotoAssetsForLarping
    in: body
    required: true
    description: List of Oath Groto assets for larping
    schema:
      type: array
      items:
        type: object
        required:
          - integrationId
          - managerAccountId
        properties:
          integrationId:
            description: An Integration identifier
            type: integer
            format: int64
          managerAccountId:
            description: Id of Oath Groto manager account
            type: string
          clientAccountId:
            description: Id of Oath Groto client account
            type: string
Command line used for generation

java -jar ~/Downloads/openapi-generator-cli-3.3.3-20181113.090410-41.jar generate -i ../fizzle.yaml -l javascript --additional-properties usePromises=true -o ./javascript/

Steps to reproduce

Generate a JavaScript client for any Swagger file that has parameters.

Related issues/PRs

None that I know of.

Suggest a fix/enhancement

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

Reproduce the issue with the provided openapi-generator CLI command and an OpenAPI or Swagger file containing named body parameters and inline array objects. Compare the generated DefaultApi.js, DefaultApi.md, and model files with the reference output; done means preserving parameter names, avoiding opts and NULLUNIQUENAME, and retaining named model files and specs.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, javascript
Domain
devtools, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.