From 29ad98f22fbb480e8ad6e1eb242374687ac4d3e2 Mon Sep 17 00:00:00 2001 From: Eric Crosson Date: Mon, 23 Dec 2024 14:17:30 -0600 Subject: [PATCH] refactor: unwrap Either immediately after inspection This simplifies code using the `Right` value. --- packages/openapi-generator/src/cli.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/openapi-generator/src/cli.ts b/packages/openapi-generator/src/cli.ts index 2b45fdb0..3b552f76 100644 --- a/packages/openapi-generator/src/cli.ts +++ b/packages/openapi-generator/src/cli.ts @@ -95,13 +95,14 @@ const app = command({ knownImports = { ...knownImports, ...customCodecs }; } - const project = await new Project({}, knownImports).parseEntryPoint(filePath); - if (E.isLeft(project)) { - logError(`${project.left}`); + const projectE = await new Project({}, knownImports).parseEntryPoint(filePath); + if (E.isLeft(projectE)) { + logError(`${projectE.left}`); process.exit(1); } + const project = projectE.right; - const entryPoint = project.right.get(filePath); + const entryPoint = project.get(filePath); if (entryPoint === undefined) { logError(`Could not find entry point ${filePath}`); process.exit(1); @@ -128,7 +129,7 @@ const app = command({ logInfo(`Found API spec in ${symbol.name}`); const result = parseApiSpec( - project.right, + project, entryPoint, symbol.init.arguments[0]!.expression, ); @@ -158,18 +159,18 @@ const app = command({ }); let schema: Schema | undefined; while (((schema = queue.pop()), schema !== undefined)) { - const refs = getRefs(schema, project.right.getTypes()); + const refs = getRefs(schema, project.getTypes()); for (const ref of refs) { if (components[ref.name] !== undefined) { continue; } - const sourceFile = project.right.get(ref.location); + const sourceFile = project.get(ref.location); if (sourceFile === undefined) { logError(`Could not find '${ref.name}' from '${ref.location}'`); process.exit(1); } - const initE = findSymbolInitializer(project.right, sourceFile, ref.name); + const initE = findSymbolInitializer(project, sourceFile, ref.name); if (E.isLeft(initE)) { logError( `Could not find symbol '${ref.name}' in '${ref.location}': ${initE.left}`, @@ -178,7 +179,7 @@ const app = command({ } const [newSourceFile, init, comment] = initE.right; - const codecE = parseCodecInitializer(project.right, newSourceFile, init); + const codecE = parseCodecInitializer(project, newSourceFile, init); if (E.isLeft(codecE)) { logError( `Could not parse codec '${ref.name}' in '${ref.location}': ${codecE.left}`,