Skip to content

Commit

Permalink
(fix): use serialziers to parse custom config, cant cast any longer
Browse files Browse the repository at this point in the history
  • Loading branch information
dsinghvi committed Mar 20, 2024
1 parent 068d708 commit be5078a
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions generators/openapi/src/writeOpenApi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ExitStatusUpdate, GeneratorConfig, GeneratorUpdate } from "@fern-fern/generator-exec-sdk/api";
import { ExitStatusUpdate, GeneratorUpdate } from "@fern-fern/generator-exec-sdk/api";
import * as GeneratorExecParsing from "@fern-fern/generator-exec-sdk/serialization";
import { IntermediateRepresentation } from "@fern-fern/ir-sdk/api";
import * as IrSerialization from "@fern-fern/ir-sdk/serialization";
import { readFile, writeFile } from "fs/promises";
Expand All @@ -19,7 +20,21 @@ export async function writeOpenApi(mode: Mode, pathToConfig: string): Promise<vo
// eslint-disable-next-line no-console
console.log("beginning writeOpenApi");
const configStr = await readFile(pathToConfig);
const config = JSON.parse(configStr.toString()) as GeneratorConfig;
// eslint-disable-next-line no-console
console.log(`Read ${pathToConfig}`);
const rawConfig = JSON.parse(configStr.toString());
const parsedConfig = await GeneratorExecParsing.GeneratorConfig.parse(rawConfig, {
unrecognizedObjectKeys: "passthrough"
});

if (!parsedConfig.ok) {
// eslint-disable-next-line no-console
console.log(`Failed to read ${pathToConfig}`);
return;
}

const config = parsedConfig.value;

const customConfig = getCustomConfig(config);

// eslint-disable-next-line no-console
Expand Down

0 comments on commit be5078a

Please sign in to comment.