-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for programmatic title generation #9183
base: main
Are you sure you want to change the base?
Changes from 9 commits
eea8462
7edfd87
2f5d5b0
67240e2
823d3d5
939c7a1
b2e5dad
306ae09
428463e
838b0c9
e12c5a2
eff9e02
070fef1
712a026
39a4dd4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,11 +33,18 @@ class ConfigDict(TypedDict, total=False): | |
title: str | None | ||
"""The title for the generated JSON schema, defaults to the model's name""" | ||
|
||
class_title_generator: Callable[[str], str] | None | ||
"""A callable that takes a class name and returns the title for it. Defaults to `None`.""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should be clear about whether this works for:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It works for all model and model-like (pydantic dataclass, builtin dataclass, typeddict) types. I will add more documentation if you feel it's necessary. |
||
|
||
field_title_generator: Callable[[str], str] | None | ||
"""A callable that takes a field name and returns title for it. Defaults to `None`.""" | ||
|
||
str_to_lower: bool | ||
"""Whether to convert all characters to lowercase for str types. Defaults to `False`.""" | ||
|
||
str_to_upper: bool | ||
"""Whether to convert all characters to uppercase for str types. Defaults to `False`.""" | ||
|
||
str_strip_whitespace: bool | ||
"""Whether to strip leading and trailing whitespace for str types.""" | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my main question is whether the full field should be passed to the function, not just the name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The full field as in the
FieldInfo
object? That we need to pass bothFieldInfo
and the name of the field sinceFieldInfo
doesn't include the name.Then the signature of
make_title
would be