Open Maxim-Mazurok opened 2 months ago
Workaround in package.json
:
{
"scripts": {
"swagger:generate": "rimraf ./src/api && orval | tee /dev/tty | grep -q \"ready to use\" && exit 0 || exit 1",
}
}
Workaround script (because there's no tee/grep on Windows...)
// this script exists because https://github.com/anymaniax/orval/issues/1497
void (async () => {
const originalConsoleLog = console.log;
let orvalFinishedFine = false;
const newConsoleLog: typeof console.log = (...parameters) => {
if (typeof parameters[0] === "string" && parameters[0].includes("ready to use")) {
// expect "🎉 api - Your OpenAPI spec has been converted into ready to use orval!"
orvalFinishedFine = true;
}
if (typeof parameters[0] === "string" && parameters[0].toLowerCase().includes("error")) {
// expect "🛑 api - TypeError: Cannot read properties of undefined (reading 'properties')"
orvalFinishedFine = false;
}
originalConsoleLog.apply(console, parameters);
};
console.log = newConsoleLog;
const orval = await import("orval"); // import after console.log is replaced
await orval.generate();
// see https://github.com/typescript-eslint/typescript-eslint/issues/9477
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (!orvalFinishedFine) {
process.exit(1);
}
})();
@Maxim-Mazurok is this something that can be fixed in Orval?
Yeah, I believe so. I think I looked into it some time ago and didn't find an easy fix. The problem occurs if you have some issues in Orval config file. In my case I was trying to access some property on undefined value.
The problem was that Orval didn't return non-zero exit code, so all other scripts in CI continued to run, making it harder to find what broke the build.
Yeah I agree! Maybe there some slick place we can do a try...catch and return the exit(1)? Just thinking out loud.
What are the steps to reproduce this issue?
npx orval
What happens?
What were you expecting to happen?
Non-
0
exit codeWhat versions are you using?
Operating System: Ubuntu Package Version: 6.22.1