OpenAPITools / OpenAPITools/openapi-generator

[BUG][NodeJS-Express-Server ReferenceRequestBodies are not parsed by the controller

Open
#6,678 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug Server: Nodejs
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • [5] 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

The NodeJS Express Server generator controller.js does not process reference request bodies. Is there are a way to make it do so?

openapi-generator version

5

OpenAPI declaration file content or url
   post:
      operationId: organisationsOrganisationIdAuthorisationserversPOST
      parameters:
      - description: The organisation ID
        explode: false
        in: path
        name: OrganisationId
        required: true
        schema:
          $ref: '#/components/schemas/OrganisationId'
        style: simple
      requestBody:
        $ref: '#/components/requestBodies/AuthorisationServerRequest'
      responses:
        "201":
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AuthorisationServer'
          description: Authorisation server response
        "400":
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BadRequest'
          description: Bad Request
        "401":
          description: Unauthorized
        "404":
          description: Not found
        "406":
          description: Not Acceptable
        "500":
          description: Internal Server Error
        "502":
          description: Bad Gateway
      security:
      - authorizer: []
      summary: Create an Authorisation Server for the given organisation
      tags:
      - Authorisation Servers
      x-eov-operation-handler: controllers/AuthorisationServersController
Command line used for generation

OPENAPI_GENERATOR_VERSION=5.0.0-SNAPSHOT openapi-generator-cli generate -i /TrustFramework.yaml -o ./output -g nodejs-express-server

Steps to reproduce
  1. Generate the server.
  2. Test that GETs function correctly.
  3. Post's fail to process throwing an undefined exception in Controller.js collectRequestParams() const { content } = request.openapi.schema.requestBody; as content is undefined whent the requestbody is a reference.
Related issues/PRs
Suggest a fix

Can reference request bodies be handled

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

Start with the generated controller.js collectRequestParams() path described in the report and reproduce the issue using the provided OpenAPI declaration and generation command. Trace how request.openapi.schema.requestBody is populated when requestBody uses a reference. Done means POST requests process reference request bodies without an undefined content error.

Written by the indexing model from the issue text.

Assessment

Tech stack
express, javascript, node.js, openapi
Domain
api, backend, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.