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?
Conversation
CodSpeed Performance ReportMerging #9183 will not alter performanceComparing Summary
|
Please review |
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.
Hey @NeevCohen,
Great work, as usual!
I want to look again at _generate_schema.py
and do a more in-depth look at your tests (great work btw, looks very thorough). This looks very promising though - I've included some initial feedback / some minor change requests.
One other change I'd like to see is the addition of some documentation in the concepts
section of our docs!
self.field_title_generator = kwargs.pop('field_title_generator', None) | ||
self.title_priority = kwargs.pop('title_priority', None) or 2 if self.title is not None else None |
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.
Very minor nit - can we order these in the same order as seen in the attribute docstring?
field_title_generator = field_info.field_title_generator or self._config_wrapper.field_title_generator | ||
if field_title_generator is not None: | ||
self._apply_field_title_generator_to_field_info(field_title_generator, field_info, 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.
Looks like we repeat this exact same logic 3x at least, maybe use a function to abstract away some of this?
) -> JsonSchemaValue: | ||
"""Add title and description for model-like classes' JSON schema. | ||
|
||
Args: | ||
schema_or_field: The schema data to generate a JSON schema from. | ||
handler: The `GetCoreSchemaHandler` instance. | ||
cls: The model-like class. | ||
title: The title to set for the model's schema, defaults to the models 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.
title: The title to set for the model's schema, defaults to the models name | |
title: The title to set for the model's schema, defaults to the model's name |
Change Summary
Implement programmatic title generation via
ConfigDict
andField
Related issue number
fix #4632
Checklist
Selected Reviewer: @dmontagu