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

feat(openapi-generator): suggest resolution for unknown codec types #974

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading