Skip to content

Commit

Permalink
Added failing test based on issue #53
Browse files Browse the repository at this point in the history
  • Loading branch information
noamgat committed Jan 7, 2024
1 parent 1ee9d39 commit c1bb065
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/test_jsonschemaparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,18 @@ def test_more_string_constraints():
'min_4_max_6': '12_'
}.items():
_test_json_schema_parsing_with_string(f'{{"{k}": "{v}"}}', StringConstraints.model_json_schema(), False)


def test_union_typed_arrays():
class AppleSchema(BaseModel):
apple_type: int

class BananaSchema(BaseModel):
is_ripe: bool

class FruitsSchema(BaseModel):
fruits: List[Union[AppleSchema, BananaSchema]]

_test_json_schema_parsing_with_string('{"fruits": [{"apple_type": 1}, {"apple_type": 2}] }', FruitsSchema.model_json_schema(), True)
_test_json_schema_parsing_with_string('{"fruits": [{"apple_type": 1}, {"is_ripe": true}] }', FruitsSchema.model_json_schema(), True)
_test_json_schema_parsing_with_string('{"fruits": [{"apple_type": 1, "is_ripe": true}] }', FruitsSchema.model_json_schema(), False)

0 comments on commit c1bb065

Please sign in to comment.