openapi-generator: [JavaScript] Parameters naming in functions, documentation and file name is wrong

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

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Comments: 22 (9 by maintainers)

Most upvoted comments

Hi guys, any update on this issue? I’m getting a similar issue when generating the SDK for javascript:

import ApiClient from '../ApiClient';

class NULLUNIQUENAME {
    /**
     * Constructs a new <code>NULLUNIQUENAME</code>.
     * @alias module:model/NULLUNIQUENAME
     */
    constructor() { 
        
        NULLUNIQUENAME.initialize(this);
    }

    /**
     * Initializes the fields of this object.
     * This method is used by the constructors of any subclasses, in order to implement multiple inheritance (mix-ins).
     * Only for internal use.
     */
    static initialize(obj) { 
    }

    /**
     * Constructs a <code>NULLUNIQUENAME</code> from a plain JavaScript object, optionally creating a new instance.
     * Copies all relevant properties from <code>data</code> to <code>obj</code> if supplied or a new instance if not.
     * @param {Object} data The plain JavaScript object bearing properties of interest.
     * @param {module:model/NULLUNIQUENAME} obj Optional instance to populate.
     * @return {module:model/NULLUNIQUENAME} The populated <code>NULLUNIQUENAME</code> instance.
     */
    static constructFromObject(data, obj) {
        if (data) {
            obj = obj || new NULLUNIQUENAME();

            if (data.hasOwnProperty('type')) {
                obj['type'] = ApiClient.convertToType(data['type'], Object);
            }
        }
        return obj;
    }
}

/**
 * @member {Object} type
 */
NULLUNIQUENAME.prototype['type'] = undefined;