Fix TokenPatternSchema pattern field validation

Empty pattern field should be considered invalid

This is fixed by replacing minItems with min_items
as described in Pydantic docs:
https://pydantic-docs.helpmanual.io/usage/schema/
This commit is contained in:
Jan Margeta 2020-10-16 00:41:19 +02:00
parent ed1c37189a
commit 1ad2213349
2 changed files with 15 additions and 1 deletions

View File

@ -257,7 +257,7 @@ class TokenPattern(BaseModel):
class TokenPatternSchema(BaseModel):
pattern: List[TokenPattern] = Field(..., minItems=1)
pattern: List[TokenPattern] = Field(..., min_items=1)
class Config:
extra = "forbid"

View File

@ -0,0 +1,14 @@
import pydantic
import pytest
from pydantic import ValidationError
from spacy.schemas import TokenPattern, TokenPatternSchema
def test_issue6258():
"""Test that the non-empty constraint pattern field is respected"""
# These one is valid
TokenPatternSchema(pattern=[TokenPattern()])
# But an empty pattern list should fail to validate
# based on the schema's constraint
with pytest.raises(ValidationError):
TokenPatternSchema(pattern=[])