Coverage for fingerprint_server_sdk / models / sdk.py: 66%

44 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-03-11 18:41 +0000

1""" 

2Server API 

3Fingerprint Server API allows you to get, search, and update Events in a server environment. It can be used for data exports, decision-making, and data analysis scenarios. 

4Server API is intended for server-side usage, it's not intended to be used from the client side, whether it's a browser or a mobile device. 

5 

6The version of the OpenAPI document: 4 

7Contact: support@fingerprint.com 

8Generated by OpenAPI Generator (https://openapi-generator.tech) 

9 

10Do not edit the class manually. 

11""" # noqa: E501 

12 

13from __future__ import annotations 

14 

15import json 

16import pprint 

17import re # noqa: F401 

18from typing import Any, ClassVar, Optional 

19 

20from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator 

21from typing_extensions import Self 

22 

23from fingerprint_server_sdk.models.integration import Integration 

24 

25 

26class SDK(BaseModel): 

27 """ 

28 Contains information about the SDK used to perform the request. 

29 """ 

30 

31 platform: StrictStr = Field( 

32 description='Platform of the SDK used for the identification request.' 

33 ) 

34 version: StrictStr = Field( 

35 description='Version string of the SDK used for the identification request. For example: `"3.12.1"` ' 

36 ) 

37 integrations: Optional[list[Integration]] = None 

38 __properties: ClassVar[list[str]] = ['platform', 'version', 'integrations'] 

39 

40 @field_validator('platform') 

41 def platform_validate_enum(cls, value: Any) -> Any: 

42 """Validates the enum""" 

43 if value not in set(['js', 'android', 'ios', 'unknown']): 

44 raise ValueError("must be one of enum values ('js', 'android', 'ios', 'unknown')") 

45 return value 

46 

47 model_config = ConfigDict( 

48 populate_by_name=True, 

49 validate_assignment=True, 

50 protected_namespaces=(), 

51 ) 

52 

53 def to_str(self) -> str: 

54 """Returns the string representation of the model using alias""" 

55 return pprint.pformat(self.model_dump(by_alias=True)) 

56 

57 def to_json(self) -> str: 

58 """Returns the JSON representation of the model using alias""" 

59 # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead 

60 return json.dumps(self.to_dict()) 

61 

62 @classmethod 

63 def from_json(cls, json_str: str) -> Optional[Self]: 

64 """Create an instance of SDK from a JSON string""" 

65 return cls.from_dict(json.loads(json_str)) 

66 

67 def to_dict(self) -> dict[str, Any]: 

68 """Return the dictionary representation of the model using alias. 

69 

70 This has the following differences from calling pydantic's 

71 `self.model_dump(by_alias=True)`: 

72 

73 * `None` is only added to the output dict for nullable fields that 

74 were set at model initialization. Other fields with value `None` 

75 are ignored. 

76 """ 

77 excluded_fields: set[str] = set([]) 

78 

79 _dict = self.model_dump( 

80 by_alias=True, 

81 exclude=excluded_fields, 

82 exclude_none=True, 

83 ) 

84 # override the default output from pydantic by calling `to_dict()` of each item in integrations (list) 

85 _items = [] 

86 if self.integrations: 

87 for _item_integrations in self.integrations: 

88 if _item_integrations: 

89 _items.append(_item_integrations.to_dict()) 

90 _dict['integrations'] = _items 

91 return _dict 

92 

93 @classmethod 

94 def from_dict(cls, obj: Optional[dict[str, Any]]) -> Optional[Self]: 

95 """Create an instance of SDK from a dict""" 

96 if obj is None: 

97 return None 

98 

99 if not isinstance(obj, dict): 

100 return cls.model_validate(obj) 

101 

102 _obj = cls.model_validate( 

103 { 

104 'platform': obj.get('platform'), 

105 'version': obj.get('version'), 

106 'integrations': [Integration.from_dict(_item) for _item in obj['integrations']] 

107 if obj.get('integrations') is not None 

108 else None, 

109 } 

110 ) 

111 return _obj