Is there a way to specify that a schema property c...
# troubleshooting
s
Is there a way to specify that a schema property could be of 2 different types? I'm building a connector for an api that has a field that is sometimes returned as string and other times returned as an object:
th.StringType
or
th.ObjectType
Is there some syntax like:
Copy code
th.Property('value',[th.ObjectType(), th.StringType])
e
Hi Stephen. JSON Schema is a bit loose when it comes to union types. I know at least two options: Custom with types array
Copy code
>>> th.CustomType({"type": ["object", "string"], "properties": {}}).to_json()
'{"type": ["object", "string"], "properties": {}}'
https://json-schema.org/understanding-json-schema/reference/type.html#type-specific-keywords oneOf
Copy code
>>> th.OneOf(th.ObjectType(), th.StringType()).to_json()
'{"oneOf": [{"type": "object", "properties": {}}, {"type": ["string"]}]}'
https://json-schema.org/understanding-json-schema/reference/combining.html#oneof I think targets tend to have better support for the first form.
s
Thanks the first option worked!