Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support nested dataclass schema #474

Closed
NoAnyLove opened this issue Apr 15, 2019 · 1 comment

Comments

Projects
None yet
1 participant
@NoAnyLove
Copy link
Contributor

commented Apr 15, 2019

Thanks @pilosus for fixing the dataclass-based schema. This is a follow up for #408.

It raises a ValueError excpetion on dataclass-based schema that uses another dataclass-based model. For example,

from pydantic import UrlStr
from pydantic.dataclasses import dataclass

@dataclass
class NavbarButton:
    href: UrlStr

@dataclass
class Navbar:
    button: NavbarButton

print(Navbar.__pydantic_model__.schema())

It raises the following exception,

Traceback (most recent call last):
  File "demo_dataclass.py", line 14, in <module>
    print(Navbar.__pydantic_model__.schema())
  File "E:\Python36\lib\site-packages\pydantic\main.py", line 406, in schema
    s = model_schema(cls, by_alias=by_alias)
  File "E:\Python36\lib\site-packages\pydantic\schema.py", line 206, in model_schema
    model, by_alias=by_alias, model_name_map=model_name_map, ref_prefix=ref_prefix
  File "E:\Python36\lib\site-packages\pydantic\schema.py", line 490, in model_process_schema
    model, by_alias=by_alias, model_name_map=model_name_map, ref_prefix=ref_prefix
  File "E:\Python36\lib\site-packages\pydantic\schema.py", line 516, in model_type_schema
    f, by_alias=by_alias, model_name_map=model_name_map, ref_prefix=ref_prefix
  File "E:\Python36\lib\site-packages\pydantic\schema.py", line 258, in field_schema
    ref_prefix=ref_prefix,
  File "E:\Python36\lib\site-packages\pydantic\schema.py", line 465, in field_type_schema
    ref_prefix=ref_prefix,
  File "E:\Python36\lib\site-packages\pydantic\schema.py", line 685, in field_singleton_schema
    raise ValueError(f'Value not declarable with JSON Schema, field: {field}')
ValueError: Value not declarable with JSON Schema, field: button type=NavbarButton required

@NoAnyLove NoAnyLove referenced this issue Apr 15, 2019

Merged

Fix nested dataclass schema #475

4 of 4 tasks complete
@NoAnyLove

This comment has been minimized.

Copy link
Contributor Author

commented Apr 15, 2019

I tried to make a fix for it. The code change is in #475. Nott quite sure if the fix is elegant or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.