Eric Jolibois
81b13ff3b4
fix: rename schema util into schema_of ( #3547 )
2021-12-22 19:42:56 +00:00
Eric Jolibois
c834f3419d
Support discriminated union ( #2336 )
...
* feat: add discriminated union
* feat: add OpenAPI spec schema
* test: add basic example for generated schema
* test: add validation tests
* docs: add basic documentation
* fix: support ForwardRef
* test: add ForwardRef case
* fix: false positive lint error
https://github.com/PyCQA/pyflakes/pull/600
* improve error
* add schema/schema_json utils
* fix tests after merge
* refactor: add `discriminator` attribute to `FieldInfo`
* refactor: @cybojenix remarks
* fix schema with forward ref
* start nested
* feat: add allowed values in error message
* fix wrong check
Same example with
```
class FooDomainA(BaseModel):
__root__: Union[FooDomainAA, FooDomainAB]
```
(without a discriminator)
should obviously be valid
* test: add nested examples
* remove uncovered code as we don't need it
* docs: add nested example
* fix: support properly Annotated Field syntax
* support naked annotated
* fix: handle TypeError
* make error loc more explicit
* fix behaviour with basemodel instance as value
* support schema for dataclasses
* tweak examples
* refactor: context manager just around code that fails
* refactor: add docstring + tweak on `get_sub_types`
* refactor: move `get_discriminator_values` in `utils.py`
* refactor: create `MissingDiscriminator` and `InvalidDiscriminator`
* refactor: move logic in `_validate_discriminated_union`
* refactor: remove `DiscriminatedUnionConfig`
* docs: schema/schema_json
* tests: add tests with other `Literal` types
* update 3.10
* add schema docstring
* weird bug on 3.8 with `Literal[None]`
* bump to view docs & coverage
* bump to prompt tests
* move tests in dedicated file
* chore: rewording
* refactor: replace property by direct slot
* refactor: faster check
* refactor: missing discriminator
* refactor: change error to ConfigError
* refactor: use display_as_type
* fix: mypy
* fix: duplicate
* feat: handle alias
* feat: handle nested unions
* tweak first example
Co-authored-by: Samuel Colvin <s@muelcolvin.com >
2021-12-18 16:31:35 +00:00
PrettyWood
75859a9d58
feat(tools): add parse_raw_as util ( #1813 )
...
closes #1812
2020-10-09 10:35:07 +01:00
Kieran Darcy
9982eb43dd
Change BaseModel.parse_file to use Config.json_loads ( #1069 )
...
fix #1067
* Making json_loads available to parse_file
* Change BaseModel.parse_file to use Config.json_loads
* Update changes/1067-kierandarcy.md
Co-Authored-By: Samuel Colvin <samcolvin@gmail.com >
* Fixed some style issues and added missing test for parse_file_as
2019-12-03 15:05:27 +00:00
dmontagu
6564bbb4ce
Add parse_as_type function ( #934 )
...
* Add parse_as_type function
* Add changes
* Incorporate feedback
* Add naming tests
* Fix double quotes
* Fix docs example
* Reorder parameters; add dataclass and mapping tests
* Rename parse_as_type to parse_obj, and add parse_file
* Incorporate feedback
* Incorporate feedback
* use custom root types
2019-11-25 12:55:15 +00:00