@asyncapi/generator 3.1.0 → 3.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/docs/configuration-file.md +1 -1
- package/docs/template.md +1 -1
- package/lib/templates/bakedInTemplates/core-template-client-kafka-java-quarkus/README.md +1 -1
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/README.md +1 -1
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/components/CompileOperationSchemas.js +7 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/components/CompileOperationSchemas.js.map +1 -1
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/template/client.js.js +7 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/template/client.js.js.map +1 -1
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/components/CompileOperationSchemas.js +7 -0
- package/lib/templates/config/loader.js +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @asyncapi/generator
|
|
2
2
|
|
|
3
|
+
## 3.1.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 4a09f57: Bump @asyncapi/parser to 3.6.0 to support AsyncAPI 3.1.0
|
|
8
|
+
|
|
9
|
+
## 3.1.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 2bfad27: Fix generator handling of template parameters with `false` default values, ensuring defaults are correctly injected and conditional generation works as expected.
|
|
14
|
+
|
|
3
15
|
## 3.1.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
|
@@ -159,7 +159,7 @@ The `generator` property from `package.json` file must contain a JSON object and
|
|
|
159
159
|
| `conditionalFiles[filePath].validation` | Object | The `validation` is a JSON Schema Draft 07 object. This JSON Schema definition will be applied to the JSON value resulting from the `subject` query. If validation doesn't have errors, the condition is met, and therefore the given file will be rendered. Otherwise, the file is ignored. Check [JSON Schema Validation](https://json-schema.org/draft-07/json-schema-validation.html#rfc.section.6) for a list of all possible validation keywords. **Note: It is deprecated and will be removed with future releases. Use `conditionalGeneration` instead.** |
|
|
160
160
|
| `conditionalGeneration` | Object[String, `{ subject?: String, parameter?: String, validation: Object }`] | An object containing all the file paths or directory names that should be conditionally rendered. Each key represents a file path or directory name and each value must be an object with the keys `subject`, `parameter` and `validation`. You can use either subject or parameter according to the use case. The path should be relative to the `template` directory inside the template. **Note: conditionalGeneration and conditionalFile are mutually exclusive, which means both cannot be configured at the same time in the template**. |
|
|
161
161
|
| `conditionalGeneration[filePath/directoryName].subject` | String | The `subject` is a [JMESPath](http://jmespath.org/) query to grab the value you want to apply the condition to. It queries an object with the whole AsyncAPI document and, when specified, the given server. The object looks like this: `{ asyncapi: { ... }, server: { ... } }`. If the template supports the `server` parameter, you can access server details like, for example, protocol this way: `server.protocol`. During validation with `conditionalGeneration`, only the server that the template user selected is available in the specification file. For more information about the `server` parameter [read about special parameters](#special-parameters). |
|
|
162
|
-
| `conditionalGeneration[filePath/directoryName].parameter` | String | The `parameter` is the name of a custom template parameter passed through `templateParams` that controls whether a specific file or folder should be included in the generated output. You must define a `validation` rule using a JSON Schema fragment to apply the condition. For example, if you define `"parameter": "includeDocs"` with `"validation": { "const": true }`, the corresponding folder (e.g., `docs/`) will only be generated when the user passes `{ includeDocs: true }`. If `includeDocs` is `false`, it will be skipped. |
|
|
162
|
+
| `conditionalGeneration[filePath/directoryName].parameter` | String | The `parameter` is the name of a custom template parameter passed through `templateParams` that controls whether a specific file or folder should be included in the generated output. You must define a `validation` rule using a JSON Schema fragment to apply the condition. For example, if you define `"parameter": "includeDocs"` with `"validation": { "const": true }`, the corresponding folder (e.g., `docs/`) will only be generated when the user passes `{ includeDocs: true }`. If `includeDocs` is `false`, it will be skipped. When you rely on a parameter here, make sure its default value declared in the `parameters` section uses the same data type your validation expects; mismatched types lead to failing conditions even when the defaults should allow generation. |
|
|
163
163
|
| `conditionalGeneration[filePath/directoryName].validation` | Object (JSON Schema fragment) | The validation defines the condition under which the file or directory will be generated. It must be a valid JSON Schema fragment that validates the value of the parameter. For example, if you want to include a folder only when includeDocs is true, use "validation": `{ "const": true }`. You can also use more complex validation logic, like "enum": ["yes", "true"] or "type": "string" with a "pattern" constraint. If the parameter fails validation, the file or folder will not be included in the generated output. This allows for powerful and flexible control over template generation based on user input. |
|
|
164
164
|
| `nonRenderableFiles` | [String] | A list of file paths or [globs](https://en.wikipedia.org/wiki/Glob_(programming)) that must be copied "as-is" to the target directory, i.e., without performing any rendering process. This is useful when you want to copy binary files. |
|
|
165
165
|
| `generator` | [String] | A string representing the generator version-range the template is compatible with. This value must follow the [semver](https://nodejs.dev/learn/semantic-versioning-using-npm) syntax. E.g., `>=1.0.0`, `>=1.0.0 <=2.0.0`, `~1.0.0`, `^1.0.0`, `1.0.0`, etc. [Read more about semver](https://docs.npmjs.com/about-semantic-versioning). |
|
package/docs/template.md
CHANGED
|
@@ -29,7 +29,7 @@ Baked-in templates benefit from:
|
|
|
29
29
|
|
|
30
30
|
In contrast, **standalone templates** (described below) are maintained as independent Node.js packages, may live in separate repositories, and can be managed or installed separately from the core generator.
|
|
31
31
|
|
|
32
|
-
Learn more from document [Baked-in Templates](
|
|
32
|
+
Learn more from document [Baked-in Templates](baked-in-templates).
|
|
33
33
|
|
|
34
34
|
### Standalone templates
|
|
35
35
|
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
1. Navigate to `packages/templates/clients/kafka/java/quarkus`
|
|
27
27
|
2. Install with `npm install`
|
|
28
28
|
3. Navigate back to `./generator`
|
|
29
|
-
4. Generate the template client with `node .\apps\generator\cli.js <path-to-custom-document> .\packages\templates\clients\kafka\java\quarkus\ -o outputClient --force-write --param server=<custom-server>`
|
|
29
|
+
4. Generate the template client with `node .\apps\generator\test\cli.js <path-to-custom-document> .\packages\templates\clients\kafka\java\quarkus\ -o outputClient --force-write --param server=<custom-server>`
|
|
30
30
|
5. Navigate to `outputClient` or any other name you gave the output folder
|
|
31
31
|
6. Navigate to the docker folder with `cd src/main/docker` and find the `docker-compose.yaml` file.
|
|
32
32
|
7. Start the kafka broker by runnning `docker-compose up -d`. Make sure you have docker desktop up and running.
|
package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/README.md
CHANGED
|
@@ -75,7 +75,7 @@ You can use our AsyncAPI's credentials to access different set of events produce
|
|
|
75
75
|
2. Navigate to `packages/templates/clients/websocket/java/quarkus`
|
|
76
76
|
3. Install with `npm install`
|
|
77
77
|
4. Navigate back to `./generator`
|
|
78
|
-
5. Generate the template client with `node .\apps\generator\cli.js <path-to-custom-document> .\packages\templates\clients\websocket\java\quarkus\ -o outputClient --force-write --param server=<custom-server>`
|
|
78
|
+
5. Generate the template client with `node .\apps\generator\test\cli.js <path-to-custom-document> .\packages\templates\clients\websocket\java\quarkus\ -o outputClient --force-write --param server=<custom-server>`
|
|
79
79
|
6. Navigate to `outputClient` or any other name you gave the output folder
|
|
80
80
|
7. Run `mvn quarkus:dev`
|
|
81
81
|
8. See the output in the terminal
|
|
@@ -38,6 +38,13 @@ async compileOperationSchemas() {
|
|
|
38
38
|
console.log('Schemas initialized successfully for operations:', this.sendOperationsId.join(', '));
|
|
39
39
|
} catch (error) {
|
|
40
40
|
console.error('Error initializing schemas:', error);
|
|
41
|
+
this.schemasCompiled = false;
|
|
42
|
+
if (error instanceof Error) {
|
|
43
|
+
error.message = \`Schema compilation failed: \${error.message}\`;
|
|
44
|
+
throw error;
|
|
45
|
+
} else {
|
|
46
|
+
throw new Error(\`Schema compilation failed: \${String(error)}\`);
|
|
47
|
+
}
|
|
41
48
|
}
|
|
42
49
|
}`
|
|
43
50
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CompileOperationSchemas.js","sources":["../../../../../../../../packages/templates/clients/websocket/javascript/components/CompileOperationSchemas.js"],"sourcesContent":["import { Text } from '@asyncapi/generator-react-sdk';\n\nexport function CompileOperationSchemas({ sendOperations }) {\n if (!sendOperations || sendOperations.length === 0) {\n return null;\n } \n\n return (\n <>\n <Text indent={2} newLines={2}>\n {\n `/**\n * Initialize and compile all schemas for operations defined.\n * This should be called once after creating the client instance.\n * Subsequent calls will be ignored if schemas are already compiled.\n * \n * @returns {Promise<void>}\n * @throws {Error} If schema compilation fails for any operation\n */\nasync compileOperationSchemas() {\n if (this.schemasCompiled) {\n return;\n }\n\n try {\n // Compile schemas for all send operations\n for (const operationId of this.sendOperationsId) {\n this.compiledSchemas[operationId] = await compileSchemasByOperationId(asyncapiFilepath, operationId);\n }\n this.schemasCompiled = true;\n console.log('Schemas initialized successfully for operations:', this.sendOperationsId.join(', '));\n } catch (error) {\n console.error('Error initializing schemas:', error);\n }\n}`\n }\n </Text>\n </>\n );\n}\n"],"names":["CompileOperationSchemas","sendOperations","length","_jsx","_Fragment","children","Text","indent","newLines"],"mappings":";;;;;;;;AAEO,SAASA,uBAAuBA,CAAC;AAAEC,EAAAA,cAAAA;AAAe,CAAC,EAAE;EAC1D,IAAI,CAACA,cAAc,IAAIA,cAAc,CAACC,MAAM,KAAK,CAAC,EAAE;AAClD,IAAA,OAAO,IAAI,CAAA;AACb,GAAA;EAEA,oBACEC,cAAA,CAAAC,mBAAA,EAAA;IAAAC,QAAA,eACEF,cAAA,CAACG,sBAAI,EAAA;AAACC,MAAAA,MAAM,EAAE,CAAE;AAACC,MAAAA,QAAQ,EAAE,CAAE;AAAAH,MAAAA,QAAA,EAEzB,CAAA;AACV;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAA,CAAA;KAEY,CAAA;AAAC,GACP,CAAC,CAAA;AAEP;;;;"}
|
|
1
|
+
{"version":3,"file":"CompileOperationSchemas.js","sources":["../../../../../../../../packages/templates/clients/websocket/javascript/components/CompileOperationSchemas.js"],"sourcesContent":["import { Text } from '@asyncapi/generator-react-sdk';\n\nexport function CompileOperationSchemas({ sendOperations }) {\n if (!sendOperations || sendOperations.length === 0) {\n return null;\n } \n\n return (\n <>\n <Text indent={2} newLines={2}>\n {\n `/**\n * Initialize and compile all schemas for operations defined.\n * This should be called once after creating the client instance.\n * Subsequent calls will be ignored if schemas are already compiled.\n * \n * @returns {Promise<void>}\n * @throws {Error} If schema compilation fails for any operation\n */\nasync compileOperationSchemas() {\n if (this.schemasCompiled) {\n return;\n }\n\n try {\n // Compile schemas for all send operations\n for (const operationId of this.sendOperationsId) {\n this.compiledSchemas[operationId] = await compileSchemasByOperationId(asyncapiFilepath, operationId);\n }\n this.schemasCompiled = true;\n console.log('Schemas initialized successfully for operations:', this.sendOperationsId.join(', '));\n } catch (error) {\n console.error('Error initializing schemas:', error);\n this.schemasCompiled = false;\n if (error instanceof Error) {\n error.message = \\`Schema compilation failed: \\${error.message}\\`;\n throw error;\n } else {\n throw new Error(\\`Schema compilation failed: \\${String(error)}\\`);\n }\n }\n}`\n }\n </Text>\n </>\n );\n}\n"],"names":["CompileOperationSchemas","sendOperations","length","_jsx","_Fragment","children","Text","indent","newLines"],"mappings":";;;;;;;;AAEO,SAASA,uBAAuBA,CAAC;AAAEC,EAAAA,cAAAA;AAAe,CAAC,EAAE;EAC1D,IAAI,CAACA,cAAc,IAAIA,cAAc,CAACC,MAAM,KAAK,CAAC,EAAE;AAClD,IAAA,OAAO,IAAI,CAAA;AACb,GAAA;EAEA,oBACEC,cAAA,CAAAC,mBAAA,EAAA;IAAAC,QAAA,eACEF,cAAA,CAACG,sBAAI,EAAA;AAACC,MAAAA,MAAM,EAAE,CAAE;AAACC,MAAAA,QAAQ,EAAE,CAAE;AAAAH,MAAAA,QAAA,EAEzB,CAAA;AACV;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAA,CAAA;KAEY,CAAA;AAAC,GACP,CAAC,CAAA;AAEP;;;;"}
|
|
@@ -71,6 +71,13 @@ async compileOperationSchemas() {
|
|
|
71
71
|
console.log('Schemas initialized successfully for operations:', this.sendOperationsId.join(', '));
|
|
72
72
|
} catch (error) {
|
|
73
73
|
console.error('Error initializing schemas:', error);
|
|
74
|
+
this.schemasCompiled = false;
|
|
75
|
+
if (error instanceof Error) {
|
|
76
|
+
error.message = \`Schema compilation failed: \${error.message}\`;
|
|
77
|
+
throw error;
|
|
78
|
+
} else {
|
|
79
|
+
throw new Error(\`Schema compilation failed: \${String(error)}\`);
|
|
80
|
+
}
|
|
74
81
|
}
|
|
75
82
|
}`
|
|
76
83
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js.js","sources":["../../../../../../../../packages/templates/clients/websocket/javascript/components/Constructor.js","../../../../../../../../packages/templates/clients/websocket/javascript/components/ModuleExport.js","../../../../../../../../packages/templates/clients/websocket/javascript/components/CompileOperationSchemas.js","../../../../../../../../packages/templates/clients/websocket/javascript/components/ClientClass.js","../../../../../../../../packages/templates/clients/websocket/javascript/template/client.js.js"],"sourcesContent":["import { Text } from '@asyncapi/generator-react-sdk';\n\nexport function Constructor({ serverUrl, sendOperations }) {\n const sendOperationsId = sendOperations.map((operation) => operation.id());\n const sendOperationsArray = JSON.stringify(sendOperationsId);\n\n return (\n <Text indent={2}>\n {\n `/*\n * Constructor to initialize the WebSocket client\n * @param {string} url - The WebSocket server URL. Use it if the server URL is different from the default one taken from the AsyncAPI document.\n*/\nconstructor(url) {\n this.url = url || '${serverUrl}';\n this.websocket = null;\n this.messageHandlers = [];\n this.errorHandlers = [];\n this.compiledSchemas = {};\n this.schemasCompiled = false;\n this.sendOperationsId = ${sendOperationsArray};\n}\n`\n }\n </Text>\n );\n}\n","import { Text } from '@asyncapi/generator-react-sdk';\n\nexport function ModuleExport({ clientName }) {\n return (\n <Text>\n {\n `module.exports = ${clientName};`\n }\n </Text>\n );\n}\n","import { Text } from '@asyncapi/generator-react-sdk';\n\nexport function CompileOperationSchemas({ sendOperations }) {\n if (!sendOperations || sendOperations.length === 0) {\n return null;\n } \n\n return (\n <>\n <Text indent={2} newLines={2}>\n {\n `/**\n * Initialize and compile all schemas for operations defined.\n * This should be called once after creating the client instance.\n * Subsequent calls will be ignored if schemas are already compiled.\n * \n * @returns {Promise<void>}\n * @throws {Error} If schema compilation fails for any operation\n */\nasync compileOperationSchemas() {\n if (this.schemasCompiled) {\n return;\n }\n\n try {\n // Compile schemas for all send operations\n for (const operationId of this.sendOperationsId) {\n this.compiledSchemas[operationId] = await compileSchemasByOperationId(asyncapiFilepath, operationId);\n }\n this.schemasCompiled = true;\n console.log('Schemas initialized successfully for operations:', this.sendOperationsId.join(', '));\n } catch (error) {\n console.error('Error initializing schemas:', error);\n }\n}`\n }\n </Text>\n </>\n );\n}\n","import { Text } from '@asyncapi/generator-react-sdk';\nimport { Constructor } from './Constructor';\nimport { CloseConnection, RegisterMessageHandler, RegisterErrorHandler, SendOperations, Connect, HandleMessage } from '@asyncapi/generator-components';\nimport { ModuleExport } from './ModuleExport';\nimport { CompileOperationSchemas } from './CompileOperationSchemas';\n\nexport function ClientClass({ clientName, serverUrl, title, sendOperations }) {\n return (\n <Text>\n <Text newLines={2}>\n {`class ${clientName} {`}\n </Text>\n <Constructor serverUrl={serverUrl} sendOperations={sendOperations} />\n <Connect language=\"javascript\" title={title} />\n <RegisterMessageHandler \n language=\"javascript\" \n methodParams={['handler']}\n />\n <RegisterErrorHandler\n language=\"javascript\" \n methodParams={['handler']}\n />\n <HandleMessage \n language=\"javascript\" \n methodParams={['message', 'cb']}\n />\n <CompileOperationSchemas sendOperations={sendOperations} />\n <SendOperations \n language=\"javascript\" \n sendOperations={sendOperations} \n clientName={clientName} \n />\n <CloseConnection language=\"javascript\" />\n <Text>\n {'}'}\n </Text>\n <ModuleExport clientName={clientName} />\n </Text>\n );\n}\n","import { File } from '@asyncapi/generator-react-sdk';\nimport { getClientName, getServerUrl, getServer, getInfo, getTitle } from '@asyncapi/generator-helpers';\nimport { FileHeaderInfo, DependencyProvider } from '@asyncapi/generator-components';\nimport { ClientClass } from '../components/ClientClass';\n\nexport default function ({ asyncapi, params }) {\n const server = getServer(asyncapi.servers(), params.server);\n const info = getInfo(asyncapi);\n const title = getTitle(asyncapi);\n const clientName = getClientName(asyncapi, params.appendClientSuffix, params.customClientName);\n const serverUrl = getServerUrl(server);\n const sendOperations = asyncapi.operations().filterBySend();\n const asyncapiFilepath = `${params.asyncapiFileDir}/asyncapi.yaml`;\n return (\n <File name={params.clientFileName}>\n <FileHeaderInfo\n info={info}\n server={server}\n language=\"javascript\"\n />\n <DependencyProvider\n language=\"javascript\"\n additionalDependencies={['const path = require(\\'path\\');', `const asyncapiFilepath = path.resolve(__dirname, '${asyncapiFilepath}');`]}\n />\n <ClientClass clientName={clientName} serverUrl={serverUrl} title={title} sendOperations={sendOperations} />\n </File>\n );\n}\n"],"names":["Constructor","serverUrl","sendOperations","sendOperationsId","map","operation","id","sendOperationsArray","JSON","stringify","_jsx","Text","indent","children","ModuleExport","clientName","CompileOperationSchemas","length","_Fragment","newLines","ClientClass","title","_jsxs","Connect","language","RegisterMessageHandler","methodParams","RegisterErrorHandler","HandleMessage","SendOperations","CloseConnection","asyncapi","params","server","getServer","servers","info","getInfo","getTitle","getClientName","appendClientSuffix","customClientName","getServerUrl","operations","filterBySend","asyncapiFilepath","asyncapiFileDir","File","name","clientFileName","FileHeaderInfo","DependencyProvider","additionalDependencies"],"mappings":";;;;;;;;AAEO,SAASA,WAAWA,CAAC;EAAEC,SAAS;AAAEC,EAAAA,cAAAA;AAAe,CAAC,EAAE;AACzD,EAAA,MAAMC,gBAAgB,GAAGD,cAAc,CAACE,GAAG,CAAEC,SAAS,IAAKA,SAAS,CAACC,EAAE,EAAE,CAAC,CAAA;AAC1E,EAAA,MAAMC,mBAAmB,GAAGC,IAAI,CAACC,SAAS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AEA,KAAM;AAACnB,MAAAA,cAAc,EAAEA,cAAAA;AAAe,KAAE,CAAC,CAAA;AAAA,GACvG,CAAC,CAAA;AAEX;;;;"}
|
|
1
|
+
{"version":3,"file":"client.js.js","sources":["../../../../../../../../packages/templates/clients/websocket/javascript/components/Constructor.js","../../../../../../../../packages/templates/clients/websocket/javascript/components/ModuleExport.js","../../../../../../../../packages/templates/clients/websocket/javascript/components/CompileOperationSchemas.js","../../../../../../../../packages/templates/clients/websocket/javascript/components/ClientClass.js","../../../../../../../../packages/templates/clients/websocket/javascript/template/client.js.js"],"sourcesContent":["import { Text } from '@asyncapi/generator-react-sdk';\n\nexport function Constructor({ serverUrl, sendOperations }) {\n const sendOperationsId = sendOperations.map((operation) => operation.id());\n const sendOperationsArray = JSON.stringify(sendOperationsId);\n\n return (\n <Text indent={2}>\n {\n `/*\n * Constructor to initialize the WebSocket client\n * @param {string} url - The WebSocket server URL. Use it if the server URL is different from the default one taken from the AsyncAPI document.\n*/\nconstructor(url) {\n this.url = url || '${serverUrl}';\n this.websocket = null;\n this.messageHandlers = [];\n this.errorHandlers = [];\n this.compiledSchemas = {};\n this.schemasCompiled = false;\n this.sendOperationsId = ${sendOperationsArray};\n}\n`\n }\n </Text>\n );\n}\n","import { Text } from '@asyncapi/generator-react-sdk';\n\nexport function ModuleExport({ clientName }) {\n return (\n <Text>\n {\n `module.exports = ${clientName};`\n }\n </Text>\n );\n}\n","import { Text } from '@asyncapi/generator-react-sdk';\n\nexport function CompileOperationSchemas({ sendOperations }) {\n if (!sendOperations || sendOperations.length === 0) {\n return null;\n } \n\n return (\n <>\n <Text indent={2} newLines={2}>\n {\n `/**\n * Initialize and compile all schemas for operations defined.\n * This should be called once after creating the client instance.\n * Subsequent calls will be ignored if schemas are already compiled.\n * \n * @returns {Promise<void>}\n * @throws {Error} If schema compilation fails for any operation\n */\nasync compileOperationSchemas() {\n if (this.schemasCompiled) {\n return;\n }\n\n try {\n // Compile schemas for all send operations\n for (const operationId of this.sendOperationsId) {\n this.compiledSchemas[operationId] = await compileSchemasByOperationId(asyncapiFilepath, operationId);\n }\n this.schemasCompiled = true;\n console.log('Schemas initialized successfully for operations:', this.sendOperationsId.join(', '));\n } catch (error) {\n console.error('Error initializing schemas:', error);\n this.schemasCompiled = false;\n if (error instanceof Error) {\n error.message = \\`Schema compilation failed: \\${error.message}\\`;\n throw error;\n } else {\n throw new Error(\\`Schema compilation failed: \\${String(error)}\\`);\n }\n }\n}`\n }\n </Text>\n </>\n );\n}\n","import { Text } from '@asyncapi/generator-react-sdk';\nimport { Constructor } from './Constructor';\nimport { CloseConnection, RegisterMessageHandler, RegisterErrorHandler, SendOperations, Connect, HandleMessage } from '@asyncapi/generator-components';\nimport { ModuleExport } from './ModuleExport';\nimport { CompileOperationSchemas } from './CompileOperationSchemas';\n\nexport function ClientClass({ clientName, serverUrl, title, sendOperations }) {\n return (\n <Text>\n <Text newLines={2}>\n {`class ${clientName} {`}\n </Text>\n <Constructor serverUrl={serverUrl} sendOperations={sendOperations} />\n <Connect language=\"javascript\" title={title} />\n <RegisterMessageHandler \n language=\"javascript\" \n methodParams={['handler']}\n />\n <RegisterErrorHandler\n language=\"javascript\" \n methodParams={['handler']}\n />\n <HandleMessage \n language=\"javascript\" \n methodParams={['message', 'cb']}\n />\n <CompileOperationSchemas sendOperations={sendOperations} />\n <SendOperations \n language=\"javascript\" \n sendOperations={sendOperations} \n clientName={clientName} \n />\n <CloseConnection language=\"javascript\" />\n <Text>\n {'}'}\n </Text>\n <ModuleExport clientName={clientName} />\n </Text>\n );\n}\n","import { File } from '@asyncapi/generator-react-sdk';\nimport { getClientName, getServerUrl, getServer, getInfo, getTitle } from '@asyncapi/generator-helpers';\nimport { FileHeaderInfo, DependencyProvider } from '@asyncapi/generator-components';\nimport { ClientClass } from '../components/ClientClass';\n\nexport default function ({ asyncapi, params }) {\n const server = getServer(asyncapi.servers(), params.server);\n const info = getInfo(asyncapi);\n const title = getTitle(asyncapi);\n const clientName = getClientName(asyncapi, params.appendClientSuffix, params.customClientName);\n const serverUrl = getServerUrl(server);\n const sendOperations = asyncapi.operations().filterBySend();\n const asyncapiFilepath = `${params.asyncapiFileDir}/asyncapi.yaml`;\n return (\n <File name={params.clientFileName}>\n <FileHeaderInfo\n info={info}\n server={server}\n language=\"javascript\"\n />\n <DependencyProvider\n language=\"javascript\"\n additionalDependencies={['const path = require(\\'path\\');', `const asyncapiFilepath = path.resolve(__dirname, '${asyncapiFilepath}');`]}\n />\n <ClientClass clientName={clientName} serverUrl={serverUrl} title={title} sendOperations={sendOperations} />\n </File>\n );\n}\n"],"names":["Constructor","serverUrl","sendOperations","sendOperationsId","map","operation","id","sendOperationsArray","JSON","stringify","_jsx","Text","indent","children","ModuleExport","clientName","CompileOperationSchemas","length","_Fragment","newLines","ClientClass","title","_jsxs","Connect","language","RegisterMessageHandler","methodParams","RegisterErrorHandler","HandleMessage","SendOperations","CloseConnection","asyncapi","params","server","getServer","servers","info","getInfo","getTitle","getClientName","appendClientSuffix","customClientName","getServerUrl","operations","filterBySend","asyncapiFilepath","asyncapiFileDir","File","name","clientFileName","FileHeaderInfo","DependencyProvider","additionalDependencies"],"mappings":";;;;;;;;AAEO,SAASA,WAAWA,CAAC;EAAEC,SAAS;AAAEC,EAAAA,cAAAA;AAAe,CAAC,EAAE;AACzD,EAAA,MAAMC,gBAAgB,GAAGD,cAAc,CAACE,GAAG,CAAEC,SAAS,IAAKA,SAAS,CAACC,EAAE,EAAE,CAAC,CAAA;AAC1E,EAAA,MAAMC,mBAAmB,GAAGC,IAAI,CAACC,SAAS,CAACN,gBAAgB,CAAC,CAAA;EAE5D,oBACEO,cAAA,CAACC,sBAAI,EAAA;AAACC,IAAAA,MAAM,EAAE,CAAE;AAAAC,IAAAA,QAAA,EAEZ,CAAA;AACR;AACA;AACA;AACA;AACA,qBAAA,EAAuBZ,SAAS,CAAA;AAChC;AACA;AACA;AACA;AACA;AACA,0BAAA,EAA4BM,mBAAmB,CAAA;AAC/C;AACA,CAA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AAQ,CAAC,CAAA;AAC9B,EAAA,MAAMV,KAAK,GAAGiB,yBAAQ,CAACP,QAAQ,CAAC,CAAA;AAChC,EAAA,MAAMhB,UAAU,GAAGwB,8BAAa,CAACR,QAAQ,EAAEC,MAAM,CAACQ,kBAAkB,EAAER,MAAM,CAACS,gBAAgB,CAAC,CAAA;AAC9F,EAAA,MAAMxC,SAAS,GAAGyC,6BAAY,CAACT,MAAM,CAAC,CAAA;EACtC,MAAM/B,cAAc,GAAG6B,QAAQ,CAACY,UAAU,EAAE,CAACC,YAAY,EAAE,CAAA;AAC3D,EAAA,MAAMC,gBAAgB,GAAG,CAAA,EAAGb,MAAM,CAACc,eAAe,CAAgB,cAAA,CAAA,CAAA;EAClE,oBACExB,eAAA,CAACyB,sBAAI,EAAA;IAACC,IAAI,EAAEhB,MAAM,CAACiB,cAAe;IAAApC,QAAA,EAAA,cAChCH,cAAA,CAACwC,kCAAc,EAAA;AACbd,MAAAA,IAAI,EAAEA,IAAK;AACXH,MAAAA,MAAM,EAAEA,MAAO;AACfT,MAAAA,QAAQ,EAAC,YAAA;AAAY,KACtB,CAAC,eACFd,cAAA,CAACyC,sCAAkB,EAAA;AACjB3B,MAAAA,QAAQ,EAAC,YAAY;AACrB4B,MAAAA,sBAAsB,EAAE,CAAC,iCAAiC,EAAE,CAAA,kDAAA,EAAqDP,gBAAgB,CAAK,GAAA,CAAA,CAAA;AAAE,KACzI,CAAC,eACFnC,cAAA,CAACU,WAAW,EAAA;AAACL,MAAAA,UAAU,EAAEA,UAAW;AAACd,MAAAA,SAAS,EAAEA,SAAU;AAACoB,MAAAA,KAAK,EAAEA,KAAM;AAACnB,MAAAA,cAAc,EAAEA,cAAAA;AAAe,KAAE,CAAC,CAAA;AAAA,GACvG,CAAC,CAAA;AAEX;;;;"}
|
|
@@ -31,6 +31,13 @@ async compileOperationSchemas() {
|
|
|
31
31
|
console.log('Schemas initialized successfully for operations:', this.sendOperationsId.join(', '));
|
|
32
32
|
} catch (error) {
|
|
33
33
|
console.error('Error initializing schemas:', error);
|
|
34
|
+
this.schemasCompiled = false;
|
|
35
|
+
if (error instanceof Error) {
|
|
36
|
+
error.message = \`Schema compilation failed: \${error.message}\`;
|
|
37
|
+
throw error;
|
|
38
|
+
} else {
|
|
39
|
+
throw new Error(\`Schema compilation failed: \${String(error)}\`);
|
|
40
|
+
}
|
|
34
41
|
}
|
|
35
42
|
}`
|
|
36
43
|
}
|
|
@@ -46,7 +46,7 @@ async function loadTemplateConfig(templateDir, templateParams) {
|
|
|
46
46
|
*/
|
|
47
47
|
function loadDefaultValues(templateConfig, templateParams) {
|
|
48
48
|
const parameters = templateConfig.parameters;
|
|
49
|
-
const defaultValues = Object.keys(parameters || {}).filter(key =>
|
|
49
|
+
const defaultValues = Object.keys(parameters || {}).filter(key => Object.hasOwn(parameters[key], "default"));
|
|
50
50
|
|
|
51
51
|
defaultValues.filter(dv => !Object.prototype.hasOwnProperty.call(templateParams, dv)).forEach(dv =>
|
|
52
52
|
Object.defineProperty(templateParams, dv, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asyncapi/generator",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.2",
|
|
4
4
|
"description": "The AsyncAPI generator. It can generate documentation, code, anything!",
|
|
5
5
|
"main": "./lib/generator.js",
|
|
6
6
|
"engines": {
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"@asyncapi/generator-hooks": "*",
|
|
54
54
|
"@asyncapi/generator-react-sdk": "*",
|
|
55
55
|
"@asyncapi/multi-parser": "^2.2.0",
|
|
56
|
-
"@asyncapi/parser": "^3.
|
|
56
|
+
"@asyncapi/parser": "^3.6.0",
|
|
57
57
|
"@npmcli/arborist": "5.6.3",
|
|
58
58
|
"@npmcli/config": "^8.0.2",
|
|
59
59
|
"ajv": "^8.12.0",
|