feat(mappers): support explicit property schemas - #3733
Conversation
Allow stream map properties to use an object containing expr and JSON Schema keywords. Validate the schema during mapper setup and normalize the expression without mutating config. Extend the built-in stream_maps config schema, preserve string and null mappings, document usage, and cover validation, runtime, and schema behavior. Closes meltano#2010 Co-authored-by: OpenAI Codex <noreply@openai.com> Signed-off-by: Abhinav Gorrepati <gorrepatiabhinav1@gmail.com>
Reviewer's GuideAdds support for explicitly-typed mapped properties in stream maps by allowing dict-based property definitions with JSON Schema, validating them at config-load time, and extending the stream_maps capability schema and documentation, while preserving existing string/null mapping behavior and avoiding user config mutation. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Documentation build overview
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- In the capabilities config schema,
Property("expr", StringType, ...)likely needsStringType()to be consistent with the other type helpers and avoid passing the class instead of an instance. - For typed property definitions, you rely on
DEFAULT_JSONSCHEMA_VALIDATOR.check_schemaat runtime; if you want to keep config errors as deterministic as possible, consider constrainingadditional_propertiesin theObjectTypeschema so obviously invalid keys are caught earlier by config validation.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In the capabilities config schema, `Property("expr", StringType, ...)` likely needs `StringType()` to be consistent with the other type helpers and avoid passing the class instead of an instance.
- For typed property definitions, you rely on `DEFAULT_JSONSCHEMA_VALIDATOR.check_schema` at runtime; if you want to keep config errors as deterministic as possible, consider constraining `additional_properties` in the `ObjectType` schema so obviously invalid keys are caught earlier by config validation.
## Individual Comments
### Comment 1
<location path="singer_sdk/mapper.py" line_range="578-579" />
<code_context>
- if prop_def in {None, NULL_STRING}:
+ if prop_def is None or prop_def == NULL_STRING:
if prop_key in (self.transformed_key_properties or []):
msg = (
f"Removing key property '{prop_key}' is not permitted in "
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Use `str(ex)` instead of `ex.message` for jsonschema errors to be more robust.
When formatting the error for an invalid typed stream map schema, this relies on `ex.message`, which is deprecated/internal in newer Python/jsonschema versions and may be missing or differently formatted. Prefer `str(ex)` (optionally with the exception type) for a more robust message, e.g. `f"Invalid JSON Schema ...: {ex}"`.
Suggested implementation:
```python
except jsonschema.exceptions.ValidationError as ex:
raise ValueError(
f"Invalid JSON Schema for typed stream map schema: {ex}"
)
```
```python
except jsonschema.exceptions.SchemaError as ex:
self.logger.error(
"Invalid JSON Schema for typed stream map schema: %s", str(ex)
)
raise
```
If there are other uses of `ex.message` for jsonschema-related exceptions in this file (or nearby modules), they should be updated in the same way:
- Replace `ex.message` in f-strings with `{ex}`.
- Replace `ex.message` used as a standalone argument (e.g. logger calls) with `str(ex)`.
This keeps formatting robust across jsonschema/Python versions.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3733 +/- ##
=======================================
Coverage 94.35% 94.35%
=======================================
Files 74 74
Lines 6289 6289
Branches 770 770
=======================================
Hits 5934 5934
Misses 266 266
Partials 89 89
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Format JSON Schema failures through the exception interface and use a StringType instance in the public stream maps config schema. Co-authored-by: OpenAI Codex <noreply@openai.com> Signed-off-by: Abhinav Gorrepati <gorrepatiabhinav1@gmail.com>
|
I also applied the review-level StringType() consistency suggestion in 55885a4. I am intentionally keeping additional_properties=AnyType(): after expr is removed, the object is a JSON Schema, whose valid vocabulary includes composition keywords, annotations, and extension keywords. Enumerating keys in the plugin config schema would reject valid present or future schemas; DEFAULT_JSONSCHEMA_VALIDATOR.check_schema remains the authoritative validation step. The config layer still requires expr to be a string, and the validate_config=True regression test covers that boundary. |
Summary
exprplus arbitrary JSON Schema keywordsstream_mapsconfig schema sovalidate_config=Trueaccepts typed mappingsValidation
uv run pytest -q— 855 passed, 388 deselected, 1 expected xfail, 21 subtests passedCI note
The API Changes job reports the intentional value change to the public
STREAM_MAPS_CONFIGschema. No API is removed; extending that schema is required so SDK plugins usingvalidate_config=Truecan accept the new typed mapping form. Comparable additive configuration-schema changes in this repository have produced the same diagnostic.Closes #2010