Skip to content

Commit

Permalink
fix anyof validation for python (#789)
Browse files Browse the repository at this point in the history
* fix anyof validation for python

* all python tests work
  • Loading branch information
dphuang2 authored Nov 20, 2024
1 parent 1b24fe7 commit 5c4f665
Show file tree
Hide file tree
Showing 692 changed files with 5,318 additions and 3,358 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,48 +90,6 @@ class ApiException(OpenApiException):
return error_message


class AnyOfValidationError(OpenApiException):
def __init__(self, error_list: typing.List[typing.Union[ApiTypeError, ApiValueError]]):
self.error_list = error_list
sub_msgs: typing.List[str] = []
for type_error in error_list:
sub_msgs.append(str(type_error))
num_validation_errors = len(self.error_list)
if num_validation_errors == 1:
super().__init__(sub_msgs[0])
else:
# create a string that says how many validation errors there were and
# prints each sub_msg out using a bulleted list of messages
msg = "{} validation error{} detected: \n".format(num_validation_errors, "s" if num_validation_errors > 1 else "")
for i, sub_msg in enumerate(sub_msgs):
msg += " {}. {}\n".format(i+1, sub_msg)
super().__init__(msg)


class InvalidHostConfigurationError(ClientConfigurationError):
def __init__(self, host: str, reason: str):
self.host = host
self.reason = reason
super().__init__('Invalid host: "{}", {}'.format(self.host, self.reason))


class MissingRequiredPropertiesError(ApiTypeError):
def __init__(self, msg: str):
super().__init__(msg)


class MissingRequiredParametersError(ApiTypeError):
def __init__(self, error: TypeError):
self.error = error
error_str = str(error)
self.msg = error_str
if "__new__()" in error_str:
# parse error to reformat
missing_parameters = error_str.split(":")[1].strip()
number_of_parameters = error_str.split("missing")[1].split("required")[0].strip()
self.msg = "Missing {} required parameter{}: {}".format(number_of_parameters, "s" if int(number_of_parameters) > 1 else "", missing_parameters)
super().__init__(self.msg)

class SchemaValidationError(OpenApiException):
def __init__(self, validation_errors: typing.List[typing.Union[ApiValueError, ApiTypeError]]):
""" Aggregates schema validation errors
Expand Down Expand Up @@ -182,3 +140,45 @@ class SchemaValidationError(OpenApiException):
num_validation_errors = len(self.validation_errors)
self.msg = "{} invalid argument{}. {}".format(num_validation_errors, "s" if num_validation_errors > 1 else "", sub_msg)
super().__init__(self.msg)

class AnyOfValidationError(OpenApiException):
def __init__(self, error_list: typing.List[typing.Union[ApiTypeError, ApiValueError, SchemaValidationError]]):
self.error_list = error_list
sub_msgs: typing.List[str] = []
for type_error in error_list:
sub_msgs.append(str(type_error))
num_validation_errors = len(self.error_list)
if num_validation_errors == 1:
super().__init__(sub_msgs[0])
else:
# create a string that says how many validation errors there were and
# prints each sub_msg out using a bulleted list of messages
msg = "{} validation error{} detected: \n".format(num_validation_errors, "s" if num_validation_errors > 1 else "")
for i, sub_msg in enumerate(sub_msgs):
msg += " {}. {}\n".format(i+1, sub_msg)
super().__init__(msg)


class InvalidHostConfigurationError(ClientConfigurationError):
def __init__(self, host: str, reason: str):
self.host = host
self.reason = reason
super().__init__('Invalid host: "{}", {}'.format(self.host, self.reason))


class MissingRequiredPropertiesError(ApiTypeError):
def __init__(self, msg: str):
super().__init__(msg)


class MissingRequiredParametersError(ApiTypeError):
def __init__(self, error: TypeError):
self.error = error
error_str = str(error)
self.msg = error_str
if "__new__()" in error_str:
# parse error to reformat
missing_parameters = error_str.split(":")[1].strip()
number_of_parameters = error_str.split("missing")[1].split("required")[0].strip()
self.msg = "Missing {} required parameter{}: {}".format(number_of_parameters, "s" if int(number_of_parameters) > 1 else "", missing_parameters)
super().__init__(self.msg)
Original file line number Diff line number Diff line change
Expand Up @@ -1870,7 +1870,7 @@ class ComposedBase(Discriminable):
continue
try:
path_to_schemas = oneof_cls._validate_oapg(arg, validation_metadata=validation_metadata)
except (ApiValueError, ApiTypeError) as ex:
except (ApiValueError, ApiTypeError, SchemaValidationError) as ex:
if discriminated_cls is not None and oneof_cls is discriminated_cls:
{{#if nonCompliantUseDiscriminatorIfCompositionFails}}
"""
Expand Down Expand Up @@ -1929,7 +1929,7 @@ class ComposedBase(Discriminable):

try:
other_path_to_schemas = anyof_cls._validate_oapg(arg, validation_metadata=validation_metadata)
except (ApiValueError, ApiTypeError) as ex:
except (ApiValueError, ApiTypeError, SchemaValidationError) as ex:
if discriminated_cls is not None and anyof_cls is discriminated_cls:
raise ex
exceptions.append(ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
}
],
"description": "This endpoint lets the user run a specified workflow with the provided workflow definition.",
"parameters": [
],
"requestBody": {
"required": true,
"content": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
from urllib.parse import urlparse, quote
from urllib3.fields import RequestField as RequestFieldBase
from urllib3.fields import guess_content_type
from dateutil import parser
from datetime import datetime as dt

import frozendict

Expand All @@ -52,6 +54,7 @@
unset,
)


@dataclass
class MappedArgs:
body: typing.Any = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ def __init__(self, host=None,
else:
raise ClientConfigurationError('API Key "api_key" is required')
if x_api_key:
if type(x_api_key) is not str:
raise ClientConfigurationError("x_api_key must be a string")
self.api_key['api_key'] = x_api_key
elif api_key is None:
raise ClientConfigurationError('API Key "api_key" is required')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,48 +98,6 @@ def __str__(self):
return error_message


class AnyOfValidationError(OpenApiException):
def __init__(self, error_list: typing.List[typing.Union[ApiTypeError, ApiValueError]]):
self.error_list = error_list
sub_msgs: typing.List[str] = []
for type_error in error_list:
sub_msgs.append(str(type_error))
num_validation_errors = len(self.error_list)
if num_validation_errors == 1:
super().__init__(sub_msgs[0])
else:
# create a string that says how many validation errors there were and
# prints each sub_msg out using a bulleted list of messages
msg = "{} validation error{} detected: \n".format(num_validation_errors, "s" if num_validation_errors > 1 else "")
for i, sub_msg in enumerate(sub_msgs):
msg += " {}. {}\n".format(i+1, sub_msg)
super().__init__(msg)


class InvalidHostConfigurationError(ClientConfigurationError):
def __init__(self, host: str, reason: str):
self.host = host
self.reason = reason
super().__init__('Invalid host: "{}", {}'.format(self.host, self.reason))


class MissingRequiredPropertiesError(ApiTypeError):
def __init__(self, msg: str):
super().__init__(msg)


class MissingRequiredParametersError(ApiTypeError):
def __init__(self, error: TypeError):
self.error = error
error_str = str(error)
self.msg = error_str
if "__new__()" in error_str:
# parse error to reformat
missing_parameters = error_str.split(":")[1].strip()
number_of_parameters = error_str.split("missing")[1].split("required")[0].strip()
self.msg = "Missing {} required parameter{}: {}".format(number_of_parameters, "s" if int(number_of_parameters) > 1 else "", missing_parameters)
super().__init__(self.msg)

class SchemaValidationError(OpenApiException):
def __init__(self, validation_errors: typing.List[typing.Union[ApiValueError, ApiTypeError]]):
""" Aggregates schema validation errors
Expand Down Expand Up @@ -190,3 +148,45 @@ def __init__(self, validation_errors: typing.List[typing.Union[ApiValueError, Ap
num_validation_errors = len(self.validation_errors)
self.msg = "{} invalid argument{}. {}".format(num_validation_errors, "s" if num_validation_errors > 1 else "", sub_msg)
super().__init__(self.msg)

class AnyOfValidationError(OpenApiException):
def __init__(self, error_list: typing.List[typing.Union[ApiTypeError, ApiValueError, SchemaValidationError]]):
self.error_list = error_list
sub_msgs: typing.List[str] = []
for type_error in error_list:
sub_msgs.append(str(type_error))
num_validation_errors = len(self.error_list)
if num_validation_errors == 1:
super().__init__(sub_msgs[0])
else:
# create a string that says how many validation errors there were and
# prints each sub_msg out using a bulleted list of messages
msg = "{} validation error{} detected: \n".format(num_validation_errors, "s" if num_validation_errors > 1 else "")
for i, sub_msg in enumerate(sub_msgs):
msg += " {}. {}\n".format(i+1, sub_msg)
super().__init__(msg)


class InvalidHostConfigurationError(ClientConfigurationError):
def __init__(self, host: str, reason: str):
self.host = host
self.reason = reason
super().__init__('Invalid host: "{}", {}'.format(self.host, self.reason))


class MissingRequiredPropertiesError(ApiTypeError):
def __init__(self, msg: str):
super().__init__(msg)


class MissingRequiredParametersError(ApiTypeError):
def __init__(self, error: TypeError):
self.error = error
error_str = str(error)
self.msg = error_str
if "__new__()" in error_str:
# parse error to reformat
missing_parameters = error_str.split(":")[1].strip()
number_of_parameters = error_str.split("missing")[1].split("required")[0].strip()
self.msg = "Missing {} required parameter{}: {}".format(number_of_parameters, "s" if int(number_of_parameters) > 1 else "", missing_parameters)
super().__init__(self.msg)
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ def workflow(
ApiResponseFor200,
api_client.ApiResponseWithoutDeserialization,
]:
""" This endpoint lets the user run a specified workflow with the provided workflow definition. """
args = self._workflow_mapped_args(
workflow_id=workflow_id,
webhook_url=webhook_url,
Expand Down Expand Up @@ -395,6 +396,7 @@ def post(
ApiResponseFor200,
api_client.ApiResponseWithoutDeserialization,
]:
""" This endpoint lets the user run a specified workflow with the provided workflow definition. """
args = self._workflow_mapped_args(
workflow_id=workflow_id,
webhook_url=webhook_url,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ class Workflow(BaseApi):
ApiResponseFor200,
api_client.ApiResponseWithoutDeserialization,
]:
""" This endpoint lets the user run a specified workflow with the provided workflow definition. """
args = self._workflow_mapped_args(
workflow_id=workflow_id,
webhook_url=webhook_url,
Expand Down Expand Up @@ -386,6 +387,7 @@ class ApiForpost(BaseApi):
ApiResponseFor200,
api_client.ApiResponseWithoutDeserialization,
]:
""" This endpoint lets the user run a specified workflow with the provided workflow definition. """
args = self._workflow_mapped_args(
workflow_id=workflow_id,
webhook_url=webhook_url,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ def get_workflow_run(
ApiResponseFor200,
api_client.ApiResponseWithoutDeserialization,
]:
""" This endpoint retrieves the details of a specific workflow run using its `workflow_run_id`. """
args = self._get_workflow_run_mapped_args(
workflow_run_id=workflow_run_id,
)
Expand Down Expand Up @@ -380,6 +381,7 @@ def get(
ApiResponseFor200,
api_client.ApiResponseWithoutDeserialization,
]:
""" This endpoint retrieves the details of a specific workflow run using its `workflow_run_id`. """
args = self._get_workflow_run_mapped_args(
workflow_run_id=workflow_run_id,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ class GetWorkflowRun(BaseApi):
ApiResponseFor200,
api_client.ApiResponseWithoutDeserialization,
]:
""" This endpoint retrieves the details of a specific workflow run using its `workflow_run_id`. """
args = self._get_workflow_run_mapped_args(
workflow_run_id=workflow_run_id,
)
Expand Down Expand Up @@ -371,6 +372,7 @@ class ApiForget(BaseApi):
ApiResponseFor200,
api_client.ApiResponseWithoutDeserialization,
]:
""" This endpoint retrieves the details of a specific workflow run using its `workflow_run_id`. """
args = self._get_workflow_run_mapped_args(
workflow_run_id=workflow_run_id,
)
Expand Down
Loading

0 comments on commit 5c4f665

Please sign in to comment.