Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

381
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda