Skip to content

Commit

Permalink
Merge pull request #974 from ericcrosson-bitgo/suggest-resolution-for…
Browse files Browse the repository at this point in the history
…-custom-codec-issues

feat(openapi-generator): suggest resolution for unknown codec types
  • Loading branch information
ericcrosson-bitgo authored Dec 24, 2024
2 parents 2ae878a + e320614 commit a3d388b
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions packages/openapi-generator/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,33 @@ const app = command({
}
const [newSourceFile, init, comment] = initE.right;

if (init === null) {
console.log({ ref });
let errorMessage = `Could not determine encode/decode types for codec '${ref.name}' in '${ref.location}'`;
if (ref.location.includes('/node_modules/io-ts-types/')) {
errorMessage += `
It looks like this codec comes from io-ts-types. Try importing directly from io-ts-types instead:
\`\`\`
import { ${ref.name} } from 'io-ts-types';
\`\`\`
`;
} else {
errorMessage += `
Consider defining a custom codec for this type.
https://github.com/BitGo/api-ts/tree/master/packages/openapi-generator#4-defining-custom-codecs
`;
}
logError(
errorMessage
.split('\n')
.map((line) => line.trimStart())
.join('\n'),
);
process.exit(1);
}

const codecE = parseCodecInitializer(project, newSourceFile, init);
if (E.isLeft(codecE)) {
logError(
Expand Down

0 comments on commit a3d388b

Please sign in to comment.