Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Always includeadditionalProperties: True for arbitrary dictionary schemas#11392

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

austinyu
Copy link
Contributor

@austinyuaustinyu commentedFeb 5, 2025
edited by Viicos
Loading

Change Summary

For following example, an extraadditionalProperties: True will be added to the existing json schema.

fromtypingimportAnyfrompydanticimportBaseModelclassModel(BaseModel):conditions:dict[str,Any]after=Model.model_json_schema()before= {"properties": {"conditions": {"title":"Conditions","type":"object"}},"required": ["conditions"],"title":"Model","type":"object",}assertafter== {"properties": {"conditions": {"additionalProperties":True,"title":"Conditions","type":"object",        }    },"required": ["conditions"],"title":"Model","type":"object",}

The same rule will be applied to all fields of the following model.

fromtypingimportAnyfromtypingimportDictfrompydanticimportBaseModelclassModel(BaseModel):ex3:dictex1:dict[str,Any]ex2:dict[Any,Any]ex4:Dictex5:Dict[str,Any]ex6:Dict[Any,Any]after=Model.model_json_schema()assertafter== {"properties": {"ex3": {"additionalProperties":True,"title":"Ex3","type":"object"},"ex1": {"additionalProperties":True,"title":"Ex1","type":"object"},"ex2": {"additionalProperties":True,"title":"Ex2","type":"object"},"ex4": {"additionalProperties":True,"title":"Ex4","type":"object"},"ex5": {"additionalProperties":True,"title":"Ex5","type":"object"},"ex6": {"additionalProperties":True,"title":"Ex6","type":"object"},    },"required": ["ex3","ex1","ex2","ex4","ex5","ex6"],"title":"Model","type":"object",}

Related issue number

fix#11318

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:@sydney-runkle

RobertCraigie reacted with heart emoji
@github-actionsgithub-actionsbot added the relnotes-fixUsed for bugfixes. labelFeb 5, 2025
@codspeed-hqCodSpeed HQ
Copy link

CodSpeed Performance Report

Merging#11392 willnot alter performance

Comparingaustinyu:addition-properties-true-json-schema (af34cf7) withmain (929e8f4)

Summary

✅ 45 untouched benchmarks

@github-actionsGitHub Actions
Copy link
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  pydantic
  json_schema.py
Project Total 

This report was generated bypython-coverage-comment-action

@austinyuaustinyu marked this pull request as ready for reviewFebruary 5, 2025 07:54
@austinyu
Copy link
ContributorAuthor

please review

pydantic-hooky[bot] reacted with thumbs up emoji

Copy link
Member

@ViicosViicos left a comment

Choose a reason for hiding this comment

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

This LGTM I'll merge soon if I don't see any objections

sydney-runkle reacted with thumbs up emoji
@sydney-runkle
Copy link
Contributor

Fine by me!

@ViicosViicos merged commitbf61067 intopydantic:mainFeb 7, 2025
54 checks passed
@austinyuaustinyu deleted the addition-properties-true-json-schema branchFebruary 11, 2025 07:19
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@ViicosViicosViicos approved these changes

Assignees

@sydney-runklesydney-runkle

Labels
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Always includeadditionalProperties: True for dictionary schemas
3 participants
@austinyu@sydney-runkle@Viicos

[8]ページ先頭

©2009-2025 Movatter.jp