I am working on modifying the tap for affinity to ...
# singer-tap-development
d
I am working on modifying the tap for affinity to add more of the API's endpoints and fields to the schema definition in the tap. The API returns some empty arrays, which appears to be valid JSON but when running "meltano el ..." it generates an error. See the thread for details. Thanks!
... Failed validating 'type' in schema['properties']['dropdown_options'] {'items': {'properties': {'color': {'type': ['integer', 'null']}, 'id': {'type': ['integer', 'null']}, 'rank': {'type': ['integer', 'null']}, 'text': {'type': ['string', 'null']}}, 'type': 'object'}, 'type': 'array'} On instance['dropdown_options']: '[]' What is the correct way to enable acceptance of an empty array? This is what is in the schema.py file: schema = th.PropertiesList( th.Property("id", th.IntegerType), th.Property("name", th.StringType), th.Property("list_id", th.IntegerType), th.Property("enrichment_source", th.StringType), th.Property("value_type", th.IntegerType), th.Property("allows_multiple", th.BooleanType), th.Property("track_changes", th.BooleanType), th.Property( "dropdown_options", th.ArrayType( th.ObjectType( th.Property("id", th.IntegerType), th.Property("text", th.StringType), th.Property("rank", th.IntegerType), th.Property("color", th.IntegerType), ) ), ), ).to_dict() Lastly, this is the first record returned by the API: [ { "id": 397020, "name": "Job Titles", "list_id": null, "enrichment_source": "affinity-data", "value_type": 2, "allows_multiple": true, "track_changes": false, "dropdown_options": [] }, ... more records follow
e
Hi Dan! I think you may be getting a
'[]'
string for that field, either directly from the API or though some post processing in the tap.
Copy code
Python 3.11.5 (main, Aug 24 2023, 15:09:45) [Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from jsonschema import Draft7Validator
>>> schema = {
...     "items": {
...         "properties": {
...             "color": {"type": ["integer", "null"]},
...             "id": {"type": ["integer", "null"]},
...             "rank": {"type": ["integer", "null"]},
...             "text": {"type": ["string", "null"]},
...         },
...         "type": "object",
...     },
...     "type": "array",
... }
>>> validator = Draft7Validator(schema)
>>> validator.validate([])
>>> validator.validate('[]')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/meltano/sdk/.venv/lib/python3.11/site-packages/jsonschema/validators.py", line 314, in validate
    raise error
jsonschema.exceptions.ValidationError: '[]' is not of type 'array'

Failed validating 'type' in schema:
    {'items': {'properties': {'color': {'type': ['integer', 'null']},
                              'id': {'type': ['integer', 'null']},
                              'rank': {'type': ['integer', 'null']},
                              'text': {'type': ['string', 'null']}},
               'type': 'object'},
     'type': 'array'}

On instance:
    '[]'
Try disabling any stream maps or flattening, if you have enabled any, and checking the raw Singer output of the tap to confirm.
d
Thanks for the suggestion, Edgar. The results look good now! I'll check more closely