Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

NeevCohen
Copy link
Contributor

@NeevCohen NeevCohen commented Apr 7, 2024

Change Summary

Implement programmatic title generation via ConfigDict and Field

Related issue number

fix #4632

Checklist

  • The pull request title is a good summary of the changes - it will be used in the changelog
  • Unit tests for the changes exist
  • Tests pass on CI
  • Documentation reflects the changes where applicable
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

Selected Reviewer: @dmontagu

Copy link

codspeed-hq bot commented Apr 7, 2024

CodSpeed Performance Report

Merging #9183 will not alter performance

Comparing NeevCohen:feature/title-generators (2f5d5b0) with main (8aeac1a)

Summary

✅ 13 untouched benchmarks

@NeevCohen
Copy link
Contributor Author

Please review

Copy link
Member

@sydney-runkle sydney-runkle left a 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!

Comment on lines +224 to +225
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
Copy link
Member

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?

Comment on lines +1154 to +1157
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)

Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Title Generator to Support Programmatic Titles
3 participants