Skip to content

Commit

Permalink
Apply suggestions from code of validator interface.
Browse files Browse the repository at this point in the history
Co-authored-by: Edgar Ramírez Mondragón <[email protected]>
  • Loading branch information
BuzzCutNorman and edgarrmondragon authored Dec 4, 2023
1 parent 7df254d commit 10445a6
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions singer_sdk/sinks/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,30 +150,21 @@ def __init__(
self._batch_dupe_records_merged: int = 0

self._validator: BaseRecordValidator | None = self.get_record_validator()
schema,
validate_formts=self.validate_field_string_format,
validator_formats=self.get_validator_formats(),
)

def get_validator_formats(self) -> dict[str, str | t.Callable[[], bool]]:
"""Get formats for JSON schema validator.
Override this method to add custom string format checkers to the JSON schema
validator.
This is useful when, for example, the target requires a specific format for a
date or datetime field.
def get_record_validator(self) -> BaseRecordValidator | None:
"""Get a record validator for this sink.
Example:
.. validate = fastjsonschema.compile(definition, formats={
'foo': r'foo|bar',
'bar': lambda value: value in ('foo', 'bar'),
})
Override this method to use a custom format validator or disable record validator, by returning `None`.
Returns:
A dictionary containing regex strings and callables.
See: https://horejsek.github.io/python-fastjsonschema/.
An instance of a subclass of ``BaseRecordValidator``.
"""
return {}
return FastJSONSchemaValidator(
schema,
validate_formats=self.validate_field_string_format,
format_validators={},
)

def _get_context(self, record: dict) -> dict: # noqa: ARG002
"""Return an empty dictionary by default.
Expand Down

0 comments on commit 10445a6

Please sign in to comment.