OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.85k stars 6.59k forks source link

[BUG] [nodejs-express-server] Function with object as parameter #8140

Open koldou98 opened 3 years ago

koldou98 commented 3 years ago

Bug Report Checklist

Description

When I create the server with nodejs express server, in the tagNameServices creates the services properly, but when the requested parameter is an object it generates it in the following way:

const foo = ({ foo }) => new Promise(
  async (resolve, reject) => {
    try {
      resolve(Service.successResponse({
        foo,
      }));
    } catch (e) {
      reject(Service.rejectResponse(
        e.message || 'Invalid input',
        e.status || 405,
      ));
    }
  },
);

The problem is that {tag} is that the parameter is always null. I would like the generator to create a variable without the object brackets.

openapi-generator version

4.3.1

OpenAPI declaration file content or url
openapi: 3.0.1
info:
  title: Issue
  version: 1.0.0
servers:
  - url: http://localhost:4000/
tags:
  - name: tag

paths:
  /tag:
    post:
      operationId: foo
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/foo'
        required: true
      responses:
        "200":
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/responsefoo'
          description: foo
      tags:
        - tag
components:
  schemas:
    foo:
      additionalProperties: false
      properties:
        test:
          description: |
            test
          maxLength: 12
          pattern: \s*
          type: string
      type: object
    responsefoo:
      additionalProperties: false
      example:
        msg: Se ha encendido el smartplug
      properties:
        msg:
          description: ok
          maxLength: 2
          minLength: 2
          pattern: '[\s]+'
          type: string
      readOnly: true
      type: object
Generation Details
openapi-generator-cli generate -i {path}/name.yaml -g nodejs-express-server -o {path}
Steps to reproduce

Open a terminal/cmd... and execute the following commnad

openapi-generator-cli generate -i {path}/name.yaml -g nodejs-express-server -o {path}

In Services/TagServices u will find the object as function parameter

Suggest a fix

Do not generate the parameter as an object

auto-labeler[bot] commented 3 years ago

👍 Thanks for opening this issue! 🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.