polyapi-python 0.2.5.dev8__py3-none-any.whl → 0.2.5.dev9__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.
- polyapi/schema.py +16 -0
- polyapi/utils.py +5 -19
- {polyapi_python-0.2.5.dev8.dist-info → polyapi_python-0.2.5.dev9.dist-info}/METADATA +1 -1
- {polyapi_python-0.2.5.dev8.dist-info → polyapi_python-0.2.5.dev9.dist-info}/RECORD +7 -7
- {polyapi_python-0.2.5.dev8.dist-info → polyapi_python-0.2.5.dev9.dist-info}/LICENSE +0 -0
- {polyapi_python-0.2.5.dev8.dist-info → polyapi_python-0.2.5.dev9.dist-info}/WHEEL +0 -0
- {polyapi_python-0.2.5.dev8.dist-info → polyapi_python-0.2.5.dev9.dist-info}/top_level.txt +0 -0
polyapi/schema.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import logging
|
|
1
2
|
import contextlib
|
|
2
3
|
from typing import Dict
|
|
3
4
|
from jsonschema_gentypes.cli import process_config
|
|
@@ -31,6 +32,21 @@ def _temp_store_input_data(input_data: Dict) -> str:
|
|
|
31
32
|
return temp_file.name
|
|
32
33
|
|
|
33
34
|
|
|
35
|
+
def wrapped_generate_schema_types(type_spec: dict, root, fallback_type):
|
|
36
|
+
if not root:
|
|
37
|
+
root = "MyList" if fallback_type == "List" else "MyDict"
|
|
38
|
+
|
|
39
|
+
try:
|
|
40
|
+
return clean_title(root), generate_schema_types(type_spec, root=root)
|
|
41
|
+
except RecursionError:
|
|
42
|
+
# some schemas are so huge, our library cant handle it
|
|
43
|
+
# TODO identify critical recursion penalty and maybe switch underlying logic to iterative?
|
|
44
|
+
return fallback_type, ""
|
|
45
|
+
except:
|
|
46
|
+
logging.exception(f"Error when generating schema type: {type_spec}")
|
|
47
|
+
return fallback_type, ""
|
|
48
|
+
|
|
49
|
+
|
|
34
50
|
def generate_schema_types(input_data: Dict, root=None):
|
|
35
51
|
"""takes in a Dict representing a schema as input then appends the resulting python code to the output file"""
|
|
36
52
|
_cleanup_input_for_gentypes(input_data)
|
polyapi/utils.py
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import re
|
|
2
2
|
import os
|
|
3
|
-
import logging
|
|
4
3
|
from typing import Tuple, List
|
|
5
4
|
from colorama import Fore, Style
|
|
6
5
|
from polyapi.constants import BASIC_PYTHON_TYPES
|
|
7
6
|
from polyapi.typedefs import PropertySpecification, PropertyType
|
|
8
|
-
from polyapi.schema import
|
|
7
|
+
from polyapi.schema import wrapped_generate_schema_types, clean_title, map_primitive_types
|
|
9
8
|
|
|
10
9
|
|
|
11
10
|
# this string should be in every __init__ file.
|
|
12
11
|
# it contains all the imports needed for the function or variable code to run
|
|
13
12
|
CODE_IMPORTS = "from typing import List, Dict, Any, TypedDict, Optional, Callable\nimport logging\nimport requests\nimport socketio # type: ignore\nfrom polyapi.config import get_api_key_and_url\nfrom polyapi.execute import execute, execute_post, variable_get, variable_update\n\n"
|
|
13
|
+
FALLBACK_TYPES = {"Dict", "List"}
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
def init_the_init(full_path: str) -> None:
|
|
@@ -96,11 +96,7 @@ def get_type_and_def(type_spec: PropertyType) -> Tuple[str, str]:
|
|
|
96
96
|
if type_spec.get("items"):
|
|
97
97
|
items = type_spec["items"]
|
|
98
98
|
if items.get("$ref"):
|
|
99
|
-
|
|
100
|
-
return "ResponseType", generate_schema_types(type_spec, root="ResponseType") # type: ignore
|
|
101
|
-
except:
|
|
102
|
-
logging.exception(f"Error when generating schema type: {type_spec}")
|
|
103
|
-
return "Dict", ""
|
|
99
|
+
return wrapped_generate_schema_types(type_spec, "ResponseType", "Dict") # type: ignore
|
|
104
100
|
else:
|
|
105
101
|
item_type, _ = get_type_and_def(items)
|
|
106
102
|
title = f"List[{item_type}]"
|
|
@@ -116,12 +112,7 @@ def get_type_and_def(type_spec: PropertyType) -> Tuple[str, str]:
|
|
|
116
112
|
title = schema.get("title", "")
|
|
117
113
|
if title:
|
|
118
114
|
assert isinstance(title, str)
|
|
119
|
-
|
|
120
|
-
try:
|
|
121
|
-
return title, generate_schema_types(schema, root=title) # type: ignore
|
|
122
|
-
except:
|
|
123
|
-
logging.exception(f"Error when generating schema type: {schema}")
|
|
124
|
-
return "Dict", ""
|
|
115
|
+
return wrapped_generate_schema_types(schema, title, "Dict") # type: ignore
|
|
125
116
|
|
|
126
117
|
elif schema.get("items"):
|
|
127
118
|
# fallback to schema $ref name if no explicit title
|
|
@@ -132,16 +123,11 @@ def get_type_and_def(type_spec: PropertyType) -> Tuple[str, str]:
|
|
|
132
123
|
title = items.get("$ref", "") # type: ignore
|
|
133
124
|
|
|
134
125
|
title = title.rsplit("/", 1)[-1]
|
|
135
|
-
title = clean_title(title)
|
|
136
126
|
if not title:
|
|
137
127
|
return "List", ""
|
|
138
128
|
|
|
139
129
|
title = f"List[{title}]"
|
|
140
|
-
|
|
141
|
-
return title, generate_schema_types(schema, root=title)
|
|
142
|
-
except:
|
|
143
|
-
logging.exception(f"Error when generating schema type: {schema}")
|
|
144
|
-
return "List", ""
|
|
130
|
+
return wrapped_generate_schema_types(schema, title, "List")
|
|
145
131
|
else:
|
|
146
132
|
return "Any", ""
|
|
147
133
|
else:
|
|
@@ -13,14 +13,14 @@ polyapi/function_cli.py,sha256=4G4xqDCF7HSVERXRJx1D3uytNI1_mhaU-bNFeNRsQ3E,9231
|
|
|
13
13
|
polyapi/generate.py,sha256=dtS6Wyb_lq9FrOs7NA_ceKCX9rogx2_3Fp57_hGwdDc,7957
|
|
14
14
|
polyapi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
15
15
|
polyapi/rendered_spec.py,sha256=yfOqZRx8BOkw5QfdrUx1m1SY2ne0Q1BolPmuSYIWwow,2230
|
|
16
|
-
polyapi/schema.py,sha256=
|
|
16
|
+
polyapi/schema.py,sha256=gea4HLyj-uarBaoCWRBaw39BlzvpetcLqLwc8mfnyYI,3560
|
|
17
17
|
polyapi/server.py,sha256=n-nMGjXoq9T9ZwE2EBDkAaxJ7UytConGaHthkjbkCXA,1894
|
|
18
18
|
polyapi/typedefs.py,sha256=mRqwd2LKofxNn_VSKxBzixni2j-tai8mfTQ0Wi2aLNM,1487
|
|
19
|
-
polyapi/utils.py,sha256=
|
|
19
|
+
polyapi/utils.py,sha256=f003Y5qP1uuyMKrvvaIUYS1TSGfSZjLnwPiXR5o4eA8,6530
|
|
20
20
|
polyapi/variables.py,sha256=d36-trnfTL_8m2NkorMiImb4O3UrJbiFV38CHxV5i0A,4200
|
|
21
21
|
polyapi/webhook.py,sha256=GvnS49Vl4k5STTvv4KKUnUAyn27OhIHHXChFmiI53Cs,4849
|
|
22
|
-
polyapi_python-0.2.5.
|
|
23
|
-
polyapi_python-0.2.5.
|
|
24
|
-
polyapi_python-0.2.5.
|
|
25
|
-
polyapi_python-0.2.5.
|
|
26
|
-
polyapi_python-0.2.5.
|
|
22
|
+
polyapi_python-0.2.5.dev9.dist-info/LICENSE,sha256=Hi0kDr56Dsy0uYIwNt4r9G7tI8x8miXRTlyvbeplCP8,1068
|
|
23
|
+
polyapi_python-0.2.5.dev9.dist-info/METADATA,sha256=ON6H4ZpZdOb4Ti602InI0GxOn4GX-MrSB8Z5TUCog20,4867
|
|
24
|
+
polyapi_python-0.2.5.dev9.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
25
|
+
polyapi_python-0.2.5.dev9.dist-info/top_level.txt,sha256=CEFllOnzowci_50RYJac-M54KD2IdAptFsayVVF_f04,8
|
|
26
|
+
polyapi_python-0.2.5.dev9.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|