3

When pydantic model is created using class definition, the "description" attribute can be added to the JSON schema by adding a class docstring:

class account_kind(str, Enum):
    """Account kind enum."""
    regular = "r"
    premium = "p"

yields

"account_kind": {
  "title": "account_kind",
  "description": "Account kind enum.",
  "enum": ["r", "p"],
  "type": "string"
}

How do I add "description" when I use dynamic model creation via create_model?

company = create_model("company", **company_attributes)

1 Answer 1

0

Apparently, the most straightforward option is to add the docstring explicitly:

company = create_model("company", **company_attributes)
company.__doc__ = "Company description."
Sign up to request clarification or add additional context in comments.

2 Comments

Any ideas on how to set the description for the individual attributes, like it would have been done statically with: regular = pydantic.Field("r", description="some desc"?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.