Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

386
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda