Skip to content

Commit

Permalink
refactor openapi notification to match postman implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Omar Rida authored and Omar Rida committed Mar 20, 2024
1 parent 74fd632 commit 068d708
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 33 deletions.
23 changes: 23 additions & 0 deletions generators/openapi/src/GeneratorNotificationService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { FernGeneratorExec, FernGeneratorExecClient } from "@fern-fern/generator-exec-sdk";

export class GeneratorNotificationService {
// implementation defined in constructor
public sendUpdate: (update: FernGeneratorExec.GeneratorUpdate) => Promise<void>;

constructor(generatorConfig: FernGeneratorExec.GeneratorConfig) {
// eslint-disable-next-line no-console
console.log(`Generator config environment is ${generatorConfig.environment.type}`);
if (generatorConfig.environment.type === "remote") {
const generatorExecClient = new FernGeneratorExecClient({
environment: generatorConfig.environment.coordinatorUrlV2
});
const taskId = generatorConfig.environment.id;
this.sendUpdate = async (update) => {
await generatorExecClient.logging.sendUpdate(taskId, [update]);
};
} else {
// no-op
this.sendUpdate = () => Promise.resolve();
}
}
}
31 changes: 0 additions & 31 deletions generators/openapi/src/generatorLoggingWrapper.ts

This file was deleted.

4 changes: 2 additions & 2 deletions generators/openapi/src/writeOpenApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import merge from "lodash-es/merge";
import path from "path";
import { convertToOpenApi } from "./convertToOpenApi";
import { getCustomConfig } from "./customConfig";
import { GeneratorLoggingWrapper } from "./generatorLoggingWrapper";
import { GeneratorNotificationService } from "./GeneratorNotificationService";

const OPENAPI_JSON_FILENAME = "openapi.json";
const OPENAPI_YML_FILENAME = "openapi.yml";
Expand All @@ -24,7 +24,7 @@ export async function writeOpenApi(mode: Mode, pathToConfig: string): Promise<vo

// eslint-disable-next-line no-console
console.log("customConfig", JSON.stringify(customConfig));
const generatorLoggingClient = new GeneratorLoggingWrapper(config);
const generatorLoggingClient = new GeneratorNotificationService(config);

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

0 comments on commit 068d708

Please sign in to comment.