Skip to content
Merged
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
21 changes: 17 additions & 4 deletions cloudquery/sdk/transformers/openapi.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Dict, List
from typing import Dict, List, Optional
import pyarrow as pa
from cloudquery.sdk.types import JSONType
from cloudquery.sdk.schema import Column
Expand All @@ -24,11 +24,24 @@ def oapi_type_to_arrow_type(field) -> pa.DataType:
return pa.string()


def oapi_definition_to_columns(definition: Dict) -> List[Column]:
def get_column_by_name(columns: List[Column], name: str) -> Optional[Column]:
for column in columns:
if column.name == name:
return column
return None


def oapi_definition_to_columns(definition: Dict, override_columns=[]) -> List[Column]:
columns = []
for key, value in definition["properties"].items():
column_type = oapi_type_to_arrow_type(value)
columns.append(
Column(name=key, type=column_type, description=value.get("description"))
column = Column(
name=key, type=column_type, description=value.get("description")
)
override_column = get_column_by_name(override_columns, key)
if override_column is not None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if override_column is not None:
if override_column:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think better is not None in python in case it evaluates to false

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

false would be falsy, also it's either a Column or None? I think this is the Pythonic way.

column.type = override_column.type
column.primary_key = override_column.primary_key
column.unique = override_column.unique
columns.append(column)
return columns