Skip to content

Commit

Permalink
Add default value for schema pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
lazebnyi committed Dec 3, 2024
1 parent fd44be1 commit 05e4f74
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1701,7 +1701,6 @@ definitions:
description: (This component is experimental. Use at your own risk.) Identifies schema details for dynamic schema extraction and processing.
type: object
required:
- schema_pointer
- key_pointer
properties:
type:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -657,8 +657,8 @@ class TypesMap(BaseModel):

class SchemaTypeIdentifier(BaseModel):
type: Optional[Literal["SchemaTypeIdentifier"]] = None
schema_pointer: List[str] = Field(
...,
schema_pointer: Optional[List[str]] = Field(
[],
description="List of nested fields defining the schema field path to extract. Defaults to [].",
title="Schema Path",
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1593,9 +1593,9 @@ def create_schema_type_identifier(
for types_pair in model.types_mapping
]
)
model_schema_pointer: List[Union[InterpolatedString, str]] = [
x for x in model.schema_pointer
]
model_schema_pointer: List[Union[InterpolatedString, str]] = (
[x for x in model.schema_pointer] if model.schema_pointer else []
)
model_key_pointer: List[Union[InterpolatedString, str]] = [x for x in model.key_pointer]
model_type_pointer: Optional[List[Union[InterpolatedString, str]]] = (
[x for x in model.type_pointer] if model.type_pointer else None
Expand Down
10 changes: 6 additions & 4 deletions airbyte_cdk/sources/declarative/schema/dynamic_schema_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,16 @@ class SchemaTypeIdentifier:
Identifies schema details for dynamic schema extraction and processing.
"""

schema_pointer: List[Union[InterpolatedString, str]]
key_pointer: List[Union[InterpolatedString, str]]
parameters: InitVar[Mapping[str, Any]]
type_pointer: Optional[List[Union[InterpolatedString, str]]] = None
types_map: Optional[List[TypesMap]] = None
schema_pointer: Optional[List[Union[InterpolatedString, str]]] = None

def __post_init__(self, parameters: Mapping[str, Any]) -> None:
self.schema_pointer = self._update_pointer(self.schema_pointer, parameters) # type: ignore[assignment] # This is reqired field in model
self.schema_pointer = (
self._update_pointer(self.schema_pointer, parameters) if self.schema_pointer else []
) # type: ignore[assignment] # This is reqired field in model
self.key_pointer = self._update_pointer(self.key_pointer, parameters) # type: ignore[assignment] # This is reqired field in model
self.type_pointer = (
self._update_pointer(self.type_pointer, parameters) if self.type_pointer else None
Expand Down Expand Up @@ -199,14 +201,14 @@ def _get_airbyte_type(field_type: str) -> Mapping[str, Any]:
def _extract_data(
self,
body: Mapping[str, Any],
extraction_path: List[Union[InterpolatedString, str]],
extraction_path: Optional[List[Union[InterpolatedString, str]]] = None,
default: Any = None,
) -> Any:
"""
Extracts data from the body based on the provided extraction path.
"""

if len(extraction_path) == 0:
if not extraction_path:
return body

path = [
Expand Down

0 comments on commit 05e4f74

Please sign in to comment.