ms32035 / firefly-iii-client

Python client for Firefly III API. Please read .generator/Readme.md
22 stars 10 forks source link

Validation of oapg is too strict when applying to incoming message #20

Open soraxas opened 7 months ago

soraxas commented 7 months ago

The validation of incoming message is too strict when compared to what is allowed (or more like what is being sent) in firefly iii.

The following is the traceback when I was requesting some account information from my firefly iii instance.  

Traceback (most recent call last):
  ......
  File "....../lib/python3.9/site-packages/firefly_iii_client/paths/v1_accounts/get.py", line 380, in list_account
    return self._list_account_oapg(
  File "....../lib/python3.9/site-packages/firefly_iii_client/paths/v1_accounts/get.py", line 316, in _list_account_oapg
    api_response = response_for_status.deserialize(response, self.api_client.configuration)
  File "....../lib/python3.9/site-packages/firefly_iii_client/api_client.py", line 952, in deserialize
    deserialized_body = body_schema.from_openapi_data_oapg(
  File "....../lib/python3.9/site-packages/firefly_iii_client/schemas.py", line 2450, in from_openapi_data_oapg
    return super().from_openapi_data_oapg(arg, _configuration=_configuration)
  File "....../lib/python3.9/site-packages/firefly_iii_client/schemas.py", line 494, in from_openapi_data_oapg
    path_to_schemas = cls.__get_new_cls(arg, validation_metadata)
  File "....../lib/python3.9/site-packages/firefly_iii_client/schemas.py", line 412, in __get_new_cls
    other_path_to_schemas = cls._validate_oapg(arg, validation_metadata=validation_metadata)
  File "....../lib/python3.9/site-packages/firefly_iii_client/schemas.py", line 1674, in _validate_oapg
    other_path_to_schemas = cls.__validate_args(arg, validation_metadata=validation_metadata)
  File "....../lib/python3.9/site-packages/firefly_iii_client/schemas.py", line 1615, in __validate_args
    other_path_to_schemas = schema._validate_oapg(value, validation_metadata=arg_validation_metadata)
  File "....../lib/python3.9/site-packages/firefly_iii_client/schemas.py", line 1426, in _validate_oapg
    other_path_to_schemas = cls.__validate_items(arg, validation_metadata=updated_vm)
  File "....../lib/python3.9/site-packages/firefly_iii_client/schemas.py", line 1351, in __validate_items
    other_path_to_schemas = item_cls._validate_oapg(
  File "....../lib/python3.9/site-packages/firefly_iii_client/schemas.py", line 1674, in _validate_oapg
    other_path_to_schemas = cls.__validate_args(arg, validation_metadata=validation_metadata)
  File "....../lib/python3.9/site-packages/firefly_iii_client/schemas.py", line 1615, in __validate_args
    other_path_to_schemas = schema._validate_oapg(value, validation_metadata=arg_validation_metadata)
  File "....../lib/python3.9/site-packages/firefly_iii_client/schemas.py", line 1674, in _validate_oapg
    other_path_to_schemas = cls.__validate_args(arg, validation_metadata=validation_metadata)
  File "....../lib/python3.9/site-packages/firefly_iii_client/schemas.py", line 1615, in __validate_args
    other_path_to_schemas = schema._validate_oapg(value, validation_metadata=arg_validation_metadata)
  File "....../lib/python3.9/site-packages/firefly_iii_client/schemas.py", line 911, in _validate_oapg
    raise ApiValueError("Invalid value {} passed in to {}, allowed_values={}".format(arg, cls, cls.MetaOapg.enum_value_to_name.keys()))
firefly_iii_client.exceptions.ApiValueError: Invalid value <NoneClass: None> passed in to <class 'firefly_iii_client.model.account_role_property.AccountRoleProperty'>, allowed_values=dict_keys(['defaultAsset', 'sharedAsset', 'savingAsset', 'ccAsset', 'cashWalletAsset', 'null'])

Pretty much it's complaining that the incoming message contains the value None, which is not allowed in-accordance to the openapi schema.

Everything works fine if I were to comment out the block of code within _validate_oapg, i.e., in firefly_iii_client/schemas.py line 897

class EnumBase:
    @classmethod
    def _validate_oapg(
        cls,
        arg,
        validation_metadata: ValidationMetadata,
    ) -> typing.Dict[typing.Tuple[typing.Union[str, int], ...], typing.Set[typing.Union['Schema', str, decimal.Decimal, BoolClass, NoneClass, frozendict.frozendict, tuple]]]:
        """
        EnumBase _validate_oapg
        Validates that arg is in the enum's allowed values
        """
-        try:
-            cls.MetaOapg.enum_value_to_name[arg]
-        except KeyError:
-            raise ApiValueError("Invalid value {} passed in to {}, allowed_values={}".format(arg, cls, 
+        # try:
+        #     cls.MetaOapg.enum_value_to_name[arg]
+        # except KeyError:
+        #     raise ApiValueError("Invalid value {} passed in to {}, allowed_values={}".format(arg, cls, cls.MetaOapg.enum_value_to_name.keys()))
        return super()._validate_oapg(arg, validation_metadata=validation_metadata)

I think perhaps the problem is that the openapi schema is not complete? It would be great if we can disable the validation function for incoming (and optionally, outgoing) message. (because I think firefly iii server would already do its own data validation, so we don't have to do it in the client side?)

soraxas commented 7 months ago

Sorry, looks like this is a duplication of #18.

But it'd be good if you can re-visit this problem