-
-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
1,123 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const models = require('./models'); | ||
|
||
module.exports = { | ||
models, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { File } from '@asyncapi/generator-react-sdk'; | ||
import { PythonGenerator, JavaGenerator, TypeScriptGenerator, FormatHelpers } from '@asyncapi/modelina'; | ||
|
||
/** | ||
* @typedef {'python' | 'java' | 'typescript'} Language | ||
* Represents the available programming languages for model generation. | ||
*/ | ||
|
||
/** | ||
* @typedef RenderArgument | ||
* @type {object} | ||
* @property {AsyncAPIDocument} asyncapi AsyncAPI document object received from the generator after initial parsing with parser-js. | ||
* @property {Language} [language='python'] The target programming language for the generated models. | ||
*/ | ||
|
||
/** | ||
* Mapping of language strings to Modelina generator classes and file extensions. | ||
*/ | ||
const generatorConfig = { | ||
python: { generator: PythonGenerator, extension: 'py' }, | ||
java: { generator: JavaGenerator, extension: 'java' }, | ||
typescript: { generator: TypeScriptGenerator, extension: 'ts' }, | ||
}; | ||
|
||
/** | ||
* Render all schema models | ||
* @param {RenderArgument} param0 | ||
* @returns {Array<File>} Array of File components with generated model content. | ||
*/ | ||
export default async function models({ asyncapi, language = 'python' }) { | ||
// Get the selected generator and file extension, defaulting to Python if unknown | ||
const { generator: GeneratorClass, extension } = generatorConfig[language] || generatorConfig.python; | ||
const generator = new GeneratorClass(); | ||
|
||
const models = await generator.generate(asyncapi); | ||
const files = []; | ||
|
||
for (const model of models) { | ||
const modelFileName = `${FormatHelpers.toPascalCase(model.modelName)}.${extension}`; | ||
files.push(<File name={modelFileName}>{model.result}</File>); | ||
} | ||
|
||
return files; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "@asyncapi/generator-components", | ||
"version": "1.0.0", | ||
"description": "Package with reusable components for generation using React render engine", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/asyncapi/generator/apps/components" | ||
}, | ||
"author": "Lukasz Gornicki", | ||
"license": "Apache-2.0", | ||
"dependencies": { | ||
"@asyncapi/generator-react-sdk": "^1.1.2", | ||
"@asyncapi/modelina": "^4.0.0-next.62" | ||
} | ||
} |
Oops, something went wrong.