OpenAPITools / OpenAPITools/openapi-generator

Design questions node-express-server

Open
#4,552 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description

This is not a bug report but more of a question about some design decision of the generated code

  1. The service class need to now about http result codes. I don't think a service should now anything about how it is used later. So it should only return data and perhaps throw an exception but it don't know if it is called from a rest-api controller, a cli or another service. But in the template the service functions should return data and http return codes

  2. Inside a service function do you create a promise

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

why not the much simpler declaring the function as async?

static async someFunction({ someParameter }) {
  try {
    return Service.successResponse('');
  } catch (e) {
    return Service.rejectResponse(
       e.message || 'Invalid input',
       e.status || 405,
    );
  }
}

or am I missing something obvious?

openapi-generator version

4.2 (but 5.0 branch is similar)

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

The issue names the node-express-server generator and its service functions; begin by reviewing the generated templates in the referenced 4.2 and 5.0 branches. Determine whether the service/controller boundary and async error-handling approach should change, then document a maintainer-approved decision before identifying the affected templates and tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
express, javascript, node.js
Domain
api, backend
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.