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

feat: Add descriptions, examples, and validations to pydantic fields #1335

Closed
wants to merge 1 commit into from

Conversation

romeonicholas
Copy link
Contributor

Resolves #1327

Adding descriptions, examples, and some validations to pydantic models. Figuring out the right balance has been a little complicated.

For 'description': A lot of these are self-evident, and I considered adding tags to indicate something the user enters (e.g. a model name is chosen by a user, but a model slug is derived and not directly modifiable) but that felt like it was getting too deep into implemenation and things that could change.

For 'examples': I've avoided including examples where they might be meaningless (any integer field), and used partial objects in place of full ones when it's reuse of a model created elsewhere (e.g. a partial user example on the event model, because the full user model is covered elsewhere).

For validations: So far I think I've only added them for user-inputted strings, with relatively arbitrary values that we should probably check against in production. We could potentially just add the limits to post and patch models, leaving existing overly-long offenders in place if we want to avoid a migration?

Still lots of fields left to work on.

Copy link

sonarcloud bot commented Feb 13, 2024

Quality Gate Passed Quality Gate passed

Issues
3 New issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

Copy link

codecov bot commented Feb 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (d6d256e) 73.22% compared to head (21442e3) 73.22%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1335   +/-   ##
=======================================
  Coverage   73.22%   73.22%           
=======================================
  Files         166      166           
  Lines        5431     5431           
  Branches      608      608           
=======================================
  Hits         3977     3977           
  Misses       1323     1323           
  Partials      131      131           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@romeonicholas
Copy link
Contributor Author

romeonicholas commented Feb 13, 2024

Note to future self: be more careful not to ignore default assignments and break the tests 😆
Assigning fields to something like name: str | None = None requires shifting the existing default into Field as in: name: str | None = Field(default=None, whateverElse="...")

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

Successfully merging this pull request may close these issues.

Improve API documentation with pydantic fields
2 participants