Skip to content

[BUG] Nodejs error "Express Server Failure" - OpenAPIRequestValidator is not a constructor #13245

Closed
@jcalmeida

Description

@jcalmeida
Description

I generated the node project based on a simple openapi.yaml and went to call npm start on its main folder and got this error:
{"level":"error","message":"Express Server failure","service":"user-service","timestamp":"2022-08-21T20:32:51.305Z"}
error: Express Server failure {"service":"user-service","timestamp":"2022-08-21T20:32:51.305Z"}
{"level":"error","service":"user-service","timestamp":"2022-08-21T20:32:51.307Z"}
error: undefined {"service":"user-service","timestamp":"2022-08-21T20:32:51.307Z"}

I figured out the issue was on expressServer.js and specifically on OpenApiRequestValidator. If remove these lines the server launches:

    new OpenApiValidator({
      apiSpec: this.openApiPath,
      operationHandlers: path.join(__dirname),
      fileUploader: { dest: config.FILE_UPLOAD_PATH },
    }).install(this.app)
      .catch(e => console.log(e))
      .then(() => {
        // eslint-disable-next-line no-unused-vars
        this.app.use((err, req, res, next) => {
          // format errors
          res.status(err.status || 500).json({
            message: err.message || err,
            errors: err.errors || '',
          });
        });

I debugged it and the error was like "OpenAPIRequestValidator is not a constructor". I think it has something to do with my node version.

I can't make the api work, hope you guys can help me.

Generation CLI:

openapi-generator-cli generate -g nodejs-express-server -o api -i reference/intake.yaml
openapi-generator version

openapi-generator version: 6.0.1
nodejs version: 18.7.0

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  title: intake
  version: "1.0"
servers:
- url: http://localhost:3000
paths:
  /contents:
    post:
      operationId: post-contents
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Contents'
      responses:
        "201":
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Contents'
          description: Created
        "400":
          description: Bad Request
        "500":
          description: Internal Server Error
      summary: ""
      x-eov-operation-handler: controllers/DefaultController
components:
  schemas:
    Contents:
      description: XXXXX
      example:
        id: 7dcb947e-201c-11ed-861d-0242ac120002
        url: https://www.github.com
      properties:
        id:
          description: xxxxxx
          example: 7dcb947e-201c-11ed-861d-0242ac120002
          format: uuid
          readOnly: true
          type: string
        url:
          description: xxxxx
          example: https://www.github.com
          format: uri
          type: string
      required:
      - url
      title: contents
      type: object
      x-stoplight:
        id: bcs35jcsjdckh
x-stoplight:
  id: 8uazc64vxu3i1
Generation Details

Simply run this:
openapi-generator-cli generate -g nodejs-express-server -o api -i reference/intake.yaml

Steps to reproduce

After generating, cd into api folder and run ´npm start´ or ´node index.js´

Related issues/PRs

Could be related to this? kogosoftwarellc/open-api#443

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions