OpenAPITools / OpenAPITools/openapi-generator

Pass Authorization header in nodejs-express-sever

Open
#5,628 5 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Is your feature request related to a problem? Please describe.

The nodejs-express-server doesn't in anyway provide the authentication header specified via security schemes.

Describe the solution you'd like

I'd like that the Authorization value is passed to the service.
For instance i'm using the generated nodejs-express-server as an aggregator between mircro-services. I want to be able to pass the Authorization header to these services.

Describe alternatives you've considered

Digging deep into the code can we simply just add the headers to the requestParams e.g

  static collectRequestParams(request) {
    this.collectFiles(request);
    const requestParams = {};
    if (request.openapi.schema.requestBody !== undefined) {
      requestParams.body = request.body;
    }
    request.openapi.schema.parameters.forEach((param) => {
      if (param.in === 'path') {
        requestParams[param.name] = request.openapi.pathParams[param.name];
      } else if (param.in === 'query') {
        requestParams[param.name] = request.query[param.name];
      }
    });
    requestParams['headers'] = request.headers; //ADDED THIS LINE
    return requestParams;
  }

// and thereafter destructure the header from the service..

  static createSomething({ something, headers }) {
    return new Promise(
      async (resolve) => {
        try {
            console.log(headers);
          resolve(Service.successResponse(''));
        } catch (e) {
          resolve(Service.rejectResponse(
            e.message || 'Invalid input',
            e.status || 405,
          ));
        }
      },
    );
  } 

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 by tracing the generated nodejs-express-server request handling around collectRequestParams and the service method pattern shown in the issue. Verify how security schemes and incoming headers are represented, then confirm that the Authorization value reaches downstream service methods without breaking existing request parameters or tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
express, javascript, node.js
Domain
api, authentication, backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 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.