openapi-generator: [BUG] Default nodejs-express-server generation not runnable in default express: error: undefined {"service":"user-service"}

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What’s the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What’s the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

cannot run the default stub of nodejs-express-server. it creates a logger.js with winston and a user-service, which is not handled in the stub. the output of npm is

 error: undefined {"service":"user-service"}
 error: undefined {"service":"user-service"}

caused by created logger.js

const winston = require('winston');

const logger = winston.createLogger({
  level: 'info',
  format: winston.format.json(),
  defaultMeta: { service: 'user-service' },
  transports: [
    new winston.transports.File({ filename: 'error.log', level: 'error' }),
    new winston.transports.File({ filename: 'combined.log' }),
  ],
});

if (process.env.NODE_ENV !== 'production') {
  logger.add(new winston.transports.Console({ format: winston.format.simple() }));
}

module.exports = logger;
openapi-generator version

openapitools/openapi-generator-cli:v4.2.3

OpenAPI declaration file content or url
openapi: '3.0.2'
info:
  title: Tree
  description: "d3vopz open api spec for tree operations"
  termsOfService: /terms-of-use
  version: '0.0.0'
  contact:
    name: "Tree API"
    url: "https://d3vopz.net/api"
    email: "d3vopz.net@gmail.com"
  license:
    name: "Don't use ;)"
    url: "https://d3vopz.net/license"
externalDocs: # Relative URL to external documentation
  url: /docs
  description: Find more info here
servers:
#  - url: '{protocol}://{environment}.{host}/v{versionId}{versionStage}{versionStageId}'
  - url: '{protocol}://{environment}.{host}/v{versionId}{versionStage}{versionStageId}'
    variables:
      protocol:
        enum:
          - http
          - https
        default: https
      environment:
        default: api    # Production server
        enum:
          - api         # Production server
          - api.dev     # Development server
          - api.staging # Staging server
      host:
        default: localhost # local server
#      versionId:
#        default: "1"   # 1st
#      versionStage:
#        default: ""    # stable
#        enum:
#          - ""         # stable stage
#          - "alpha"    # alpha stage
#          - "beta"     # beta stage
#      versionStageId:
#        default: ""    # stable (empty)
paths:
  /tree:
    get:
      tags:
      - Current tree data
      summary: "Call current node data."
      description: "Cet current node data."
      operationId: CurrentNodeData
      parameters:
      - name: idx
        in: query
        description: "nodes idx"
        schema:
          type: integer
          format: int64
      responses:
        200:
          description: Successful response
          content:
            application/json:
              schema:
                title: Sample
                type: object
                properties:
                  placeholder:
                    type: string
                    description: Placeholder description
        404:
          description: Not found response
          content:
            text/plain:
              schema:
                title: Node not found
                type: string
                example: Not found
Command line used for generation

create the stub with: openapitools/openapi-generator-cli:v4.2.3 generate -i /local/openapi.yml -g nodejs-express-server -o /local/out/nodejs-express-server

running the stub in npm --prefix /data start where /data contains the stub

Steps to reproduce

see command line

Related issues/PRs

Did not find a similiar issue

Suggest a fix

providing an example how to get it simple running with winston or disable complex winston log as default? idk

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 5
  • Comments: 17 (5 by maintainers)

Most upvoted comments

Same here.

Now both swagger-codegen is glitchy and cannot be overridden and this doesn’t work either… So basically we are deprived of any legal way to run a trivial mock server. Great.

I’m getting the same thing on Bullseye (Debian) Linux (on a Raspberry Pi), after generating code with 6.0.1.

This was after it had been running, but failing on every query because of the “request should have required property ‘headers’” bug. I did an npm list and it claimed a bunch of dependencies were missing for express-openapi-validator (despite no errors being thrown on previous runs), so I did a manual npm install of express-openapi-validator alone. This had a bunch of deprecated or security-compromised modules, so I did a full update.

Now once again this entire server side is broken. Thanks to the OP’s analysis of logger.js, I realize that this is just a generic uninformative error message that leaves us totally in the dark.

I have pushed today a significant change to the module - took care of form-data as well. It’s still processing the pull request. I will update you as soon as you can download an update

On Sun, 22 Mar 2020, 18:16 Artiom Neganov, notifications@github.com wrote:

After some debugging I reached a spot in express-openapi-validator/dist/middlewares/openapi.request.validator.js where the error is triggered, startin from line 72:

    if (this._apiDocs.components.requestBodies) {
        Object.entries(this._apiDocs.components.requestBodies).forEach(([id, schema]) => {
            // TODO add support for content all content types
            ajv.addSchema(schema.content[TYPE_JSON].schema, `#/components/requestBodies/${id}`);
        });
    }

Specifically, this one triggers the error:

ajv.addSchema(schema.content[TYPE_JSON].schema, #/components/requestBodies/${id});

allegedly because schema.content may not have ‘application/json’ key and in my case has multipart/form-data instead.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/OpenAPITools/openapi-generator/issues/5190#issuecomment-602233517, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGOOLIT6E2HSWBLP2WEXUTRIY2W3ANCNFSM4KO2HLVA .