I'm try to fix the schema for a tap I'm working on...
# singer-tap-development
m
I'm try to fix the schema for a tap I'm working on, but I have trouble with a property where the API sometimes returns a numeric value but sometimes returns a string value depending on the row. I tried using the "OneOf" type like this:
Property('step_number', OneOf(IntegerType, StringType))
but then I get this error on run: `ValueError: Could not append type because the JSON schema for the dictionary
{'oneOf': [{'type': ['integer']}, {'type': ['string']}]}
appears to be invalid.` What's the best way to handle this type of property? Should I use a transformation step to coerce the numeric values to strings and just use a StringType in the schema?
e
Hi @mark_estey! You found a bug: https://github.com/meltano/sdk/issues/1887
m
Good to know I'm not way off base! 😅 I'm curious though how the OneOf type will translate to the target though, does it determine a shared base type like in this case that integers can be converted to strings?
e
That depends on the target! For example, I don't think target-postgres handles
oneOf
but for
anyOf
it does exactly what you describe: https://github.com/MeltanoLabs/target-postgres/blob/0c82a7f50b8b930b6624a80b04753e8e9105dd79/target_postgres/tests/test_standard_target.py#L345-L378 cc @visch
m
That makes sense. I don't see 'AnyOf' in the Meltano SDK helper types so I guess that one hasn't been implemented yet?
v
@mark_estey for that use case I'd go with
Copy code
type: ["string", "integer", "null"]
See https://github.com/AutoIDM/tap-clickup/blob/main/tap_clickup/schemas/goal.json#L96-L98 for an example I think it's easier to reason about.
OneOf
should be supported though as
AnyOf
should be but that's what I do for taps as it seems to be the most "supported"
m
I've been using the Meltano SDK so I was hoping to avoid using a manual schema for this one case 😅
v
You don't have to you can still use the helpers the sdk offers and do the same thing
https://sdk.meltano.com/en/latest/classes/typing/singer_sdk.typing.CustomType.html I think can do the trick otherwise you can extend on yourself 🤷
m
Oooooh okay that works! Thanks, I didn't know I could just provide multiple different types other than null in a JSON schema