Handle lists in JSON schema parsing
Closed this issue · 4 comments
gwukelic commented
Hi Chris! I noticed that lists in JSON schemas are not being parsed correctly by the JSONSchemaConverter
in json_schema.py
. For example, attempting to parse the following file results in an Unsupported JSON schema
error message.
Example: foobar.json
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "FooBar",
"type": "object",
"properties": {
"foo": {
"description": "Placeholder description",
"type": ["string", "null"]
}
}
}
One potential solution is adding to switch statement in json_schema.py
, specifically by adding another case
match json_schema:
...
# New case to handle lists
case {"type": types} if isinstance(types, list):
fields = []
for field_type in types:
item = {"type": field_type}
field = self._parse(item, alias_strategy)
fields.append(field)
return StructType(fields, **extra_attrs)
...
# Without the code above, we hit this case
case _:
raise ValueError(f"Unsupported JSON schema: {json_schema}")
Let me know what you think! I'd be happy to open a pull request for this fix.
criccomini commented
Dang, good catch. Not sure how this made it through the tests. 😢
Yes, a PR would be most welcome!
adrianisk commented
I'll send over a PR for this shortly
criccomini commented
@adrianisk @gwukelic checkin' in on this one
adrianisk commented
Heyo, sorry it's been a very busy week, but I will get this in this weekend...