OpenAPITools / OpenAPITools/openapi-generator

[BUG][nodejs-express-server] HTTP headers with hyphens

Open
#7,389 1 comment 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)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

When the spec includes HTTP headers with hyphens (my-header), as is the standard, the generated service correctly converts the variable name to camelCase (myHeader), however at runtime, the requestParams object still uses the hyphen version (params['my-header']).

Therefore, the variable does not correctly map the value.

openapi-generator version

5.0.0-SNAPSHOT

OpenAPI declaration file content or url
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "in": "header",
            "name": "my-header",
            "required": true
          }
        ]
Generation Details

docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli generate -i /local/api/api.json -t /local/core/swagger/mustache/nodejs-express-server/ -g nodejs-express-server -o /local/server/ --skip-validate-spec

Steps to reproduce
  • Create an API specs with required HTTP headers, the header name must include a hyphen
  • Generate a nodejs server
  • Put a breakpoint in the generate Service, see that the variable is always undefined.
Suggest a fix

Whatever algorithm is used to transform the variable names, should be used when mapping the request params at run time.

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 nodejs-express-server template at core/swagger/mustache/nodejs-express-server/ and reproduce the issue using the Docker generation command in the report. Use an OpenAPI header named my-header, then inspect the generated Service and requestParams handling. Done means the runtime mapping uses the same camelCase variable name as the generated service.

Written by the indexing model from the issue text.

Assessment

Tech stack
express, nodejs
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.