Skip to content

fix: Add additionalProperties to fields of type object #601

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions tap_postgres/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,14 @@ def array_to_jsonschema(self, column_type: postgresql.ARRAY) -> dict:
def json_to_jsonschema(self, column_type: postgresql.JSON) -> dict:
"""Override the default mapping for JSON and JSONB columns."""
if self.json_as_object:
return {"type": ["object", "null"]}
return {"type": ["string", "number", "integer", "array", "object", "boolean"]}
return {
"type": ["object", "null"],
"additionalProperties": True,
}
return {
"type": ["string", "number", "integer", "array", "object", "boolean"],
"additionalProperties": True,
}

@to_jsonschema.register
def datetime_to_jsonschema(self, column_type: sqlalchemy.types.DateTime) -> dict:
Expand Down
15 changes: 10 additions & 5 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ def test_jsonb_json():
"object",
"boolean",
"null",
]
],
"additionalProperties": True,
}
assert schema_message["schema"]["properties"]["column_json"] == {
"type": [
Expand All @@ -269,7 +270,8 @@ def test_jsonb_json():
"object",
"boolean",
"null",
]
],
"additionalProperties": True,
}
for i in range(len(rows)):
assert test_runner.records[altered_table_name][i] == rows[i]
Expand Down Expand Up @@ -330,7 +332,8 @@ def test_jsonb_array():
"array",
"object",
"boolean",
]
],
"additionalProperties": True,
},
"type": ["array", "null"],
}
Expand Down Expand Up @@ -397,13 +400,15 @@ def test_json_as_object():
"type": [
"object",
"null",
]
],
"additionalProperties": True,
}
assert schema_message["schema"]["properties"]["column_json"] == {
"type": [
"object",
"null",
]
],
"additionalProperties": True,
}

assert len(rows) == len(test_runner.records[altered_table_name])
Expand Down