From 2120e093b34e0a8d61dcebc4b9c3e2d8a4f3db40 Mon Sep 17 00:00:00 2001 From: Axel Hecht Date: Fri, 21 Jun 2024 13:03:27 +0200 Subject: [PATCH 1/2] feat: Add --pyDantic to cli for Python and Pydantic preset --- modelina-cli/src/helpers/python.ts | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) 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, From 6a5d89a7c035980e1ecb35051de818b4d4e2d5b9 Mon Sep 17 00:00:00 2001 From: Axel Hecht Date: Fri, 21 Jun 2024 16:17:50 +0200 Subject: [PATCH 2/2] test: integration test for --pyDantic flag --- modelina-cli/test/integration/generate.test.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) 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', () => {