Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fixed bool params and complex types params #4

Merged
merged 4 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
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: 20 additions & 1 deletion gen/client_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,25 @@
def get_type_for_param(param: dict, swagger: dict | None = None) -> str:
if swagger is None:
swagger = {}
_in = param.get("in")

if param.get("in") in ("query", "path"):
if _in == "path":
return str.__name__
elif _in == "query":
_type = get_path(
param,
"schema.type",
default="string"
)
if _type in SIMPLE_TYPES_MAP:
return SIMPLE_TYPES_MAP[_type]
else:
_items_type = get_path(
param,
"schema.items.type",
default="string"
)
return COMPLEX_TYPES_MAP[(_type, _items_type)]

param_type = param.get("type")
schema_type = get_path(param, "schema.type", None)
Expand Down Expand Up @@ -154,6 +170,7 @@ def param_to_function_argument(param: dict, swagger: dict | None = None) -> str:
swagger = {}

name = convert_to_snake_case(param["name"])

_type = get_type_for_param(param, swagger)

is_required = param.get('required', False)
Expand Down Expand Up @@ -556,6 +573,7 @@ def create_method_sig(swagger: dict, name: str, params: list[str], body_required
path_params = [
p for p in params if p['name'] not in SPECIAL_HEADERS and p["in"] != "body"
]

elements = [name, ]
sig = ""
_input_parameters_strings = [param_to_function_argument(p)
Expand All @@ -575,6 +593,7 @@ def create_method_sig(swagger: dict, name: str, params: list[str], body_required

doc = generate_doc_string(name, path_params, body_required, body_not_required,
swagger, method, path, indent_offset=1)

try:
if len(elements) > 1:
sig = "def %s(self, *, %s, data_partition_id: str | None = None) -> dict:" % tuple(elements)
Expand Down
10 changes: 2 additions & 8 deletions gen/tests_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,16 @@

TYPE_DEFAULTS = {
str: '"text"',
str | None: '"text"',
'str | None': '"text"',
'str': '"text"',
int | None: '10',
'int | None': '10',
dict: '{}',
'dict': '{}',
bool | None: 'False',
list[str]: '["text"]',
'bool | None': 'False',
'list[str]': '["text"]',
list[dict]: '[{}]',
'list[dict]': '[{}]',
list[dict] | None: '[{}]',
dict | None: '{}',
'list[dict] | None': '[{}]',
'dict | None': '{}',
list[str] | None: '["text"]',
'list[str] | None': '["text"]'
}

Expand Down
4 changes: 2 additions & 2 deletions osdu_client/services/entitlements/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ def list_partition_groups(
*,
type: str,
cursor: str | None = None,
limit: str | None = None,
limit: int | None = None,
data_partition_id: str | None = None,
) -> dict:
"""
Expand All @@ -445,7 +445,7 @@ def list_partition_groups(
data_partition_id (str): identifier of the data partition to query. If None sets by auth session.
type (str): type
cursor (str): cursor
limit (str): limit
limit (int): limit
Returns:
response data (dict)
Raises:
Expand Down
2 changes: 1 addition & 1 deletion osdu_client/services/file/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from osdu_client.utils import urljoin
from osdu_client.validation import validate_data

from .models import FileListRequest, FileLocationRequest, LocationRequest, Record, DeliveryGetFileSignedURLRequest
from .models import DeliveryGetFileSignedURLRequest, FileListRequest, FileLocationRequest, LocationRequest, Record


class FileAPIError(OSDUAPIError):
Expand Down
8 changes: 4 additions & 4 deletions osdu_client/services/indexer/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def provision_partition(self, data_partition_id: str | None = None) -> dict:
def reindex_kind(
self,
*,
force_clean: str | None = None,
force_clean: bool | None = None,
kind: str,
cursor: str | None = None,
data_partition_id: str | None = None,
Expand All @@ -50,7 +50,7 @@ def reindex_kind(
This API allows users to re-index a 'kind' without re-ingesting the records via storage API. Required roles: `service.search.admin`
Args:
data_partition_id (str): identifier of the data partition to query. If None sets by auth session.
force_clean (str): Force Clean
force_clean (bool): Force Clean
kind (str):
cursor (str):
Returns:
Expand Down Expand Up @@ -83,13 +83,13 @@ def reindex_kind(
return response.json()

def reindex_partition(
self, *, force_clean: str | None = None, data_partition_id: str | None = None
self, *, force_clean: bool | None = None, data_partition_id: str | None = None
) -> dict:
"""
This API allows users to re-index an entire partition without re-ingesting the records via storage API.Required roles: `users.datalake.ops`
Args:
data_partition_id (str): identifier of the data partition to query. If None sets by auth session.
force_clean (str): Force Clean
force_clean (bool): Force Clean
Returns:
response data (dict)
Raises:
Expand Down
8 changes: 4 additions & 4 deletions osdu_client/services/legal/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ class LegalClient(OSDUAPIClient):
service_path = "/api/legal/v1/"

def list_legaltags(
self, *, valid: str | None = None, data_partition_id: str | None = None
self, *, valid: bool | None = None, data_partition_id: str | None = None
) -> dict:
"""
This allows for the retrieval of all LegalTags.
Args:
data_partition_id (str): identifier of the data partition to query. If None sets by auth session.
valid (str): If true returns only valid LegalTags, if false returns only invalid LegalTags. Default value is true.
valid (bool): If true returns only valid LegalTags, if false returns only invalid LegalTags. Default value is true.
Returns:
response data (dict)
Raises:
Expand Down Expand Up @@ -171,7 +171,7 @@ def validate_legaltags(
def query_legaltags(
self,
*,
valid: str | None = None,
valid: bool | None = None,
query_list: list[str] | None = None,
operator_list: list[str] | None = None,
sort_by: str | None = None,
Expand All @@ -183,7 +183,7 @@ def query_legaltags(
This allows search for specific attributes of legaltags including the attributes of extensionproperties
Args:
data_partition_id (str): identifier of the data partition to query. If None sets by auth session.
valid (str): If true returns only valid LegalTags, if false returns only invalid LegalTags. Default value is true.
valid (bool): If true returns only valid LegalTags, if false returns only invalid LegalTags. Default value is true.
query_list (list[str]): Filter condition query
operator_list (list[str]): If there are multiple conditions need to be joined in by logical operators
sort_by (str):
Expand Down
32 changes: 16 additions & 16 deletions osdu_client/services/policy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ def evaluate_policy(
self,
*,
policy_id: str,
include_auth: str | None = None,
include_auth: bool | None = None,
correlation_id: str | None = None,
user_agent: str | None = None,
x_user_id: str | None = None,
Expand Down Expand Up @@ -425,7 +425,7 @@ def evaluate_policy(
Args:
data_partition_id (str): identifier of the data partition to query. If None sets by auth session.
policy_id (str):
include_auth (str): Update posted data to include auth (token, xuserid and data partition id) from headers
include_auth (bool): Update posted data to include auth (token, xuserid and data partition id) from headers
correlation_id (str):
user_agent (str):
x_user_id (str): identifier the user in the query
Expand Down Expand Up @@ -552,8 +552,8 @@ def get_api_policy_v1_info(
def create_api_policy_v1_compile(
self,
*,
metrics: str | None = None,
instrument: str | None = None,
metrics: bool | None = None,
instrument: bool | None = None,
correlation_id: str | None = None,
user_agent: str | None = None,
x_user_id: str | None = None,
Expand Down Expand Up @@ -581,8 +581,8 @@ def create_api_policy_v1_compile(
We recommend leaving query instrumentation off unless you are debugging a performance problem.
Args:
data_partition_id (str): identifier of the data partition to query. If None sets by auth session.
metrics (str): Include report detailed performance metrics on requested on individual API call. Returned inline with the API response
instrument (str): Include instrumentation data wth detailed performance metrics on requested on individual API call. Returned inline with the API response
metrics (bool): Include report detailed performance metrics on requested on individual API call. Returned inline with the API response
instrument (bool): Include instrumentation data wth detailed performance metrics on requested on individual API call. Returned inline with the API response
correlation_id (str):
user_agent (str):
x_user_id (str): identifier the user in the query
Expand Down Expand Up @@ -617,7 +617,7 @@ def create_api_policy_v1_compile(
def get_tenant(
self,
*,
all_data: str | None = None,
all_data: bool | None = None,
correlation_id: str | None = None,
user_agent: str | None = None,
x_user_id: str | None = None,
Expand All @@ -628,7 +628,7 @@ def get_tenant(
These details are read from OPA configmap.
Args:
data_partition_id (str): identifier of the data partition to query. If None sets by auth session.
all_data (str):
all_data (bool):
correlation_id (str):
user_agent (str):
x_user_id (str): identifier the user in the query
Expand Down Expand Up @@ -662,8 +662,8 @@ def update_tenant(
self,
*,
service: str,
polling_min_delay_seconds: str | None = None,
polling_max_delay_seconds: str | None = None,
polling_min_delay_seconds: int | None = None,
polling_max_delay_seconds: int | None = None,
correlation_id: str | None = None,
user_agent: str | None = None,
x_user_id: str | None = None,
Expand All @@ -675,8 +675,8 @@ def update_tenant(
Args:
data_partition_id (str): identifier of the data partition to query. If None sets by auth session.
service (str):
polling_min_delay_seconds (str):
polling_max_delay_seconds (str):
polling_min_delay_seconds (int):
polling_max_delay_seconds (int):
correlation_id (str):
user_agent (str):
x_user_id (str): identifier the user in the query
Expand Down Expand Up @@ -832,7 +832,7 @@ def validate_policy(
self,
*,
policy_id: str,
template: str | None = None,
template: bool | None = None,
correlation_id: str | None = None,
user_agent: str | None = None,
x_user_id: str | None = None,
Expand All @@ -849,7 +849,7 @@ def validate_policy(
Args:
data_partition_id (str): identifier of the data partition to query. If None sets by auth session.
policy_id (str):
template (str):
template (bool):
correlation_id (str):
user_agent (str):
x_user_id (str): identifier the user in the query
Expand Down Expand Up @@ -925,7 +925,7 @@ def get_backup(
def bootstrap(
self,
*,
force: str | None = None,
force: bool | None = None,
correlation_id: str | None = None,
user_agent: str | None = None,
x_user_id: str | None = None,
Expand All @@ -949,7 +949,7 @@ def bootstrap(
* HTTP_424_FAILED_DEPENDENCY - bundle server caused failure
Args:
data_partition_id (str): identifier of the data partition to query. If None sets by auth session.
force (str):
force (bool):
correlation_id (str):
user_agent (str):
x_user_id (str): identifier the user in the query
Expand Down
Loading
Loading