From 968ed6d796057c8950d21ac6296c9a5037652d45 Mon Sep 17 00:00:00 2001 From: Alex McKinney Date: Sun, 26 May 2024 07:48:25 -0700 Subject: [PATCH] Start adding readme controller --- fern/apis/generator-cli/definition/readme.yml | 9 +++++++-- packages/generator-cli/src/index.ts | 2 +- packages/generator-cli/src/readme/index.ts | 2 ++ pnpm-lock.yaml | 3 +++ servers/fdr/package.json | 1 + servers/fdr/src/__test__/local/setupMockFdr.ts | 4 ++++ .../fdr/src/controllers/readme/getReadmeService.ts | 12 ++++++++++++ servers/fdr/src/server.ts | 4 ++++ 8 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 packages/generator-cli/src/readme/index.ts create mode 100644 servers/fdr/src/controllers/readme/getReadmeService.ts diff --git a/fern/apis/generator-cli/definition/readme.yml b/fern/apis/generator-cli/definition/readme.yml index c9c8153f93..4f5276f7fc 100644 --- a/fern/apis/generator-cli/definition/readme.yml +++ b/fern/apis/generator-cli/definition/readme.yml @@ -77,10 +77,15 @@ service: name: GenerateReadmeRequest body: properties: - readmeConfig: ReadmeConfig + # TODO: If we store the features.yml data in the DB, we can + # alternatively accept the generator name and version. featuresConfig: features.FeaturesConfig + readmeConfig: ReadmeConfig snippets: - # TODO: Can we reference the generator-exec snippets here? + # TODO: This is duplicative; FDR already stores snippets, so + # we shouldn't need to pass them here. However, FDR doesn't + # store the snippets based on their feature, so we'd need + # to remodel the FDR API to do so. docs: | The snippet.json produced by the generator. type: unknown diff --git a/packages/generator-cli/src/index.ts b/packages/generator-cli/src/index.ts index cb0ff5c3b5..a2ac69fc1c 100644 --- a/packages/generator-cli/src/index.ts +++ b/packages/generator-cli/src/index.ts @@ -1 +1 @@ -export {}; +export * from "./readme"; diff --git a/packages/generator-cli/src/readme/index.ts b/packages/generator-cli/src/readme/index.ts new file mode 100644 index 0000000000..517add4ec3 --- /dev/null +++ b/packages/generator-cli/src/readme/index.ts @@ -0,0 +1,2 @@ +export { ReadmeGenerator } from "./ReadmeGenerator"; +export { ReadmeParser } from "./ReadmeParser"; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b942605be6..750acc8179 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1600,6 +1600,9 @@ importers: '@fern-api/fdr-sdk': specifier: workspace:* version: link:../../packages/fdr-sdk + '@fern-api/generator-cli': + specifier: workspace:* + version: link:../../packages/generator-cli '@fern-api/template-resolver': specifier: workspace:* version: link:../../packages/template-resolver diff --git a/servers/fdr/package.json b/servers/fdr/package.json index fc2620a887..baa2abbd06 100644 --- a/servers/fdr/package.json +++ b/servers/fdr/package.json @@ -12,6 +12,7 @@ "dependencies": { "@aws-sdk/client-s3": "^3.335.0", "@aws-sdk/s3-request-presigner": "^3.574.0", + "@fern-api/generator-cli": "workspace:*", "@fern-api/fdr-sdk": "workspace:*", "@fern-api/template-resolver": "workspace:*", "@fern-api/venus-api-sdk": "^0.6.2-1-gbbd1ac5", diff --git a/servers/fdr/src/__test__/local/setupMockFdr.ts b/servers/fdr/src/__test__/local/setupMockFdr.ts index 436e50fd6d..1fec2d4874 100644 --- a/servers/fdr/src/__test__/local/setupMockFdr.ts +++ b/servers/fdr/src/__test__/local/setupMockFdr.ts @@ -13,6 +13,7 @@ import { getDocsReadService } from "../../controllers/docs/v1/getDocsReadService import { getDocsWriteService } from "../../controllers/docs/v1/getDocsWriteService"; import { getDocsReadV2Service } from "../../controllers/docs/v2/getDocsReadV2Service"; import { getDocsWriteV2Service } from "../../controllers/docs/v2/getDocsWriteV2Service"; +import { getReadmeService } from "../../controllers/readme/getReadmeService"; import { getSnippetsFactoryService } from "../../controllers/snippets/getSnippetsFactoryService"; import { getSnippetsService } from "../../controllers/snippets/getSnippetsService"; import { getTemplatesService } from "../../controllers/snippets/getTemplatesService"; @@ -102,6 +103,9 @@ async function runMockFdr(port: number): Promise { templates: getTemplatesService(fdrApplication), diff: getApiDiffService(fdrApplication), docsCache: getDocsCacheService(fdrApplication), + generatorCli: { + readme: getReadmeService(fdrApplication), + }, }); const server = app.listen(port); console.log(`Mock FDR server running on http://localhost:${port}/`); diff --git a/servers/fdr/src/controllers/readme/getReadmeService.ts b/servers/fdr/src/controllers/readme/getReadmeService.ts new file mode 100644 index 0000000000..85cf08e015 --- /dev/null +++ b/servers/fdr/src/controllers/readme/getReadmeService.ts @@ -0,0 +1,12 @@ +import { ReadmeService } from "../../api/generated/api/resources/generatorCli/resources/readme/service/ReadmeService"; +import { type FdrApplication } from "../../app"; + +export function getReadmeService(app: FdrApplication): ReadmeService { + return new ReadmeService({ + generate: async (req, res) => { + // TODO: Implement me! This will take the same form as the CLI entrypoint. + // TODO: We will need to import generator-exec from here. + return; + }, + }); +} diff --git a/servers/fdr/src/server.ts b/servers/fdr/src/server.ts index a246ff7a0f..142d65bc06 100644 --- a/servers/fdr/src/server.ts +++ b/servers/fdr/src/server.ts @@ -14,6 +14,7 @@ import { getDocsReadService } from "./controllers/docs/v1/getDocsReadService"; import { getDocsWriteService } from "./controllers/docs/v1/getDocsWriteService"; import { getDocsReadV2Service } from "./controllers/docs/v2/getDocsReadV2Service"; import { getDocsWriteV2Service } from "./controllers/docs/v2/getDocsWriteV2Service"; +import { getReadmeService } from "./controllers/readme/getReadmeService"; import { getSnippetsFactoryService } from "./controllers/snippets/getSnippetsFactoryService"; import { getSnippetsService } from "./controllers/snippets/getSnippetsService"; import { getTemplatesService } from "./controllers/snippets/getTemplatesService"; @@ -111,6 +112,9 @@ async function startServer(): Promise { templates: getTemplatesService(app), diff: getApiDiffService(app), docsCache: getDocsCacheService(app), + generatorCli: { + readme: getReadmeService(app), + }, }); registerBackgroundTasks(app); app.logger.info(`Listening for requests on port ${PORT}`);