Skip to content

Commit

Permalink
Allow overriding full validator instance
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Mar 1, 2023
1 parent 556e921 commit c1a8177
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions singer_sdk/sinks/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from typing import IO, TYPE_CHECKING, Any, Mapping, Sequence

from dateutil import parser
from jsonschema import Draft7Validator, FormatChecker
from jsonschema import Draft7Validator, FormatChecker, Validator

from singer_sdk.helpers._batch import (
BaseBatchFileEncoding,
Expand Down Expand Up @@ -83,7 +83,23 @@ def __init__(
self._batch_records_read: int = 0
self._batch_dupe_records_merged: int = 0

self._validator = Draft7Validator(
self._validator = self.get_record_validator(self.schema)

def get_record_validator(self, schema: dict) -> Validator:
"""Get JSON schema validator for a given schema.
Override this method to customize the JSON schema validator.
Args:
schema: JSON schema to validate records against.
Returns:
A ``jsonschema`` `validator`_.
.. _validator:
https://python-jsonschema.readthedocs.io/en/stable/api/jsonschema/validators/
"""
return Draft7Validator( # type: ignore[return-value]
schema,
format_checker=self.get_format_checker(),
)
Expand Down

0 comments on commit c1a8177

Please sign in to comment.