Commit Graph

40 Commits

Author SHA1 Message Date
Samuel Colvin 8301f9e4b2 dataclass validation (#334)
* dataclass validation, fix #273

* support for tuple or dict in dataclasses

* tweaks

* adding example in docs
2018-12-27 19:15:39 +00:00
jarekkar 72791787ea Add support for passing Configs to Dataclasses (#285)
* Add support for passing Configs to Dataclasses

* formatting and fixes

* move tests into dataclasses_config.py

* use inherit_config in create_model

fix #276
2018-12-27 17:54:17 +00:00
Samuel Colvin 7a06736ead Add additional parameters to Schema for validation and annotation (#319)
* 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
2018-12-03 12:37:39 +00:00
Jason Kuhrt a0aa9e78cd feat: add support for case insensitive env names (#313)
* feat: add support for case insensitive env names

Closes #277

* feedback: just alias os.environ

* doc: update history

* doc: mention case_insensitive option

* refactor: feedback if-else expression assignment

* fix: formatting

* chore: encode black configuration in file to support IDEs

* docs: fix example

* feedback: no suppport for IDEs in this PR

* feedback: style
2018-11-26 14:57:09 +00:00
Sebastián Ramírez 94706bc834 JSON Schema update/refactor/augment, to conform to spec (#308)
* Update schema tests to conform to JSON Schema spec

* Add JSON Schema tests for all supported types

including datetime and all supported Pydantic.types

* Add JSON Schema conforming schema sub module

* Update BaseModel to use schema module for JSON Schema generation

and update/simplify internal Schema methods

* Remove Schema code from Field class, replaced with JSON Schema module

* Add submodules to test model name generation for JSON Schemas

* Refactor/rewrite schema module to generate definions and refs

* Update and augment JSON Schema tests to include definitions and refs

and generation of a single JSON Schema with definitions from multiple (unrelated) models

* Add ref_prefix functionality to JSON Schema generation functions

* Test custom ref_prefix in JSON Schema generation

* Remove un-used BaseModel method, now refactored to schema module

* Update formating of test_schema

* Fix long lines in test_schema

* Fix imported but unused in fields

* Fix imported but unused in main.py

* Ignore imported but unused for testing modulec

* Refactor schema module for complexity

* Add conflicting name model to raise coverage

* Add conflicting model to test other flow and raise coverage

* Ignore complexity as destructuring more would make it more complex

and more difficult to understand, similar to .fields.validate

* Fix import sorting

* Update formatting with black, with CI settings

* Fix test for schemas with email validation

* Check if field is class before checking if is subclass

* Improve schema error when using unsuported types

* Add additional tests for corner cases, raise coverage to 100%

* Rename BaseModel.schema_json to schema_str (EAFP Python style)

* Add more tests to utils.display_as_type to increase the coverage for enums

* Remove unused catched error in schema tests

* Fix formatting with black

* Update docs schema example

* Add schema examples for top-level schema with multiple models

* Update docs, section Schema, with new JSON Schema generation details

* Update docs, history, with new features

* Update fields, remove unnecessary schema code for enums

* Update docs, fix links and typos in Schema section

* Trigger CI, as Python 3.7-dev seems to have random CI errors

* Revert Model.schema_str to Model.schema_json as requested

* Remove unnecessary assert in schema module as requested

* Remove annotations in internal functions, as requested

* Refactor get_flat_models_from_fields and reuse

* Use set short assignment syntax in schema module

* Remove unwanted assertion

* Make get_long_model_name a single line f-string

* Update model_name_map, add docstring and remove first return value

* Simplify dict operation in get_model_name_map as requested

* Make more concise model_name_map computation

* Remove bool from field check in schema as is subclass of int

* Make ref_prefix default to None and use global default

* Fix formatting for schema.py

* Refactor field_singleton_schema to use data structures

* Move main functions to top of schema, and add docstrings for them

* Implement __all__, move and order parts of schema

* Remove schema testing sub-package code as requested

* Generate schema testing subpackage in code

* Update schema tests with several related fields to use parametrized pytest

* Fix formatting and imports I missed after rebase

* Fix new formatting errors from CI

* Re-trigger Travis CI, Python 3.7-dev random error again, no re-run click in Travis for non owners

* Trigger annotation error with non-forward references

* Add docstrings for submodel schema

* tweaks and rewrite schema mapping table in python

* support complex defaults

* use str not int as dict keys

* Fix links to JSON Schema and OpenAPI
2018-11-22 16:00:06 +00:00
Samuel Colvin f3a278bb8d Dataclasses (#269)
* pydantic.dataclasses.dataclass decorator

* add dataclasses to requirnment.txt

* reimplement dataclasses

* fix linting, fix coverage

* docs
2018-10-01 09:48:28 +01:00
Stefan Gangefors c32ce342c9 Add support for deep copying of models (#261)
Using `model.copy(deep=True)` will deep copy a module instance.

Making a deep copy is useful for models that have lists of dicts or
any other non-simple data structure to not accidentally modify data
between instances.

`model.copy()` behaviour is unchanged and will do a shallow copy of
the model instance.

fix #249
2018-09-10 11:35:58 -04:00
Samuel Colvin c7c15bc415 fix json documentation (#253) 2018-08-29 10:38:02 +01:00
Samuel Colvin f46dc0c56f timedelta json encoding (#247)
* timedelta json encoding, altnative to #220

* history and tests

* fix comments and tests

* docs for json_encoders

* tests plain timedelta object parsing

* uprev

* tweak docs
2018-08-25 17:06:32 +01:00
Nikita Grishko aad175a25f add `UrlStr and urlstr` types #236 (#246)
fix #236

* add ``UrlStr`` and ``urlstr`` types #236

* review fixes
2018-08-20 10:14:46 +01:00
Evghenii Goncearov a0e0aa4f79 Docs for json type (#228) 2018-07-11 15:08:51 +01:00
Samuel Colvin 1dc294015d cleaning up _populate_sub_fields, support tuples (#227)
* cleaning up _populate_sub_fields

* support tuples, fix #12

* fix, history and docs

* rename _create_sub_type
2018-07-10 18:45:15 +01:00
Nikita Grishko d43ab483ee fix schema creation docs (#212)
* fix schema creation docs

* review fixes
2018-06-30 23:06:39 +01:00
Samuel Colvin 37364a05b9 implement JSON serialisation (#210)
* implement JSON serialisation, fix #133

* documenting JSON serialisation

* fix coverage
2018-06-28 18:21:45 +01:00
Samuel Colvin dd8d013e10 Schemas (#190)
* starting field and model schemas

* field.schema()

* sub-models working

* move default in Schema and tests

* adding schema

* tweak docs
2018-06-28 13:06:24 +01:00
Nikita Grishko f8c1a350f4 add `FilePath and DirectoryPath` types #10 (#208)
* add ``FilePath`` and ``DirectoryPath`` types #10

* review fixes

* improve tests

* simplify errors
2018-06-28 11:04:00 +01:00
clip d2745065f5 fix typo (#207)
* fix typo

* fix test
2018-06-24 17:52:56 +01:00
Samuel Colvin 9338c413c7 remove msgpack (#201)
* remove msgpack

* update history
2018-06-18 12:20:10 +01:00
Samuel Colvin f0f9de5f96 improve docs on error handling (#198)
* improve docs on error handling

* change ValidationError signature

* cleanup

* rename _raw_errors > raw_errors

* improve _display_error_type_and_ctx
2018-06-11 13:06:50 +01:00
Jasper Schulz 3ef595556c Added le and ge bounds to constrained numerics. (#194)
* Added `le` and `ge` bounds to constrained numerics.

* Addressed comments.

* Addressed @Gr1N comments.

* Removed comment.
2018-06-08 10:32:26 +01:00
Nikita Grishko 3f53cb5980 Update documentation (#162) (#189)
* Update documentation (#162)

* More docs about error handling
2018-06-04 10:55:48 +01:00
Nikita Grishko 99d7eafa61 add `Decimal, ConstrainedDecimal and condecimal` types #170 (#175) 2018-05-10 12:11:45 +01:00
Nikita Grishko b4d3a2d544 add `UUID1, UUID3, UUID4 and UUID5` types (#167) (#167) 2018-05-02 22:49:55 +01:00
Nikita Grishko dc07277017 add `ConstrainedFloat, confloat, PositiveFloat and NegativeFloat` types #166 (#166) 2018-04-28 18:40:28 +01:00
Nikita Grishko f88e5925b5 add strip_whitespace option for ConstrainedStr and constr (#163) 2018-04-25 02:29:25 +07:00
clip cfb1057ae6 add document about "custom data types" (#157) 2018-04-16 19:32:50 +01:00
Samuel Colvin f9cf6b42f4 Create model method (#125)
* adding create_model method

* adding  method

* docs and tweaks

* prevent config and base together

* tweak docs
2018-02-06 14:29:56 +00:00
Josep Cugat 06008146fe Subclass abcmeta (#123)
* Added compatibility with python's ABC

* Added documentation

* Added link
2018-02-06 13:56:45 +00:00
Samuel Colvin acf3128dcd Validator always (#102)
* validators called always, fix #100

* testing validate always validators

* adding docs
2017-11-08 14:37:01 +00:00
Samuel Colvin 91f962e533 replace values() with dict() (#99)
* replace values(), with dict(), fix #98

* add history and test
2017-11-07 13:28:42 +00:00
Samuel Colvin dfc5924936 Better validators (#97)
* working on improved validators

* full tests for validators

* tweask

* tweaking fields.py

* adding docs

* add history

* fix classmethod validators
2017-11-07 13:06:44 +00:00
Samuel Colvin 02dc2f2697 allow json env vars (#96)
* allow json env vars

* add docs
2017-11-07 11:26:16 +00:00
Samuel Colvin b10566841e Less verbose errors (#90)
* make errors less verbose, fix #71

* remove track too if null

* update docs

* better dict error, fix #74

* add history
2017-10-23 20:06:48 +01:00
Samuel Colvin 5cf23fb415 Uuid type (#89)
* adding UUID validator, fix #65

* add docs

* uprev
2017-10-23 19:49:52 +01:00
Samuel Colvin 044fd42f4f parser methods (#58), fix #39
* working on parsers

* starting parse tests

* proper tests for parse

* adding parse docs

* tweaks and history

* add test for datetime direct, fix tests

* tweak docs
2017-07-08 18:39:24 +01:00
Samuel Colvin 92d7689271 Immutability part 2 (#53)
* add construct method, fix #48
* adding copy method
* adding pickle support, fix #40
* tweak copy and add fields copy test
* adding docs for immutability, values and copy
* add docs for pickle
2017-06-21 18:15:08 +01:00
Samuel Colvin 6923e5e677 models allowing immutability (#44)
* working on models allowing immutability, ref #38

* up complexity

* use noqa c901

* fixing fields with new processor

* allow_mutation config and tests

* uprev, history and docs

* fix typos
2017-06-13 09:52:47 +01:00
Samuel Colvin ff3fa95eb0 convert values to a function, fix #28 (#43) 2017-06-07 22:40:09 +01:00
Samuel Colvin e945a2afcf use annotation only declaration in first example 2017-06-07 20:07:38 +01:00
Samuel Colvin c81ec9aeec add support for annotation only fields (#41)
* add support for annotation only fields, fix #34

* adding tests with mypy

* adding docs for mypy usage

* adding mypy failure test

* adding alias tests

* tweak mypy tests
2017-06-07 19:56:46 +01:00