Skip to content

Fix Outputted Model JSON Schema for Sequence type#9303

Merged
sydney-runkle merged 5 commits intopydantic:mainfrom
anesmemisevic:fix/model-json-schema-from-sequence
Apr 28, 2024
Merged

Fix Outputted Model JSON Schema for Sequence type#9303
sydney-runkle merged 5 commits intopydantic:mainfrom
anesmemisevic:fix/model-json-schema-from-sequence

Conversation

@anesmemisevic
Copy link
Copy Markdown
Contributor

@anesmemisevic anesmemisevic commented Apr 23, 2024

Change Summary

Fixing an issue where the outputted JSON Schema, for the Sequence type, used minLength rather than minItems.
Fixed the same for maxLength - maxItems in advance.
Provided tests for the relevant changes.

Related issue number

fix #9256

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: @davidhewitt

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 23, 2024

CodSpeed Performance Report

Merging #9303 will not alter performance

Comparing anesmemisevic:fix/model-json-schema-from-sequence (eb615cb) with main (2612947)

Summary

✅ 13 untouched benchmarks

@anesmemisevic
Copy link
Copy Markdown
Contributor Author

please review

Copy link
Copy Markdown
Collaborator

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Thanks for the fix! I have one thought, I wonder what you think of it?

Comment thread pydantic/_internal/_known_annotated_metadata.py Outdated
@sydney-runkle sydney-runkle added the relnotes-fix Used for bugfixes. label Apr 23, 2024
Copy link
Copy Markdown
Collaborator

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

This looks good to me, thanks!

@sydney-runkle
Copy link
Copy Markdown
Contributor

Thanks! Merging now :).

@sydney-runkle sydney-runkle merged commit c4d2edc into pydantic:main Apr 28, 2024
evals-gic pushed a commit to evals-gic/pydantic that referenced this pull request Feb 11, 2026
Add _get_schema_type_for_js_update() helper function to determine effective
schema type for JSON schema constraint keys. Update min_length and max_length
handlers to use minItems/maxItems for sequence types (list, tuple, set,
frozenset, generator) and minLength/maxLength for text types (str, bytes,
url, multi-host-url).

Fixes pydantic#9303
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When using min_length on Sequence field, outputted JSON schema is minLength instead of minItems for array type

3 participants