capella-collab-manager icon indicating copy to clipboard operation
capella-collab-manager copied to clipboard

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

Open romeonicholas opened this issue 1 year ago • 3 comments

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.

romeonicholas avatar Feb 12 '24 06:02 romeonicholas

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

sonarqubecloud[bot] avatar Feb 13 '24 14:02 sonarqubecloud[bot]

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

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           

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Feb 13 '24 14:02 codecov[bot]

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="...")

romeonicholas avatar Feb 13 '24 14:02 romeonicholas