ul-api-utils 7.8.7__py3-none-any.whl → 7.9.0__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,12 +1,12 @@
1
1
  import argparse
2
2
  import ast
3
+ import csv
3
4
  import importlib
4
5
  import inspect
5
6
  import os
6
7
  import logging
7
8
  from datetime import datetime
8
- from typing import Dict, Callable, Any, List, TextIO
9
-
9
+ from typing import Dict, Callable, Any, List, TextIO, Set
10
10
  from flask import url_for, Flask
11
11
  from ul_py_tool.commands.cmd import Cmd
12
12
 
@@ -20,11 +20,13 @@ class CmdGenApiFunctionDocumentation(Cmd):
20
20
  db_dir: str
21
21
  include_api_utils_doc: bool
22
22
  include_db_utils_doc: bool
23
+ app_host: str
23
24
 
24
25
  @staticmethod
25
26
  def add_parser_args(parser: argparse.ArgumentParser) -> None:
26
27
  parser.add_argument('--api-dir', dest='api_dir', type=str, required=True)
27
28
  parser.add_argument('--db-dir', dest='db_dir', type=str, required=True)
29
+ parser.add_argument('--app-host', dest='app_host', type=str, required=False, default="{baseUrl}")
28
30
  parser.add_argument('--include-utils-api', dest='include_api_utils_doc', type=bool, required=False, default=False)
29
31
  parser.add_argument('--include-utils-db', dest='include_db_utils_doc', type=bool, required=False, default=False)
30
32
 
@@ -45,27 +47,41 @@ class CmdGenApiFunctionDocumentation(Cmd):
45
47
  db_helper_functions = self.load_functions(f'{self.db_dir}/models_manager')
46
48
  db_utils_functions = self.load_functions(f"{self.db_dir}/utils")
47
49
  with current_app.app_context():
48
- current_app.config['SERVER_NAME'] = '{base_url}'
49
- with current_app.app_context(), open(f'.tmp/api_doc_{datetime.now().isoformat()}.md', 'w') as file:
50
- for api_route_id, flask_api_rule in enumerate(current_app.url_map.iter_rules()):
51
- options = {}
52
- for arg in flask_api_rule.arguments:
53
- options[arg] = "[{0}]".format(arg)
54
- api_route_methods = ','.join([method for method in flask_api_rule.methods if method not in ('HEAD', 'OPTIONS')]) # type: ignore
55
- api_route_path = url_for(flask_api_rule.endpoint, **options).replace('%5B', '[').replace('%5D', ']')
56
- func_object = current_app.view_functions[flask_api_rule.endpoint]
57
- if not func_object.__module__.startswith(self.api_module):
58
- continue
59
- self.generate_documentation(
60
- func_object,
61
- file,
62
- api_route_id=api_route_id,
63
- api_route_path=api_route_path,
64
- api_route_methods=api_route_methods,
65
- loaded_db_helper_functions=db_helper_functions,
66
- loaded_api_utils_functions=api_utils_functions,
67
- loaded_db_utils_functions=db_utils_functions,
68
- )
50
+ current_app.config['SERVER_NAME'] = self.app_host
51
+ csv_data: List[Dict[str, str]] = []
52
+ with current_app.app_context():
53
+ now = datetime.now().isoformat()
54
+ filename = f'.tmp/{now}-doc.md'
55
+ with open(filename, 'w') as file:
56
+ for api_route_id, flask_api_rule in enumerate(current_app.url_map.iter_rules()):
57
+ options = {}
58
+ for arg in flask_api_rule.arguments:
59
+ options[arg] = "[{0}]".format(arg)
60
+ api_route_methods = ','.join([method for method in flask_api_rule.methods if method not in ('HEAD', 'OPTIONS')]) # type: ignore
61
+ api_route_path = url_for(flask_api_rule.endpoint, **options).replace('%5B', '[').replace('%5D', ']')
62
+ func_object = current_app.view_functions[flask_api_rule.endpoint]
63
+ if not func_object.__module__.startswith(self.api_module):
64
+ continue
65
+ csv_data.append({
66
+ "api_path": api_route_path,
67
+ "api_methods": api_route_methods,
68
+ "api_function_name": func_object.__name__,
69
+ })
70
+ self.generate_documentation(
71
+ func_object,
72
+ file,
73
+ api_route_id=api_route_id,
74
+ api_route_path=api_route_path,
75
+ api_route_methods=api_route_methods,
76
+ loaded_db_helper_functions=db_helper_functions,
77
+ loaded_api_utils_functions=api_utils_functions,
78
+ loaded_db_utils_functions=db_utils_functions,
79
+ )
80
+ with open(f'.tmp/{now}-doc.csv', 'w') as csvfile:
81
+ fields = ['api_path', 'api_methods', 'api_function_name']
82
+ writer = csv.DictWriter(csvfile, fieldnames=fields)
83
+ writer.writeheader()
84
+ writer.writerows(csv_data)
69
85
 
70
86
  @staticmethod
71
87
  def load_functions(directory: str) -> Dict[str, Callable[..., Any]]:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ul-api-utils
3
- Version: 7.8.7
3
+ Version: 7.9.0
4
4
  Summary: Python api utils
5
5
  Author: Unic-lab
6
6
  Author-email:
@@ -33,7 +33,7 @@ ul_api_utils/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3h
33
33
  ul_api_utils/commands/cmd_enc_keys.py,sha256=-Tblh6lI7G6M5YVwbVQqZmXhBMiIpB3a7b0Lv1MFufk,8453
34
34
  ul_api_utils/commands/cmd_gen_api_user_token.py,sha256=Vg7oEYHvof7DSLat9yJ_k5AYL9ZOC4Jvd38DBn5U-R0,2730
35
35
  ul_api_utils/commands/cmd_gen_new_api_user.py,sha256=ICZbKqz2D6DRvjwtNM08rNjIlWN3qClcUQw5L8FxRBY,4549
36
- ul_api_utils/commands/cmd_generate_api_docs.py,sha256=t4wIVN6cdQLN7FX7_RWxGy0D8tUSe4bs2_HNVdLrwKk,8788
36
+ ul_api_utils/commands/cmd_generate_api_docs.py,sha256=cEBUOkn8iQIir78yXzHK_gy_hna2cP58x8N5DzCeZEA,9617
37
37
  ul_api_utils/commands/cmd_start.py,sha256=aMz6o6HBzLxWrNpV2_rayQ7Nb-VX3-DHgzOUk39R7NA,3623
38
38
  ul_api_utils/commands/cmd_worker_start.py,sha256=1tt4_mL8T8_q7i1bqnfjPSkSYlRNNNp8eJ-5rTYj36w,2593
39
39
  ul_api_utils/commands/start/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -135,9 +135,9 @@ ul_api_utils/validators/validate_empty_object.py,sha256=3Ck_iwyJE_M5e7l6s1i88aqb
135
135
  ul_api_utils/validators/validate_uuid.py,sha256=EfvlRirv2EW0Z6w3s8E8rUa9GaI8qXZkBWhnPs8NFrA,257
136
136
  ul_api_utils/validators/__tests__/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
137
137
  ul_api_utils/validators/__tests__/test_custom_fields.py,sha256=QLZ7DFta01Z7DOK9Z5Iq4uf_CmvDkVReis-GAl_QN48,1447
138
- ul_api_utils-7.8.7.dist-info/LICENSE,sha256=6Qo8OdcqI8aGrswJKJYhST-bYqxVQBQ3ujKdTSdq-80,1062
139
- ul_api_utils-7.8.7.dist-info/METADATA,sha256=FQg9L90kCARNwhkLhbOoByS6PZZfI4uGpK8ItUG3R4Q,14671
140
- ul_api_utils-7.8.7.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
141
- ul_api_utils-7.8.7.dist-info/entry_points.txt,sha256=8tL3ySHWTyJMuV1hx1fHfN8zumDVOCOm63w3StphkXg,53
142
- ul_api_utils-7.8.7.dist-info/top_level.txt,sha256=1XsW8iOSFaH4LOzDcnNyxHpHrbKU3fSn-aIAxe04jmw,21
143
- ul_api_utils-7.8.7.dist-info/RECORD,,
138
+ ul_api_utils-7.9.0.dist-info/LICENSE,sha256=6Qo8OdcqI8aGrswJKJYhST-bYqxVQBQ3ujKdTSdq-80,1062
139
+ ul_api_utils-7.9.0.dist-info/METADATA,sha256=eC9Hz_VF7dWCNKiXCMuO8VHqEs31pOTrADzM3UK90lQ,14671
140
+ ul_api_utils-7.9.0.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
141
+ ul_api_utils-7.9.0.dist-info/entry_points.txt,sha256=8tL3ySHWTyJMuV1hx1fHfN8zumDVOCOm63w3StphkXg,53
142
+ ul_api_utils-7.9.0.dist-info/top_level.txt,sha256=1XsW8iOSFaH4LOzDcnNyxHpHrbKU3fSn-aIAxe04jmw,21
143
+ ul_api_utils-7.9.0.dist-info/RECORD,,