Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong template directory lookup when running programmatic generation #1740

Open
2 tasks done
nicotsx opened this issue Jan 7, 2025 · 1 comment
Open
2 tasks done
Labels
bug good first issue This issue could be an easy PR for those looking to help contribute help wanted

Comments

@nicotsx
Copy link

nicotsx commented Jan 7, 2025

I'm trying to use the programmatic generation in order to leverage my server hot reload and have up-to-date routes and specs when developing. However, I get a strange error when running generateRoute.

Here is my helper function:

export const generateOpenApiSpec = async () => {
  const specOptions: ExtendedSpecConfig = {
    noImplicitAdditionalProperties: 'silently-remove-extras',
    entryFile: './src/server.ts',
    specVersion: 3,
    outputDirectory: './src/api/generated',
    controllerPathGlobs: ['./src/api/**/*.controller.ts'],
  };

  const routeOptions: ExtendedRoutesConfig = {
    noImplicitAdditionalProperties: 'silently-remove-extras',
    basePath: '/api/v1',
    entryFile: './src/api/server.ts',
    routesDir: './src/api/generated',
    controllerPathGlobs: ['./src/api/**/*.controller.ts'],
    bodyCoercion: true,
  };

  await generateSpec(specOptions).catch((err) => {
    console.error('Spec error', err);
  });
  await generateRoutes(routeOptions).catch((err) => {
    console.error('Routes error', err);
  });
};

Then in my main server.ts I simply call it before everything else:

export const start = async () => {
  const app = Express();

  await generateOpenApiSpec();
}

When running my app with node, I get the following error:

Routes error [Error: ENOENT: no such file or directory, open '/Users/<my-project-path>/routeGeneration/templates/express.hbs'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/Users/<my-project-path>/routeGeneration/templates/express.hbs'
}

It seems the process is trying to lookup a template from by project root instead of the dependency root.

Sorting

  • I'm submitting a ...

    • bug report
  • I confirm that I

    • used the search to make sure that a similar issue hasn't already been submit
Copy link

github-actions bot commented Jan 7, 2025

Hello there nicotsx 👋

Thank you for opening your very first issue in this project.

We will try to get back to you as soon as we can.👀

@WoH WoH added bug help wanted good first issue This issue could be an easy PR for those looking to help contribute labels Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug good first issue This issue could be an easy PR for those looking to help contribute help wanted
Projects
None yet
Development

No branches or pull requests

2 participants