Skip to content

Commit

Permalink
feat: add --pyDantic to cli for Python and Pydantic preset (#2058)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pike authored Jun 22, 2024
1 parent 6a861bc commit 64d7342
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
20 changes: 17 additions & 3 deletions modelina-cli/src/helpers/python.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions modelina-cli/test/integration/generate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 64d7342

Please sign in to comment.