diff --git a/apps/integrations/src/trigger/sdk/generateService.ts b/apps/integrations/src/trigger/sdk/generateService.ts index e1c93e6c6..9479696a5 100644 --- a/apps/integrations/src/trigger/sdk/generateService.ts +++ b/apps/integrations/src/trigger/sdk/generateService.ts @@ -232,7 +232,8 @@ async function generateDocs( functionsData: Record ) { const promises = Object.values(functionsData).map(async (f) => { - const markdown = `--- + //metadata and intro + let markdown = `--- title: ${f.title} sidebarTitle: ${f.title} description: ${f.description} @@ -240,6 +241,22 @@ description: ${f.description} ${f.description}`; + //Base params + markdown += ` + +## Params + + + A unique string. Please see the [Keys and Resumability](/guides/resumability) + doc for more info. +`; + + //Input schema + if (f.input) { + markdown += "\n\n"; + markdown += generateParamFieldFromSchema("params", true, f.input); + } + project.createSourceFile( `${basePath}/docs/${fileNameFromTitleCase(f.friendlyName)}.mdx`, markdown, @@ -248,6 +265,14 @@ ${f.description}`; } ); + project.createSourceFile( + `${basePath}/docs/${fileNameFromTitleCase(f.friendlyName)}.json`, + JSON.stringify(f.input, null, 2), + { + overwrite: true, + } + ); + return Promise.resolve(); }); @@ -270,3 +295,46 @@ function TitleCaseWithSpaces(str: string) { return str.toUpperCase(); }); } + +function generateParamFieldFromSchema( + key: string, + required: boolean, + schema: JSONSchema | boolean +): string { + if (typeof schema === "boolean") return ""; + const { description } = schema; + let output = `\n`; + if (description) { + output += ` ${description}\n`; + } + + if (schema.type === "object") { + if (schema.properties) { + output += Object.entries(schema.properties) + .map( + ([k, v]) => + ` ${generateParamFieldFromSchema( + k, + schema.required?.find((r) => r === k) != undefined ?? false, + v + )}` + ) + .join("\n"); + } + if (schema.additionalProperties) { + output += Object.entries(schema.additionalProperties) + .map( + ([k, v]) => + ` ${generateParamFieldFromSchema( + k, + schema.required?.find((r) => r === k) != undefined ?? false, + v + )}` + ) + .join("\n"); + } + } + + output += ``; + return output; +}