add DTO object generator

This commit is contained in:
marys
2026-06-03 15:08:11 +02:00
parent 4daa2241c7
commit dd31750e1a
17 changed files with 190 additions and 3306 deletions
-2
View File
@@ -6,8 +6,6 @@
// return <File name="client.py">{asyncapi.info().title()}</File>
// }
import { File } from '@asyncapi/generator-react-sdk';
export default function ({ asyncapi }) {
+15 -3
View File
@@ -9,21 +9,33 @@
import { File } from '@asyncapi/generator-react-sdk';
import { PythonGenerator, FormatHelpers } from '@asyncapi/modelina';
export default function ({ asyncapi, params }) {
export default async function ({ asyncapi, params }) {
const channels = Object.keys(asyncapi.components());
let content = ''
for (const channel of channels) {
content += `# channel: ${channel}\n`
}
const pythonGenerator = new PythonGenerator();
const models = await pythonGenerator.generate(asyncapi);
const files = [];
for (const model of models) {
const modelFileName = `${FormatHelpers.toPascalCase(model.modelName)}.py`;
files.push(modelFileName);
}
return (
<File name="client2.py"># {asyncapi.info().title()}
{`\n`}
# {asyncapi.info().description()}
{`\n`}
{channels.map((ch) => `# channel: ${ch}\n`)}
{content}
# {channels.map((ch) => `# channel: ${ch}\n`)}
# {content}
# {'=========='}
# {files}
# {'=========='}
</File>
)
}
@@ -0,0 +1,13 @@
import { File } from '@asyncapi/generator-react-sdk';
import { PythonGenerator, FormatHelpers } from '@asyncapi/modelina';
export default async function schemaRender({ asyncapi }) {
const pythonGenerator = new PythonGenerator();
const models = await pythonGenerator.generate(asyncapi);
const files = [];
for (const model of models) {
files.push(model.model)
}
return <File name="debug.py">{JSON.stringify(models, null, 2)}</File>
}
@@ -0,0 +1,33 @@
// 1
import { File } from '@asyncapi/generator-react-sdk';
// 2
import { PythonGenerator, FormatHelpers } from '@asyncapi/modelina';
/**
* @typedef RenderArgument
* @type {object}
* @property {AsyncAPIDocument} asyncapi document object received from the generator.
*/
/**
* Render all schema models
* @param {RenderArgument} param0
* @returns
*/
// 3
export default async function schemaRender({ asyncapi }) {
// 4
const pythonGenerator = new PythonGenerator();
// 5
const models = await pythonGenerator.generate(asyncapi);
// 6
const files = [];
// 7
for (const model of models) {
// 8
const modelFileName = `${FormatHelpers.toPascalCase(model.modelName)}.py`;
// 9
files.push(<File name={modelFileName}>{model.result}</File>);
}
return files;
}