Skip to content

Commit a3d388b

Browse files
Merge pull request #974 from ericcrosson-bitgo/suggest-resolution-for-custom-codec-issues
feat(openapi-generator): suggest resolution for unknown codec types
2 parents 2ae878a + e320614 commit a3d388b

File tree

1 file changed

+27
-0
lines changed
  • packages/openapi-generator/src

1 file changed

+27
-0
lines changed

packages/openapi-generator/src/cli.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,33 @@ const app = command({
179179
}
180180
const [newSourceFile, init, comment] = initE.right;
181181

182+
if (init === null) {
183+
console.log({ ref });
184+
let errorMessage = `Could not determine encode/decode types for codec '${ref.name}' in '${ref.location}'`;
185+
if (ref.location.includes('/node_modules/io-ts-types/')) {
186+
errorMessage += `
187+
It looks like this codec comes from io-ts-types. Try importing directly from io-ts-types instead:
188+
189+
\`\`\`
190+
import { ${ref.name} } from 'io-ts-types';
191+
\`\`\`
192+
`;
193+
} else {
194+
errorMessage += `
195+
Consider defining a custom codec for this type.
196+
197+
https://github.com/BitGo/api-ts/tree/master/packages/openapi-generator#4-defining-custom-codecs
198+
`;
199+
}
200+
logError(
201+
errorMessage
202+
.split('\n')
203+
.map((line) => line.trimStart())
204+
.join('\n'),
205+
);
206+
process.exit(1);
207+
}
208+
182209
const codecE = parseCodecInitializer(project, newSourceFile, init);
183210
if (E.isLeft(codecE)) {
184211
logError(

0 commit comments

Comments
 (0)