diff --git a/pages/docs/tools/generator/api.md b/pages/docs/tools/generator/api.md index e15f4cdf9db..b6923a5e7a1 100644 --- a/pages/docs/tools/generator/api.md +++ b/pages/docs/tools/generator/api.md @@ -26,7 +26,15 @@ Reference API documentation for AsyncAPI Generator library. * [.hooks](#Generator+hooks) : `Object` * [.mapBaseUrlToFolder](#Generator+mapBaseUrlToFolder) : `Object` * [.templateParams](#Generator+templateParams) : `Object` - * [.generate(asyncapiDocument, [parseOptions])](#Generator+generate) ⇒ `Promise` + * [.generate(asyncapiDocument, [parseOptions])](#Generator+generate) ⇒ `Promise.` + * [.validateAsyncAPIDocument(asyncapiDocument)](#Generator+validateAsyncAPIDocument) + * [.setupOutput()](#Generator+setupOutput) + * [.setupFSOutput()](#Generator+setupFSOutput) ⇒ `Promise.` + * [.setLogLevel()](#Generator+setLogLevel) ⇒ `void` + * [.installAndSetupTemplate()](#Generator+installAndSetupTemplate) ⇒ `Promise.<{templatePkgName: string, templatePkgPath: string}>` + * [.configureTemplateWorkflow(parseOptions)](#Generator+configureTemplateWorkflow) ⇒ `Promise.` + * [.handleEntrypoint()](#Generator+handleEntrypoint) ⇒ `Promise.` + * [.executeAfterHook()](#Generator+executeAfterHook) ⇒ `Promise.` * [.parseInput()](#Generator+parseInput) * [.configureTemplate()](#Generator+configureTemplate) * ~~[.generateFromString(asyncapiString, [parseOptions])](#Generator+generateFromString) ⇒ `Promise`~~ @@ -169,11 +177,19 @@ The template parameters. The structure for this object is based on each individu Generates files from a given template and an AsyncAPIDocument object. **Kind**: instance method of [`Generator`](#Generator) +**Returns**: `Promise.` - A Promise that resolves when the generation is completed. **Params** - asyncapiDocument `AsyncAPIDocument` | `string` - AsyncAPIDocument object to use as source. -- [parseOptions] `Object` ` = {}` - AsyncAPI Parser parse options. Check out [@asyncapi/parser](https://www.github.com/asyncapi/parser-js) for more information. Remember to use the right options to the right parser depending on the template you are using. +- [parseOptions] `Object` ` = {}` - AsyncAPI Parser parse options. + Check out [@asyncapi/parser](https://www.github.com/asyncapi/parser-js) for more information. + Remember to use the right options for the right parser depending on the template you are using. +**Example** +```js +await generator.generate(myAsyncAPIdocument); +console.log('Done!'); +``` **Example** ```js generator @@ -193,6 +209,118 @@ try { } ``` + + +### generator.validateAsyncAPIDocument +Validates the provided AsyncAPI document. + +**Kind**: instance method of [`Generator`](#Generator) +**Throws**: + +- `Error` Throws an error if the document is not valid. + +**Since**: 10/9/2023 - 4:26:33 PM +**Params** + +- asyncapiDocument `*` - The AsyncAPI document to be validated. + + + + +* generator.setupOutput()** : +Sets up the output configuration based on the specified output type. + +**Kind**: instance method of [`Generator`](#Generator) +**Throws**: + +- `Error` If 'output' is set to 'string' without providing 'entrypoint'. + +**Example** +```js +const generator = new Generator(); +generator.setupOutput(); +``` + + + +* generator.setupFSOutput() ⇒ `Promise.`** : +Sets up the file system (FS) output configuration. + +This function creates the target directory if it does not exist and verifies +the target directory if forceWrite is not enabled. + +**Kind**: instance method of [`Generator`](#Generator) +**Returns**: `Promise.` - A promise that fulfills when the setup is complete. +**Throws**: + +- `Error` If verification of the target directory fails and forceWrite is not enabled. + + + + +* generator.setLogLevel() ⇒ `void`** : +Sets the log level based on the debug option. + +If the debug option is enabled, the log level is set to 'debug'. + +**Kind**: instance method of [`Generator`](#Generator) + + + +* generator.installAndSetupTemplate() ⇒ `Promise.<{templatePkgName: string, templatePkgPath: string}>`** : +Installs and sets up the template for code generation. + +This function installs the specified template using the provided installation option, +sets up the necessary directory paths, loads the template configuration, and returns +information about the installed template. + +**Kind**: instance method of [`Generator`](#Generator) +**Returns**: `Promise.<{templatePkgName: string, templatePkgPath: string}>` - A promise that resolves to an object containing the name and path of the installed template. + + + +### generator.configureTemplateWorkflow +Configures the template workflow based on provided parsing options. + +This function performs the following steps: +1. Parses the input AsyncAPI document using the specified parse options. +2. Validates the template configuration and parameters. +3. Configures the template based on the parsed AsyncAPI document. +4. Registers filters, hooks, and launches the 'generate:before' hook if applicable. + +**Kind**: instance method of [`Generator`](#Generator) +**Returns**: `Promise.` - A promise that resolves when the configuration is completed. +**Params** + +- parseOptions `*` - Options for parsing the AsyncAPI document. + + + + +* generator.handleEntrypoint() ⇒ `Promise.`** : +Handles the logic for the template entrypoint. + +If an entrypoint is specified: +- Resolves the absolute path of the entrypoint file. +- Throws an error if the entrypoint file doesn't exist. +- Generates a file or renders content based on the output type. +- Launches the 'generate:after' hook if the output is 'fs'. + +If no entrypoint is specified, generates the directory structure. + +**Kind**: instance method of [`Generator`](#Generator) +**Returns**: `Promise.` - A promise that resolves when the entrypoint logic is completed. + + + +* generator.executeAfterHook() ⇒ `Promise.`** : +Executes the 'generate:after' hook. + +Launches the after-hook to perform additional actions after code generation. + +**Kind**: instance method of [`Generator`](#Generator) +**Returns**: `Promise.` - A promise that resolves when the after-hook execution is completed. + * generator.parseInput()** :