Add additional parameters to Schema for validation and annotation #311
Add additional parameters to Schema for validation and annotation, in a single declaration.
Integrates and uses
As a result, a current model created as:
from pydantic import BaseModel, constr, Schema class Foo(BaseModel): a: constr(min_length=2, max_length=10) = Schema('bar')
can also be created as:
from pydantic import BaseModel, Schema class Foo(BaseModel): a: str = Schema('bar', min_length=2, max_length=10)
by being able to declare
The generated JSON Schema will output validation keywords of
For numbers validations like
Other option for the parameters would be to use the literal name used in JSON Schema, as
And other option would be using JSON Schema names and change them to snake-case, as
But I imagine the preferred option is to keep the same parameter names used in the rest of the code, as in
Specific parameters added to
The text was updated successfully, but these errors were encountered:
@@ Coverage Diff @@ ## json-schema-extra #311 +/- ## ================================================ Coverage 100% 100% ================================================ Files 13 14 +1 Lines 1708 1770 +62 Branches 323 338 +15 ================================================ + Hits 1708 1770 +62
Do you want me to mark as "resolved" the comments in the review that are already done?
I'm leaving them there so you can come back, check and confirm, before marking them as resolved. But let me know if you want me to mark the ones that are done and don't have a pending discussion.
* Add additional parameters to Schema for validation and annotation (#311) * Add tests for validation declared via Schema class in defaults * Add validations to field from declarations in Schema * Add annotations in generated JSON Schema from validations via Schema * Augment tests for schema generation * Simplify validations from Schema in fields, from coverage hints * Update schema test to use the spec plural "examples" * Add docs and simple example of the additional parameters for Schema * Update history * Fix number of PR in HISTORY * Refactor check for numeric types, remove break to make coverage happy * Fix typo in docs, I confused gt with maximum * Finish docstring for Schema (I had forgotten about it) * Implement code review requests and lenient_issubclass with tests * Move Schema to its now file to extract from fields.py but avoid circular imports * Control coverage * Schema fixes (#318) * rearrange code * cleanup get_annotation_from_schema * fix typo * rename _schema to schema