tsoa
tsoa copied to clipboard
Wrong template directory lookup when running programmatic generation
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 ...
- [x] bug report
-
I confirm that I
- [x] used the search to make sure that a similar issue hasn't already been submit
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.👀