Skip to content

Commit

Permalink
(fix) use right type check when modifying schema (#1562)
Browse files Browse the repository at this point in the history
fix #1552
  • Loading branch information
PrettyWood committed Jun 27, 2020
1 parent c59db27 commit 7ac9faf
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions changes/1552-PrettyWood.md
@@ -0,0 +1 @@
Call `__modify_schema__` only for the field schema
2 changes: 1 addition & 1 deletion pydantic/schema.py
Expand Up @@ -239,7 +239,7 @@ def get_field_schema_validations(field: ModelField) -> Dict[str, Any]:
f_schema['const'] = field.default
if field.field_info.extra:
f_schema.update(field.field_info.extra)
modify_schema = getattr(field.type_, '__modify_schema__', None)
modify_schema = getattr(field.outer_type_, '__modify_schema__', None)
if modify_schema:
modify_schema(f_schema)
return f_schema
Expand Down
4 changes: 3 additions & 1 deletion tests/test_schema.py
Expand Up @@ -1822,15 +1822,17 @@ def __modify_schema__(cls, schema):
class Model(BaseModel):
path1: Path
path2: MyPath
path3: List[MyPath]

assert Model.schema() == {
'title': 'Model',
'type': 'object',
'properties': {
'path1': {'title': 'Path1', 'type': 'string', 'format': 'path'},
'path2': {'title': 'Path2', 'type': 'string', 'format': 'path', 'foobar': 123},
'path3': {'title': 'Path3', 'type': 'array', 'items': {'type': 'string', 'format': 'path', 'foobar': 123}},
},
'required': ['path1', 'path2'],
'required': ['path1', 'path2', 'path3'],
}


Expand Down

0 comments on commit 7ac9faf

Please sign in to comment.