ul-api-utils 7.10.6__py3-none-any.whl → 7.10.8__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.

Potentially problematic release.


This version of ul-api-utils might be problematic. Click here for more details.

@@ -1,4 +1,5 @@
1
1
  import logging
2
+ from enum import IntEnum, Enum
2
3
  from time import sleep
3
4
  from datetime import datetime, timedelta
4
5
  from typing import List, Optional, Tuple
@@ -43,14 +44,18 @@ class RespObject(JsonApiResponsePayload):
43
44
  notes: str = ''
44
45
 
45
46
 
47
+ class Eeenum(IntEnum):
48
+ one = 1
49
+ two = 2
50
+
46
51
  class SomeBody(BaseModel):
47
52
  seconds: float
48
-
53
+ eenum: Optional[Eeenum]
49
54
 
50
55
  class Some2Query(ApiRequestQuery):
51
56
  sleep: float = 0.4
52
57
  some: QueryParamsSeparatedList[str] = '' # type: ignore
53
-
58
+ eenum: Optional[Eeenum]
54
59
 
55
60
  logger = logging.getLogger(__name__)
56
61
 
@@ -78,9 +83,14 @@ def some5(api_resource: ApiResource, body: SomeBody) -> JsonApiResponse[List[Res
78
83
  RespObject(now=datetime.now() + timedelta(seconds=body.seconds * 2)),
79
84
  ], 2)
80
85
 
86
+ class Eennum(Enum):
87
+ one = 'one'
88
+ two = 'two'
81
89
 
82
90
  class Some7Query(ApiRequestQuery):
83
91
  need_redirect: int
92
+ eenum: Optional[Eeenum]
93
+ eennum: Optional[Eennum]
84
94
 
85
95
 
86
96
  @sdk.rest_api('POST', '/example-resource-simple-any', access=sdk.ACCESS_PUBLIC)
@@ -48,9 +48,7 @@ def init_socket_io(config: SocketIOConfig | None) -> SocketIO | None:
48
48
  if config.app_type is SocketIOConfigType.EXTERNAL_PROCESS:
49
49
  socket_io = SocketIO(
50
50
  message_queue=config.message_queue,
51
- async_mode=SocketAsyncModesEnum.GEVENT.value,
52
51
  channel=config.channel,
53
- cors_allowed_origins=config.cors_allowed_origins,
54
52
  logger=config.logs_enabled,
55
53
  engineio_logger=config.engineio_logs_enabled,
56
54
  )
@@ -378,6 +378,7 @@ class SwaggerQueryParameter(SwaggerModel):
378
378
  name: Optional[str] = None,
379
379
  description: Optional[str] = None,
380
380
  required: bool = True,
381
+ enum: Optional[list] = None,
381
382
  ) -> None:
382
383
  super(SwaggerQueryParameter, self).__init__()
383
384
  self.input_type = InputType.from_string(input_type) # type: ignore
@@ -386,6 +387,7 @@ class SwaggerQueryParameter(SwaggerModel):
386
387
  self.name = name
387
388
  self.description = f'description: {description}' if description else ''
388
389
  self.required = required
390
+ self.enum = enum
389
391
 
390
392
  def perform_write(self, file) -> None: # type: ignore
391
393
  if self.input_type.value == InputType.UUID:
@@ -407,25 +409,48 @@ class SwaggerQueryParameter(SwaggerModel):
407
409
  ),
408
410
  )
409
411
  else:
410
- parameter_entry = inspect.cleandoc(
411
- """
412
- - in: query
413
- name: {name}
414
- schema:
415
- type: {input_type}
416
- {input_format}
417
- {default_value}
418
- {description}
419
- required: {required}
420
- """.format(
421
- name=self.name,
422
- required=self.required,
423
- description=self.description,
424
- input_type=self.input_type.value,
425
- input_format=self.input_format,
426
- default_value=self.default_value,
427
- ),
428
- )
412
+ if self.enum is not None:
413
+ parameter_entry = inspect.cleandoc(
414
+ """
415
+ - in: query
416
+ name: {name}
417
+ schema:
418
+ type: {input_type}
419
+ {input_format}
420
+ enum: {enum}
421
+ {default_value}
422
+ {description}
423
+ required: {required}
424
+ """.format(
425
+ name=self.name,
426
+ required=self.required,
427
+ description=self.description,
428
+ input_type=self.input_type.value,
429
+ input_format=self.input_format,
430
+ default_value=self.default_value,
431
+ enum=self.enum,
432
+ ),
433
+ )
434
+ else:
435
+ parameter_entry = inspect.cleandoc(
436
+ """
437
+ - in: query
438
+ name: {name}
439
+ schema:
440
+ type: {input_type}
441
+ {input_format}
442
+ {default_value}
443
+ {description}
444
+ required: {required}
445
+ """.format(
446
+ name=self.name,
447
+ required=self.required,
448
+ description=self.description,
449
+ input_type=self.input_type.value,
450
+ input_format=self.input_format,
451
+ default_value=self.default_value,
452
+ ),
453
+ )
429
454
 
430
455
  param = self.indent(parameter_entry, 3 * self.TAB)
431
456
  file.write(param)
@@ -484,6 +509,7 @@ class SwaggerPath(SwaggerModel):
484
509
  swagger_request_type.add_swagger_model(parameters)
485
510
  query_schema = query_model.schema()
486
511
  query_required_fields = set(query_schema.get('required')) if query_schema.get('required') is not None else set()
512
+ query_definitions = query_schema.get('definitions')
487
513
  for parameter_name, parameter_spec in query_schema.get('properties').items():
488
514
  if parameter_spec.get('type') is not None:
489
515
  parameter_models.add(SwaggerQueryParameter(
@@ -494,6 +520,17 @@ class SwaggerPath(SwaggerModel):
494
520
  description=parameter_spec.get('description'),
495
521
  required=parameter_name in query_required_fields,
496
522
  ))
523
+ elif parameter_spec.get('$ref') is not None:
524
+ definition = query_definitions.get(parameter_spec.get('$ref', '').split('/')[-1], {})
525
+ parameter_models.add(SwaggerQueryParameter(
526
+ input_type=definition.get('type', 'string'),
527
+ input_format=definition.get('format'),
528
+ default_value=definition.get('default'),
529
+ name=parameter_name,
530
+ description=definition.get('description'),
531
+ enum=definition.get('enum'),
532
+ required=parameter_name in query_required_fields,
533
+ ))
497
534
  if isinstance(parameters, SwaggerModel):
498
535
  parameters.add_swagger_models(parameter_models)
499
536
  elif isinstance(parameters, list):
@@ -3,13 +3,12 @@ import redis
3
3
  import ormsgpack
4
4
  import collections
5
5
 
6
- from pydantic import BaseModel, ValidationError
6
+ from pydantic import ValidationError, parse_obj_as, BaseModel
7
7
  from typing import Any, Type, overload, Iterator, KeysView, cast
8
8
 
9
9
  from ul_api_utils.utils.instance_checks import isinstance_namedtuple
10
10
  from ul_api_utils.utils.memory_db.errors import CompositeKeyError, UnsupportedParsingType
11
11
 
12
-
13
12
  CompositeKeyT = tuple[str, Type[BaseModel]]
14
13
  AnyKeyT = str | CompositeKeyT
15
14
  AnyT = Any
@@ -59,10 +58,9 @@ class BaseMemoryDbRepository(collections.abc.MutableMapping[str, AnyT]):
59
58
  raise UnsupportedParsingType(f"Unsupported parsing type {_parse_as_type}.")
60
59
  value = ormsgpack.unpackb(self._db[composite_key_name])
61
60
  try:
62
- model_fields = _parse_as_type.__fields_set__
63
61
  if isinstance(value, list):
64
- return [_parse_as_type.construct(_fields_set=model_fields, **obj) for obj in value]
65
- return _parse_as_type.construct(_fields_set=model_fields, **value)
62
+ return parse_obj_as(list[_parse_as_type], value) # type: ignore
63
+ return parse_obj_as(_parse_as_type, value)
66
64
  except ValidationError:
67
65
  raise UnsupportedParsingType(f"Could not parse the value of key '{composite_key_name}' with type {_parse_as_type}") from None
68
66
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ul-api-utils
3
- Version: 7.10.6
3
+ Version: 7.10.8
4
4
  Summary: Python api utils
5
5
  Author: Unic-lab
6
6
  Author-email:
@@ -6,7 +6,7 @@ example/pure_flask_example.py,sha256=A7cbcjTr28FS1sVNAsQbj1N9EgEFIXDB4aRwOV6_tbU
6
6
  example/rate_limit_load.py,sha256=U2Bgp8UztT4TNKdv9NVioxWfE68aCsC7uKz7xPCy6XM,225
7
7
  example/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
8
  example/routes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
- example/routes/api_some.py,sha256=fnFO1uFQx-oypCqPNkUfueABrTsAWLdB5spRnhWSZ58,12790
9
+ example/routes/api_some.py,sha256=JN7_MT4zDlXTsPLDJiYUQayjezZ-ti0HVY-OBCDt2gI,13032
10
10
  example/sockets/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
11
  example/sockets/on_connect.py,sha256=3sluHnVT_-e2Oa4YsRZUJIc2L4VnMSJu5rgI_mkg8BQ,411
12
12
  example/sockets/on_disconnect.py,sha256=ev0uJutqmTSsbrBcQIRudBX-6g7uSmZj8Imuf6pVIMU,277
@@ -78,7 +78,7 @@ ul_api_utils/resources/debugger_scripts.py,sha256=qqf6zeJ1aE_STNYX1j9-ZfBgB_jcQo
78
78
  ul_api_utils/resources/not_implemented.py,sha256=OQE5LGA4KqZDwP5Wtub3Aw-icwzbqCSKcEFoFp4w7_k,973
79
79
  ul_api_utils/resources/permissions.py,sha256=8c8cEPkm69zxgXbDiwUkW6Mi_496-MZXbPOxHITetKs,1436
80
80
  ul_api_utils/resources/rate_limitter.py,sha256=QMpaLu1LoFbvtIEhxF8HbAZIAW4oGKTClt7XEUsqx98,3358
81
- ul_api_utils/resources/socketio.py,sha256=OzPmHITp3YF5KGVHAwY8DEcKx0PldvXrUhzfkortT64,1979
81
+ ul_api_utils/resources/socketio.py,sha256=oeQdULtBnslyMJkeqfZMWxtK6efLFX1LrfA2cBPhOUo,1859
82
82
  ul_api_utils/resources/swagger.py,sha256=fK8S9X4YCSqe_weCzV_BcMPoL_NR073BsGUzn2ImbHI,5391
83
83
  ul_api_utils/resources/health_check/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
84
84
  ul_api_utils/resources/health_check/const.py,sha256=QzVZP_ZKmVKleUACiOGjzP-v54FD7tEN6NEF4Jb50Ow,78
@@ -124,7 +124,7 @@ ul_api_utils/utils/flask_swagger_generator/exceptions.py,sha256=yA4IsUyxh5puyoYz
124
124
  ul_api_utils/utils/flask_swagger_generator/specifiers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
125
125
  ul_api_utils/utils/flask_swagger_generator/specifiers/swagger_models.py,sha256=eMRDP60GUbIuBGinFPfjp7VsnbgmzockTsIT-KadchA,1690
126
126
  ul_api_utils/utils/flask_swagger_generator/specifiers/swagger_specifier.py,sha256=9Cf1ijk90IDYUDG8kTjK4cxjdxpYjWZz1tKJHPCeDAA,1513
127
- ul_api_utils/utils/flask_swagger_generator/specifiers/swagger_three_specifier.py,sha256=n_eZkIu-n73ZH7lHErpnq7oGw7C7POf38OgXwWxlBJE,28944
127
+ ul_api_utils/utils/flask_swagger_generator/specifiers/swagger_three_specifier.py,sha256=ofFePEc7wXu1H5_Q5L12JM2HXvqG2HjaKvDj0bhlG6k,30812
128
128
  ul_api_utils/utils/flask_swagger_generator/specifiers/swagger_version.py,sha256=A14IRG-e2KL2SlFbHep2FH0uMRIHPhfd7KLkYdtWrfA,1312
129
129
  ul_api_utils/utils/flask_swagger_generator/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
130
130
  ul_api_utils/utils/flask_swagger_generator/utils/input_type.py,sha256=Ynp3zI5q1F0Tl_eTdNbWoCxRKPwBCJkwJOoeHE2pTRE,2533
@@ -138,7 +138,7 @@ ul_api_utils/utils/jinja/t_url_for.py,sha256=PG9W4UbkWv2pLXNMQiCt22vp4sDi-Uz5w2u
138
138
  ul_api_utils/utils/jinja/to_pretty_json.py,sha256=wcc_EJ6yM4lipE0Vr6cgYOB-rBk7_j_Wa7bijjI_bCs,302
139
139
  ul_api_utils/utils/memory_db/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
140
140
  ul_api_utils/utils/memory_db/errors.py,sha256=Bw1O1Y_WTCeCRNgb9iwrGT1fst6iHORhrNstwxiaUu8,267
141
- ul_api_utils/utils/memory_db/repository.py,sha256=dLg8vyYLxWwTFrCo0Mv0fxJGYJOWV4y-U65tG_wK1Uk,3482
141
+ ul_api_utils/utils/memory_db/repository.py,sha256=c_4BJuakhAtf0X3nlIKeWI4bsb1Wf2CK0xjKdY4_o-I,3395
142
142
  ul_api_utils/utils/memory_db/__tests__/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
143
143
  ul_api_utils/validators/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
144
144
  ul_api_utils/validators/custom_fields.py,sha256=iqDnAvO-Bs13ZtLtccAG8SdJ8jWDlVcW6_ckChrTdXQ,4023
@@ -146,9 +146,9 @@ ul_api_utils/validators/validate_empty_object.py,sha256=3Ck_iwyJE_M5e7l6s1i88aqb
146
146
  ul_api_utils/validators/validate_uuid.py,sha256=EfvlRirv2EW0Z6w3s8E8rUa9GaI8qXZkBWhnPs8NFrA,257
147
147
  ul_api_utils/validators/__tests__/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
148
148
  ul_api_utils/validators/__tests__/test_custom_fields.py,sha256=QLZ7DFta01Z7DOK9Z5Iq4uf_CmvDkVReis-GAl_QN48,1447
149
- ul_api_utils-7.10.6.dist-info/LICENSE,sha256=6Qo8OdcqI8aGrswJKJYhST-bYqxVQBQ3ujKdTSdq-80,1062
150
- ul_api_utils-7.10.6.dist-info/METADATA,sha256=ewir03FvSTWnMH-6ZbqpAReZPjMva5hmV-3ifoBoGc4,14715
151
- ul_api_utils-7.10.6.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
152
- ul_api_utils-7.10.6.dist-info/entry_points.txt,sha256=8tL3ySHWTyJMuV1hx1fHfN8zumDVOCOm63w3StphkXg,53
153
- ul_api_utils-7.10.6.dist-info/top_level.txt,sha256=1XsW8iOSFaH4LOzDcnNyxHpHrbKU3fSn-aIAxe04jmw,21
154
- ul_api_utils-7.10.6.dist-info/RECORD,,
149
+ ul_api_utils-7.10.8.dist-info/LICENSE,sha256=6Qo8OdcqI8aGrswJKJYhST-bYqxVQBQ3ujKdTSdq-80,1062
150
+ ul_api_utils-7.10.8.dist-info/METADATA,sha256=hfUgEuBg6yRPvKqT6czDB8u-C0Bz-CEAhg23mw1JDeY,14715
151
+ ul_api_utils-7.10.8.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
152
+ ul_api_utils-7.10.8.dist-info/entry_points.txt,sha256=8tL3ySHWTyJMuV1hx1fHfN8zumDVOCOm63w3StphkXg,53
153
+ ul_api_utils-7.10.8.dist-info/top_level.txt,sha256=1XsW8iOSFaH4LOzDcnNyxHpHrbKU3fSn-aIAxe04jmw,21
154
+ ul_api_utils-7.10.8.dist-info/RECORD,,