Hi all, I have an issue where a value returned fro...
# singer-tap-development
j
Hi all, I have an issue where a value returned from a stream can either be an array or a string. Can't work out the correct syntax. I thought it would be a union. Has anyone else come across this?
Copy code
th.Property(
            "meta_data",
                th.ArrayType(th.ObjectType(
                    th.Property("id", th.NumberType),
                    th.Property("key", th.StringType),
                    th.Property("value", Union[th.StringType, th.ArrayType])
                ))
        ),
e
Hi @jazzy. Yes, in concept it'd be a union or more concretely a JSON Schema
anyOf
. However, the SDK doesn't support using Python's built-in typing mechanisms (e.g.
Union
) to build the JSON Schema, so it relies entirely on its own type definitions and currently there is no way of declaring an
anyOf
type in there.
j
Thanks for the response that makes sense. Any suggestion for a quick fix to get around this issue?
e
You could declare a raw JSON schema without the helpers
Copy code
{
  "type": "object",
  "properties": {
    "value": {
      "anyOf": [
        {"type": "string"},
        {"type": "array"},
      ]
    }
  }
}
a
@jazzy - What you can implement in JSON Schema isn't always the easiest to deal with downstream. What do you think of just making this an array and in the
post_process()
method you can conform a single string into an "array of 1 item"?
This doesn't exactly match the upstream, but it works around the issue - while also making it easier on the target to deal with the record.
j
@aaronsteers Thanks for the response. I like the idea!