datamodel-code-generator icon indicating copy to clipboard operation
datamodel-code-generator copied to clipboard

Option to include `Example` attribute of model as Docstring in addition to `Field` keyword argument

Open santhoshramaraj opened this issue 2 years ago • 0 comments

I am using datamodel-code-generator to generate models to go along with Uplink to create REST clients. My REST API documentation is in OpenAPI yaml format and includes examples for field values. These example values are useful for the API client users to understand the field value and formats.

VSCode and other IDE with intellisense pick up the doc string to display help on a function and its arguments.

The values of Example field in the OpenAPI documents are translated as Field(example='your example here') which benefits if the model is dumped as JSON schema but fails in the goal of guiding the user during development.

The ideal solution would incorporate the example field as part of docstring and thereby show up in intellisense.

If adopted, this feature adds an argument example_as_docstring to datamodel_code_generator.generate() and an option --use-field-description-example to CLI

santhoshramaraj avatar Nov 14 '23 03:11 santhoshramaraj