@api-ts/openapi-generator
Advanced tools
Comparing version
@@ -102,8 +102,9 @@ #!/usr/bin/env node | ||
} | ||
const project = await new project_1.Project({}, knownImports).parseEntryPoint(filePath); | ||
if (E.isLeft(project)) { | ||
(0, error_1.logError)(`${project.left}`); | ||
const projectE = await new project_1.Project({}, knownImports).parseEntryPoint(filePath); | ||
if (E.isLeft(projectE)) { | ||
(0, error_1.logError)(`${projectE.left}`); | ||
process.exit(1); | ||
} | ||
const entryPoint = project.right.get(filePath); | ||
const project = projectE.right; | ||
const entryPoint = project.get(filePath); | ||
if (entryPoint === undefined) { | ||
@@ -134,3 +135,3 @@ (0, error_1.logError)(`Could not find entry point ${filePath}`); | ||
(0, error_1.logInfo)(`Found API spec in ${symbol.name}`); | ||
const result = (0, apiSpec_1.parseApiSpec)(project.right, entryPoint, symbol.init.arguments[0].expression); | ||
const result = (0, apiSpec_1.parseApiSpec)(project, entryPoint, symbol.init.arguments[0].expression); | ||
if (E.isLeft(result)) { | ||
@@ -160,3 +161,3 @@ (0, error_1.logError)(`Error when parsing ${symbol.name}: ${result.left}`); | ||
while (((schema = queue.pop()), schema !== undefined)) { | ||
const refs = (0, ref_1.getRefs)(schema, project.right.getTypes()); | ||
const refs = (0, ref_1.getRefs)(schema, project.getTypes()); | ||
for (const ref of refs) { | ||
@@ -166,3 +167,3 @@ if (components[ref.name] !== undefined) { | ||
} | ||
const sourceFile = project.right.get(ref.location); | ||
const sourceFile = project.get(ref.location); | ||
if (sourceFile === undefined) { | ||
@@ -172,3 +173,3 @@ (0, error_1.logError)(`Could not find '${ref.name}' from '${ref.location}'`); | ||
} | ||
const initE = (0, resolveInit_1.findSymbolInitializer)(project.right, sourceFile, ref.name); | ||
const initE = (0, resolveInit_1.findSymbolInitializer)(project, sourceFile, ref.name); | ||
if (E.isLeft(initE)) { | ||
@@ -179,3 +180,28 @@ (0, error_1.logError)(`Could not find symbol '${ref.name}' in '${ref.location}': ${initE.left}`); | ||
const [newSourceFile, init, comment] = initE.right; | ||
const codecE = (0, codec_1.parseCodecInitializer)(project.right, newSourceFile, init); | ||
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 | ||
`; | ||
} | ||
(0, error_1.logError)(errorMessage | ||
.split('\n') | ||
.map((line) => line.trimStart()) | ||
.join('\n')); | ||
process.exit(1); | ||
} | ||
const codecE = (0, codec_1.parseCodecInitializer)(project, newSourceFile, init); | ||
if (E.isLeft(codecE)) { | ||
@@ -182,0 +208,0 @@ (0, error_1.logError)(`Could not parse codec '${ref.name}' in '${ref.location}': ${codecE.left}`); |
{ | ||
"name": "@api-ts/openapi-generator", | ||
"version": "5.3.1", | ||
"version": "5.4.0", | ||
"description": "Generate an OpenAPI specification from an io-ts-http contract", | ||
@@ -5,0 +5,0 @@ "author": "Patrick McLaughlin <patrickmclaughlin@bitgo.com>", |
Sorry, the diff of this file is not supported yet
261543
0.62%3256
0.74%