diff --git a/modelina-cli/src/helpers/python.ts b/modelina-cli/src/helpers/python.ts index ec2aaa284d..d469ce66a4 100644 --- a/modelina-cli/src/helpers/python.ts +++ b/modelina-cli/src/helpers/python.ts @@ -1,7 +1,15 @@ -import { PythonFileGenerator } from "@asyncapi/modelina"; +import { Flags } from "@oclif/core"; +import { PYTHON_PYDANTIC_PRESET, PythonFileGenerator } from "@asyncapi/modelina"; import { BuilderReturnType } from "./generate"; -export const PythonOclifFlags = { } +export const PythonOclifFlags = { + pyDantic: Flags.boolean({ + description: 'Python specific, generate the Pydantic models.', + required: false, + default: false, + }), + + } /** * This function builds all the relevant information for the main generate command @@ -10,7 +18,13 @@ export const PythonOclifFlags = { } * @returns */ export function buildPythonGenerator(flags: any): BuilderReturnType { - const fileGenerator = new PythonFileGenerator(); + const {pyDantic} = flags; + const presets = []; + if (pyDantic) { + presets.push(PYTHON_PYDANTIC_PRESET); + } + + const fileGenerator = new PythonFileGenerator({presets}); const fileOptions = undefined; return { fileOptions, diff --git a/modelina-cli/test/integration/generate.test.ts b/modelina-cli/test/integration/generate.test.ts index 7d047eaf44..27f2138d6b 100644 --- a/modelina-cli/test/integration/generate.test.ts +++ b/modelina-cli/test/integration/generate.test.ts @@ -127,6 +127,16 @@ describe('models', () => { ); done(); }); + test + .stderr() + .stdout() + .command([...generalOptions, 'python', ASYNCAPI_V2_DOCUMENT, '--pyDantic']) + .it('works when --pyDantic is set', (ctx, done) => { + expect(ctx.stdout).to.contain( + 'Successfully generated the following models: ' + ); + done(); + }); }); describe('for Rust', () => {