Commit Graph

5 Commits

Author SHA1 Message Date
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
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
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