* introduce read_only Field constraint
* add changes markdown for read_only constraint
* add readOnly property to json schema generation
* Revert "add readOnly property to json schema generation"
This reverts commit dad3d3e23a7336aa978dcdedc157559ea102fa54.
* change read_only field constraint to allow_mutation
* Update change notes for allow_mutation
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
* allow field constraints defaults to be not None
* remove unnecessary test after constraint refactor
* push used constraints check back to schema functions
* use tuple item name descriptions instead of indexes
* move get_constraints function to method on FieldInfo
* address code review comments for minor changes
* Apply suggestions from code review
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
* fix merge conflict
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
* Fixed issue causing KeyError to be raised when building schema from multiple `BaseModel` with the same names declared in separate classes (#1912)
* Update test
* Removed redundant f-string
* Fixed formatting
* Fixed lint
* fix(fields): handle properly default value for type `Callable`
closes#1596
* chore: move test in test_dataclasses
* chore: add comments
* test: rewrite test
* chore: remove useless variable
* fix(schema): add support when callable field has default value
closes#2086
fix#2108
* Fix schema extra not being included when field type is Enum
* Code format
* More code format
* Add changes file
Co-authored-by: Ben Martineau <b.martineau@iwoca.co.uk>
* ignore Pipfile, .lock files
* add ref_template option
use a string.Template instead of a ref_prefix to allow for more varied`$ref`s to be created.
Template string is expected to have $model_name `identifier `
* formatting / linting
* add changes
* typo
* use string.format instead of string.Template
* remove ref_prefix default
if no `ref_prefix` provided, use the `template_default`
* use ref_template in field_singleton_schema
* fix test_schema_with_ref_template
* add parameters for `test_schema_with_refs`
test name change
test for key error
* provide ref_template default argument
* fix linting
* fix mypy and coverage
* docs and correct model_schema usage
* fastAPI tests actualy caught an error
* linting
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* refactor(schema): put schema data from fieldinfo in dedicated function
* feat(schema): support custom title, description and default for enums
closes#1748
* refactor: replace $ref by allOf + $ref to be supported by doc generation tools
* fix: do not set title by default for enums
* refactor: make code more explicit
* fix: run linter
* Apply __modify_schema__ on enum schema rather than fields that use it
Resolves#1576
* tweak test
* correct linting :-(
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* add frozenset to field_class_to_schema
* add change.md
* add my test
* format my test
* remove print()
* just test
* return to original code
Co-authored-by: wangpeibao <wangpeibao@troila.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* Updates schema() to generate enums as separate models
* Fixes mypy annotations
* Adds changes file
* Fixes comment
* Removes unused import
* Fixes test case
* Fixes missing partial branch in test coverage
* Resolves PR comments
* 🐛 Include enums in flat model schema handling
as they now have independent schemas, they kinda behave like top-level models, and should be taken into account for top level definitions
* ✅ Add test for coverage
* 🐛 Use Type[Enum] as type for consistency
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
* fix alias priority so alias_generators don't take priority
* improve test names
* remove debugs
* Apply suggestions from code review
* more tests and allow custom alias_priority on fields
* precedence tests and docs
* tweaks and add change
* suggestions
* ✨ Implement support for infinite generators with Iterable
* ✅ Add tests for infinite generators
* 🎨 Fix format
* 📝 Add docs for infinite generators
* 📝 Add changes file
* ✨ Store sub_field with original type parameter to allow custom validation
* 📝 Add example for validating first value in infinite generators
* 🔥 Remove unused import in example
* ✅ Add test for infinite generator with first-value validation
* ♻️ Update fields with code review
* 📝 Update example from code review
* 📝 Update docs and format from code review
* Pass model_class to schema_extra staticmethod
Resolves#1122
* Add changelog
* Apply suggestions from code review
Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>
* Fix import after rebase
* Fix test bug
* Use TypeError instead of assert as per review
* Rename var so declaration fits one one line
* tiny tweaks
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
* rename Schema to Field
* add Schema function with deprecation warning
* mypy tests and other tweaks
* tweaks and cleanup
* Update pydantic/fields.py
Co-Authored-By: Sebastián Ramírez <tiangolo@gmail.com>
* new URL parsing, fix#603, fix#541
* AnyUrl parts and more tests
* more coverage and db DSNs
* remove DSN methods
* tests for urlstr
* remove debug
* make AnyStr a subtype of str
* fix with cython
* rearranging networking code
* allowing international domains, cleanup
* support international domains
* better URL builder
* allow underscores in subdomains and domains
* tests for json and schema, max length
* urlstr > stricturl
* updating docs
* tweak docs examples
* tweak docs
* Make schema work for Literal and NewType, fix#646
* Fix test when typing_extensions not installed
* Make literal values fetching 3.6 compatible
* Rework to get around issues with Literal in python 3.6
* Make cython-compatible
* Use union for multiple allowed literal values
* Minor simplification of values-gathering
* Updated history
* support custom root types
* update HISTORY.rst for costom root types
* fix invalid arguments case
* remove the keyword argument of "__root__" in __init__
add a keyword argument of "__root__" in parse_obj
fix documents
create a method for cheking valid field name
* fix parse_obj
* Update docs/index.rst
Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>
* Apply suggestions from code review
Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>
* add type cheking for custom root type
* Update docs/index.rst
Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>
* Update index.rst
* Fix circular schema generation, remove None checking hack
* Include test written by @wongpat to make it run in CI
* Update History
* Update nested_models in-place
Co-Authored-By: Patrick Wong <wongpat@users.noreply.github.com>
* Update nested_models in-place
Co-Authored-By: Patrick Wong <wongpat@users.noreply.github.com>
* Update nested_models in place everywhere for consistency