Skip to content

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

@santhoshramaraj

Description

@santhoshramaraj

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions