Skip to content

Commit

Permalink
fix: fixes multi line descriptions for the pydantic preset in python
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethaasan committed Nov 2, 2023
1 parent 4c2eec1 commit 3e1d290
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/generators/python/presets/Pydantic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const PYTHON_PYDANTIC_CLASS_PRESET: ClassPresetType<PythonOptions> = {
? params.property.property.type
: `Optional[${params.property.property.type}]`;
const alias = params.property.property.originalInput['description']
? `alias='${params.property.property.originalInput['description']}'`
? `alias='''${params.property.property.originalInput['description']}'''`
: '';

return `${params.property.propertyName}: ${type} = Field(${alias})`;
Expand Down
34 changes: 34 additions & 0 deletions test/generators/python/presets/Pydantic.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {
PythonGenerator,
PYTHON_PYDANTIC_PRESET
} from '../../../../src/generators/python';

describe('PYTHON_PYDANTIC_PRESET', () => {
let generator: PythonGenerator;

beforeEach(() => {
generator = new PythonGenerator({
presets: [PYTHON_PYDANTIC_PRESET]
});
});

test('should render pydantic for class', async () => {
const doc = {
title: 'Test',
type: 'object',
properties: {
prop: {
description: `test
multi
line
description`,
type: 'string'
}
}
};

const models = await generator.generate(doc);
expect(models).toHaveLength(1);
expect(models[0].result).toMatchSnapshot();
});
});
11 changes: 11 additions & 0 deletions test/generators/python/presets/__snapshots__/Pydantic.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`PYTHON_PYDANTIC_PRESET should render pydantic for class 1`] = `
"class Test(BaseModel):
prop: Optional[str] = Field(alias='''test
multi
line
description''')
additionalProperties: Optional[dict[Any, Any]] = Field()
"
`;

0 comments on commit 3e1d290

Please sign in to comment.