Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

380
Views
Writing Node business logic behind openapi-generator-cli nodejs-express-server

Currently we are doing the following:

Using an openapitools.json that looks like the following:

{
  "$schema": "node_modules/@openapitools/openapi-generator-cli/config.schema.json",
  "spaces": 2,
  "generator-cli": {
    "version": "5.1.1",
    "generators": {
      "node_v1.0": {
        "generatorName": "nodejs-express-server",
        "output": "#{cwd}/api/gen/v1.0/#{name}",
        "glob": "openapi/*.yaml"
      }
    }
  }
}

And we run a command:

npx openapi-generator-cli generate

Which creates this gen dir which structure like:

- api
- controllers
- services
- utils

etc.

Currently, our solution for business and database logic is to go to the controllers/DefaultController.js and change the require link for Service to point to our actual src/business_logic/Service.js code. In our Service.js code we call other logic in the endpoints like for example:

static getMaterials() {
    const payload = MaterialLogic.materialFetchAll();
    const code = 200;
    return { payload, code };
}

For reference, the generated code look like this, but you can see there is no logic:

/**
* Returns list of materials
*
* returns List
* */
const getMaterials = () => new Promise(
  async (resolve, reject) => {
    try {
      resolve(Service.successResponse({
      }));
    } catch (e) {
      reject(Service.rejectResponse(
        e.message || 'Invalid input',
        e.status || 405,
      ));
    }
  },
);

The OpenAPI spec for this looks like:

/materials:
  get:
    operationId: getMaterials
    description: Returns list of materials
    responses:
      200:
        description: list of Materials
        content:
          application/json:
            schema:
              type: array
              items:
                $ref: '#/components/schemas/Material'
      401:
        description: not authorized to use this endpoint

It's obviously the wrong approach for us to have to change any code in gen to make our application work as it needs to be overridden and generated at any time (hence the whole point of using openapi gen tools). What's the correct way to do this? In our openapi spec is there a way to specify a different Service.js to use? Or is there some kind of dependency injection we are missing to get our business/database logic in there? Hopefully our problem is clear enough.

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!