amsdal_utils 0.4.5__py3-none-any.whl → 0.5.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
amsdal_utils/__about__.py CHANGED
@@ -1,4 +1,4 @@
1
1
  # SPDX-FileCopyrightText: 2023-present
2
2
  #
3
3
  # SPDX-License-Identifier: AMSDAL End User License Agreement
4
- __version__ = '0.4.5'
4
+ __version__ = '0.5.1'
@@ -72,6 +72,24 @@ class LegacyDictSchema(BaseModel):
72
72
  value_type: str
73
73
 
74
74
 
75
+ def process_one_of(data: dict[str, Any]) -> dict[str, Any]:
76
+ one_of = [
77
+ ao
78
+ for ao in data.pop('oneOf')
79
+ if ao not in [{'type': 'null'}, {'$ref': '#/$defs/Reference'}, {'$ref': '#/$defs/LegacyModel'}]
80
+ ]
81
+
82
+ for _one_of_item in one_of:
83
+ if not _one_of_item or '$ref' not in _one_of_item:
84
+ msg = f'Multiple oneOf should contain $ref. Currently: {one_of}'
85
+ raise ValueError(msg)
86
+
87
+ _types = [_one_of_item['$ref'].rsplit('/', 1)[-1] for _one_of_item in one_of]
88
+ data['type'] = '|'.join(_types)
89
+
90
+ return data
91
+
92
+
75
93
  def process_any_of(data: dict[str, Any], info: ValidationInfo) -> dict[str, Any]:
76
94
  _any_of = data.pop('anyOf')
77
95
  if _any_of in [[{'$ref': '#/$defs/Reference'}], [{'$ref': '#/$defs/Reference'}, {'type': 'null'}]]:
@@ -85,8 +103,13 @@ def process_any_of(data: dict[str, Any], info: ValidationInfo) -> dict[str, Any]
85
103
  ]
86
104
 
87
105
  if len(any_of) != 1:
88
- err_type = 'invalid_data'
89
- raise PydanticCustomError(err_type, 'Data must have exactly one non-null type in "anyOf"')
106
+ for _any_of_item in any_of:
107
+ if not _any_of_item or '$ref' not in _any_of_item:
108
+ msg = f'Multiple anyOf should contain $ref. Currently: {any_of}'
109
+ raise ValueError(msg)
110
+ _types = [_any_of_item['$ref'].rsplit('/', 1)[-1] for _any_of_item in any_of]
111
+
112
+ data['type'] = '|'.join(_types)
90
113
 
91
114
  _any_of_element = any_of[0]
92
115
 
@@ -186,6 +209,15 @@ class TypeData(BaseModel, extra='allow'):
186
209
  if 'anyOf' in data:
187
210
  data = process_any_of(data, info)
188
211
 
212
+ if 'oneOf' in data:
213
+ data = process_one_of(data)
214
+
215
+ if 'discriminator' in data and isinstance(data['discriminator'], dict):
216
+ try:
217
+ data['discriminator'] = data['discriminator']['propertyName']
218
+ except:
219
+ raise
220
+
189
221
  if 'type' not in data:
190
222
  data['type'] = 'object'
191
223
 
@@ -30,7 +30,6 @@ class PropertyData(TypeData, extra='allow'):
30
30
  field_name (str | None): The name of the field.
31
31
  field_id (str | None): The ID of the field.
32
32
  is_deleted (bool): Indicates if the property is deleted.
33
- db_field (list[str] | None): The database fields.
34
33
  """
35
34
 
36
35
  title: str | None = None
@@ -38,11 +37,10 @@ class PropertyData(TypeData, extra='allow'):
38
37
  field_name: str | None = None
39
38
  field_id: str | None = None
40
39
  is_deleted: bool = False
41
- db_field: list[str] | None = None
40
+ discriminator: str | None = None
42
41
 
43
- @model_validator(mode='before')
44
42
  @classmethod
45
- def format_openapi_parameters(cls, data: dict[str, Any], info: ValidationInfo) -> dict[str, Any]:
43
+ def _format_openapi_parameters(cls, data: dict[str, Any], info: ValidationInfo) -> dict[str, Any]:
46
44
  if '$ref' in data:
47
45
  if not info.context:
48
46
  msg = 'Context is required to resolve $ref'
@@ -59,11 +57,9 @@ class PropertyData(TypeData, extra='allow'):
59
57
  if 'anyOf' in _add_props:
60
58
  _add_props = process_any_of(_add_props, info)
61
59
 
62
- _type = _add_props.get('type', 'object')
63
-
64
60
  items = DictSchema(
65
61
  key=TypeData(type='string'),
66
- value=TypeData(type=CLASS_OPENAPI_PARAMETERS_MAPPER.get(_type, _type)),
62
+ value=TypeData(**cls._format_openapi_parameters(_add_props, info)),
67
63
  )
68
64
 
69
65
  if 'items' not in data:
@@ -74,6 +70,11 @@ class PropertyData(TypeData, extra='allow'):
74
70
 
75
71
  return {CLASS_OPENAPI_PARAMETERS_MAPPER.get(k, k): v for k, v in data.items()}
76
72
 
73
+ @model_validator(mode='before')
74
+ @classmethod
75
+ def format_openapi_parameters(cls, data: dict[str, Any], info: ValidationInfo) -> dict[str, Any]:
76
+ return cls._format_openapi_parameters(data, info)
77
+
77
78
  @model_validator(mode='after')
78
79
  def validate_options(self) -> 'PropertyData':
79
80
  if isinstance(getattr(self, 'enum', None), list) and not self.options:
@@ -101,6 +102,14 @@ class PropertyData(TypeData, extra='allow'):
101
102
  return self
102
103
 
103
104
 
105
+ class StorageMetadata(BaseModel, extra='allow'):
106
+ table_name: str | None = Field(None, title='Table name')
107
+ db_fields: dict[str, list[str]] | None = Field(None, title='Database property to fields mapping')
108
+ primary_key: list[str] | None = Field(None, title='Primary key fields')
109
+ indexed: list[list[str]] | None = Field(None, title='Indexed')
110
+ unique: list[list[str]] | None = Field(None, title='Unique Fields')
111
+
112
+
104
113
  class ObjectSchema(BaseModel, extra='allow'):
105
114
  r"""
106
115
  Schema for an object.
@@ -127,6 +136,7 @@ class ObjectSchema(BaseModel, extra='allow'):
127
136
  options: list[OptionItemData] | None = None
128
137
  meta_class: str = MetaClasses.CLASS_OBJECT.value
129
138
  custom_code: str | None = None
139
+ storage_metadata: StorageMetadata | None = None
130
140
 
131
141
  @model_validator(mode='before')
132
142
  @classmethod
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: amsdal_utils
3
- Version: 0.4.5
3
+ Version: 0.5.1
4
4
  Summary: Utils for AMSDAL data framework
5
5
  Project-URL: Documentation, https://pypi.org/project/amsdal_utils/#readme
6
6
  Project-URL: Issues, https://pypi.org/project/amsdal_utils/#issues
@@ -1,5 +1,5 @@
1
1
  amsdal_utils/Third-Party Materials - AMSDAL Dependencies - License Notices.md,sha256=blZRsT9Qg4u4LzZuxlWQOzlWGpLAg7DugWS6nz7s_yw,62595
2
- amsdal_utils/__about__.py,sha256=HQoXWCI9LqYb-j-ea1Ulejb3Ir-_CD3-UeZt8eLJTPQ,124
2
+ amsdal_utils/__about__.py,sha256=8T_uBHVYswzzhu1l92_ZGiaOtk_9NzrS_TQ0P-bqbf8,124
3
3
  amsdal_utils/__init__.py,sha256=EQCJ5OevmkkIpIULumPNIbWk3UI7afDfRzIsZN5mfwg,73
4
4
  amsdal_utils/errors.py,sha256=P90oGdKczHZzHukWnzJfbsSxMC-Sc8dUXvHzP7b1IIA,129
5
5
  amsdal_utils/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -25,7 +25,7 @@ amsdal_utils/models/base.py,sha256=jcY7ZE6n0lANGjg87sEwlz6val_8ZRHWaCmNZo9Oxnc,1
25
25
  amsdal_utils/models/enums.py,sha256=1iuixjmfHMIMDM3rEQ1YUjOPF3aV_OEoPq61I61KvGI,745
26
26
  amsdal_utils/models/data_models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
27
27
  amsdal_utils/models/data_models/address.py,sha256=haQmHYfQcQdejgM1KrNIylfNS-0R0KEDH4v2I8sjIWo,6600
28
- amsdal_utils/models/data_models/core.py,sha256=tRFy95RrsdyKJFIyxqBWbVawReuWyyWr2jZT1pRLBhs,7494
28
+ amsdal_utils/models/data_models/core.py,sha256=F1UpyJ4efAvb-BEWzxwdDVpUMP19hMO41T0QoOvdHbU,8566
29
29
  amsdal_utils/models/data_models/enums.py,sha256=qDJDPU5oxPlSNENFNf3PPgxiFJYbTM8OOE8stMmYYHc,4130
30
30
  amsdal_utils/models/data_models/metadata.py,sha256=J9r7K2_coE2qD3au-Y7wS2YXcjMUOkW_kx3Gubr3Oyg,2979
31
31
  amsdal_utils/models/data_models/reference.py,sha256=hA-06Dq64oMVNv6L6DIelpraxpQJAPiHf4_3UqLmuw4,5098
@@ -49,7 +49,7 @@ amsdal_utils/query/data_models/paginator.py,sha256=oDEWEdyrEBBkHXyrS4K2mglYVw8An
49
49
  amsdal_utils/query/data_models/query_specifier.py,sha256=7rEVChU2XPy-3ooaTgfSZGKIOyIIKn8245MMuWrv3Mk,469
50
50
  amsdal_utils/schemas/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
51
51
  amsdal_utils/schemas/interfaces.py,sha256=XJGw45IE7E1HjYArdz2LELOcx15PeTw4L1V34atKm6Y,773
52
- amsdal_utils/schemas/schema.py,sha256=K4sUhxWKARg8IoO3-iYKiNWwmijFKYpxmjIDQS9Gy5E,5950
52
+ amsdal_utils/schemas/schema.py,sha256=kVstZBTJyeR_P7DJZ3Dblv1whj_2BtWg4CLXGkYQ5Js,6493
53
53
  amsdal_utils/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
54
54
  amsdal_utils/utils/classes.py,sha256=GeJIt-jxOHgMnlEHMmzNk9vwxv4_V5dLP-Fv89hN5hc,354
55
55
  amsdal_utils/utils/decorators.py,sha256=RCWbbQJ2hY2s-uAI0C5M0X8gTXqUbL1Gx9NxACYBMOA,992
@@ -57,7 +57,7 @@ amsdal_utils/utils/identifier.py,sha256=oP3CHd2i8EBHMVUC8DWLr9pFZBt1IdH7Falaa3M2
57
57
  amsdal_utils/utils/lazy_object.py,sha256=eIVHBDNCSHKQopzYjviPCuh0svbRJQOCZ8KzqFLiS-s,2115
58
58
  amsdal_utils/utils/singleton.py,sha256=DbgQVJdeftO8sGVm2ti4zf4KDaDd2ogclO3B6gxfqag,744
59
59
  amsdal_utils/utils/text.py,sha256=4L5aICJGbmFZwNUhMrACb5thqmcIaWb3aVD24lW24a0,1962
60
- amsdal_utils-0.4.5.dist-info/METADATA,sha256=_wkKuSJDrHCl0Zax_pv-HWMHIJwclWdqROWvIYFc_W8,57431
61
- amsdal_utils-0.4.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
62
- amsdal_utils-0.4.5.dist-info/licenses/LICENSE.txt,sha256=hG-541PFYfNJi9WRZi_hno91UyqNg7YLK8LR3vLblZA,27355
63
- amsdal_utils-0.4.5.dist-info/RECORD,,
60
+ amsdal_utils-0.5.1.dist-info/METADATA,sha256=ngtpWnIxQ-x8j08FQ4t1sQQjNH_e4KyumFGwqFZWxzs,57431
61
+ amsdal_utils-0.5.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
62
+ amsdal_utils-0.5.1.dist-info/licenses/LICENSE.txt,sha256=hG-541PFYfNJi9WRZi_hno91UyqNg7YLK8LR3vLblZA,27355
63
+ amsdal_utils-0.5.1.dist-info/RECORD,,