However, this is not accessed in the self.model_dump method of a pydantic Model. self.model_json_schema() exports descriptions, but they are in a JSON schema, which can not be immediately parsed to the config file.
From the JSON schema, sections and options can be extracted and a custom dictionary created.
Pydantic
fields have the possibility to specify descriptions https://docs.pydantic.dev/latest/concepts/fields/#customizing-json-schemaHowever, this is not accessed in the
self.model_dump
method of a pydantic Model.self.model_json_schema()
exports descriptions, but they are in a JSON schema, which can not be immediately parsed to the config file.From the JSON schema, sections and options can be extracted and a custom dictionary created.
To insert comments into cfg files with configparser, see https://stackoverflow.com/a/19432072