Skip to content

Commit 29ad98f

Browse files
refactor: unwrap Either immediately after inspection
This simplifies code using the `Right` value.
1 parent 6977b62 commit 29ad98f

File tree

1 file changed

+10
-9
lines changed
  • packages/openapi-generator/src

1 file changed

+10
-9
lines changed

packages/openapi-generator/src/cli.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,14 @@ const app = command({
9595
knownImports = { ...knownImports, ...customCodecs };
9696
}
9797

98-
const project = await new Project({}, knownImports).parseEntryPoint(filePath);
99-
if (E.isLeft(project)) {
100-
logError(`${project.left}`);
98+
const projectE = await new Project({}, knownImports).parseEntryPoint(filePath);
99+
if (E.isLeft(projectE)) {
100+
logError(`${projectE.left}`);
101101
process.exit(1);
102102
}
103+
const project = projectE.right;
103104

104-
const entryPoint = project.right.get(filePath);
105+
const entryPoint = project.get(filePath);
105106
if (entryPoint === undefined) {
106107
logError(`Could not find entry point ${filePath}`);
107108
process.exit(1);
@@ -128,7 +129,7 @@ const app = command({
128129
logInfo(`Found API spec in ${symbol.name}`);
129130

130131
const result = parseApiSpec(
131-
project.right,
132+
project,
132133
entryPoint,
133134
symbol.init.arguments[0]!.expression,
134135
);
@@ -158,18 +159,18 @@ const app = command({
158159
});
159160
let schema: Schema | undefined;
160161
while (((schema = queue.pop()), schema !== undefined)) {
161-
const refs = getRefs(schema, project.right.getTypes());
162+
const refs = getRefs(schema, project.getTypes());
162163
for (const ref of refs) {
163164
if (components[ref.name] !== undefined) {
164165
continue;
165166
}
166-
const sourceFile = project.right.get(ref.location);
167+
const sourceFile = project.get(ref.location);
167168
if (sourceFile === undefined) {
168169
logError(`Could not find '${ref.name}' from '${ref.location}'`);
169170
process.exit(1);
170171
}
171172

172-
const initE = findSymbolInitializer(project.right, sourceFile, ref.name);
173+
const initE = findSymbolInitializer(project, sourceFile, ref.name);
173174
if (E.isLeft(initE)) {
174175
logError(
175176
`Could not find symbol '${ref.name}' in '${ref.location}': ${initE.left}`,
@@ -178,7 +179,7 @@ const app = command({
178179
}
179180
const [newSourceFile, init, comment] = initE.right;
180181

181-
const codecE = parseCodecInitializer(project.right, newSourceFile, init);
182+
const codecE = parseCodecInitializer(project, newSourceFile, init);
182183
if (E.isLeft(codecE)) {
183184
logError(
184185
`Could not parse codec '${ref.name}' in '${ref.location}': ${codecE.left}`,

0 commit comments

Comments
 (0)