polyapi-python 0.3.8.dev9__py3-none-any.whl → 0.3.8.dev10__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/poly_schemas.py CHANGED
@@ -25,11 +25,13 @@ FALLBACK_SPEC_TEMPLATE = """class {name}(TypedDict, total=False):
25
25
 
26
26
  def generate_schemas(specs: List[SchemaSpecDto], limit_ids: List[str] = None):
27
27
  failed_schemas = []
28
+ successful_schemas = []
28
29
  if limit_ids:
29
30
  for spec in specs:
30
31
  if spec["id"] in limit_ids:
31
32
  try:
32
33
  create_schema(spec)
34
+ successful_schemas.append(f"{spec.get('context', 'unknown')}.{spec.get('name', 'unknown')}")
33
35
  except Exception as e:
34
36
  schema_path = f"{spec.get('context', 'unknown')}.{spec.get('name', 'unknown')}"
35
37
  schema_id = spec.get('id', 'unknown')
@@ -40,6 +42,7 @@ def generate_schemas(specs: List[SchemaSpecDto], limit_ids: List[str] = None):
40
42
  for spec in specs:
41
43
  try:
42
44
  create_schema(spec)
45
+ successful_schemas.append(f"{spec.get('context', 'unknown')}.{spec.get('name', 'unknown')}")
43
46
  except Exception as e:
44
47
  schema_path = f"{spec.get('context', 'unknown')}.{spec.get('name', 'unknown')}"
45
48
  schema_id = spec.get('id', 'unknown')
@@ -51,6 +54,37 @@ def generate_schemas(specs: List[SchemaSpecDto], limit_ids: List[str] = None):
51
54
  logging.warning(f"WARNING: {len(failed_schemas)} schema(s) failed to generate:")
52
55
  for failed_schema in failed_schemas:
53
56
  logging.warning(f" - {failed_schema}")
57
+ logging.warning(f"Successfully generated {len(successful_schemas)} schema(s)")
58
+
59
+
60
+ def validate_schema_content(schema_content: str, schema_name: str) -> bool:
61
+ """
62
+ Validate that the schema content is meaningful and not just imports.
63
+ Returns True if the schema is valid, False otherwise.
64
+ """
65
+ if not schema_content or not schema_content.strip():
66
+ logging.debug(f"Schema {schema_name} failed validation: Empty content")
67
+ return False
68
+
69
+ lines = schema_content.strip().split('\n')
70
+
71
+ # Check if the content has any actual class definitions or type aliases
72
+ has_class_definition = any(line.strip().startswith('class ') for line in lines)
73
+ has_type_alias = any(schema_name in line and '=' in line and not line.strip().startswith('#') for line in lines)
74
+
75
+ # Check if it's essentially just imports (less than 5 lines and no meaningful definitions)
76
+ meaningful_lines = [line for line in lines if line.strip() and not line.strip().startswith('from ') and not line.strip().startswith('import ') and not line.strip().startswith('#')]
77
+
78
+ # Enhanced logging for debugging
79
+ if not (has_class_definition or has_type_alias) or len(meaningful_lines) < 1:
80
+ # Determine the specific reason for failure
81
+ if len(meaningful_lines) == 0:
82
+ logging.debug(f"Schema {schema_name} failed validation: No meaningful content (only imports) - likely empty object or unresolved reference")
83
+ elif not has_class_definition and not has_type_alias:
84
+ logging.debug(f"Schema {schema_name} failed validation: No class definition or type alias found")
85
+ return False
86
+
87
+ return True
54
88
 
55
89
 
56
90
  def add_schema_file(
@@ -75,9 +109,9 @@ def add_schema_file(
75
109
 
76
110
  schema_defs = render_poly_schema(spec)
77
111
 
78
- if not schema_defs:
79
- # If render_poly_schema failed and returned empty string, don't create any files
80
- raise Exception("Schema rendering failed - empty schema content returned")
112
+ # Validate schema content before proceeding
113
+ if not validate_schema_content(schema_defs, schema_name):
114
+ raise Exception(f"Schema rendering failed or produced invalid content for {schema_name}")
81
115
 
82
116
  # Prepare all content first before writing any files
83
117
  schema_namespace = to_func_namespace(schema_name)
polyapi/schema.py CHANGED
@@ -104,12 +104,26 @@ def generate_schema_types(input_data: Dict, root=None):
104
104
  # Regex to match everything between "# example: {\n" and "^}$"
105
105
  MALFORMED_EXAMPLES_PATTERN = re.compile(r"# example: \{\n.*?^\}$", flags=re.DOTALL | re.MULTILINE)
106
106
 
107
+ # Regex to fix invalid escape sequences in docstrings
108
+ INVALID_ESCAPE_PATTERNS = [
109
+ # Fix "\ " (backslash space) which is not a valid escape sequence
110
+ (re.compile(r'\\(\s)', re.DOTALL), r'\1'),
111
+ # Fix other common invalid escape sequences in docstrings
112
+ (re.compile(r'\\([^nrtbfav"\'\\])', re.DOTALL), r'\\\\\1'),
113
+ ]
114
+
107
115
 
108
116
  def clean_malformed_examples(example: str) -> str:
109
117
  """ there is a bug in the `jsonschmea_gentypes` library where if an example from a jsonchema is an object,
110
- it will break the code because the object won't be properly commented out
118
+ it will break the code because the object won't be properly commented out. Also fixes invalid escape sequences.
111
119
  """
120
+ # Remove malformed examples
112
121
  cleaned_example = MALFORMED_EXAMPLES_PATTERN.sub("", example)
122
+
123
+ # Fix invalid escape sequences in docstrings
124
+ for pattern, replacement in INVALID_ESCAPE_PATTERNS:
125
+ cleaned_example = pattern.sub(replacement, cleaned_example)
126
+
113
127
  return cleaned_example
114
128
 
115
129
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: polyapi-python
3
- Version: 0.3.8.dev9
3
+ Version: 0.3.8.dev10
4
4
  Summary: The Python Client for PolyAPI, the IPaaS by Developers for Developers
5
5
  Author-email: Dan Fellin <dan@polyapi.io>
6
6
  License: MIT License
@@ -206,3 +206,4 @@ Please ignore \[name-defined\] errors for now. This is a known bug we are workin
206
206
  ## Support
207
207
 
208
208
  If you run into any issues or want help getting started with this project, please contact support@polyapi.io
209
+ .
@@ -13,19 +13,19 @@ polyapi/execute.py,sha256=sjI6BMBYPSCD6UngV9DzpJIRSU6p02aShNaTXhDExtY,3457
13
13
  polyapi/function_cli.py,sha256=H0sVrbvRBXw_xeApe2MvQw8p_xE7jVTTOU-07Dg041A,4220
14
14
  polyapi/generate.py,sha256=slCw9AOvQHQ8UtEaumFI1NoRvjH2Dj3Y33u7imQqi8c,19521
15
15
  polyapi/parser.py,sha256=20ZE7kSXx3UL7QVSIYYxzsnJlygVbsaDAg9q7c41WxQ,20695
16
- polyapi/poly_schemas.py,sha256=TC_pCuK2lGCxEruW-og4fcQzliPZEbCGzrjAOLB-kXw,7061
16
+ polyapi/poly_schemas.py,sha256=760g-rBou-XT0y7N0THHHJBHlqIrOhVsAj500T6Qp0Q,8994
17
17
  polyapi/prepare.py,sha256=pRWBhpgqMtKP04P9F6PIA3eCkOpCxQSv9TZdR3qR34I,7216
18
18
  polyapi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
19
  polyapi/rendered_spec.py,sha256=nJEj2vRgG3N20fU4s-ThRtOIwAuTzXwXuOBIkXljDVc,2240
20
- polyapi/schema.py,sha256=Czh94VsbVCOT44Eym3fzO5p-g3icjPHpebE40-JOPuY,4709
20
+ polyapi/schema.py,sha256=zMN0zr_dku-NzmL8e0C6lbym8I0SrzXxtU5I8-YwHkM,5291
21
21
  polyapi/server.py,sha256=YXWxhYBx-hluwDQ8Jvfpy2s8ogz0GsNTMcZVNcP5ca8,2147
22
22
  polyapi/sync.py,sha256=PGdC0feBBjEVrF3d9EluW_OAxbWuzSrfh84czma8kWg,6476
23
23
  polyapi/typedefs.py,sha256=vJLZYBNmR3i8yQEDYlu1UfvtJyg6E1R1QyGlgFUm2rU,2362
24
24
  polyapi/utils.py,sha256=1F7Dwst_PbPuUBUSxx5r8d2DHDgqHtu07QW92T_YSdw,12454
25
25
  polyapi/variables.py,sha256=VAp2d5I-4WLYHCPF1w3pqU4-z8_XRQpYW-ddOw6G5S4,7268
26
26
  polyapi/webhook.py,sha256=gWYXHz0PnB_uY_lnHeUlg3EIHfTGwF-Tc6UaatldZBw,5333
27
- polyapi_python-0.3.8.dev9.dist-info/licenses/LICENSE,sha256=6b_I7aPVp8JXhqQwdw7_B84Ca0S4JGjHj0sr_1VOdB4,1068
28
- polyapi_python-0.3.8.dev9.dist-info/METADATA,sha256=BJ99UKHoY-SonR3ELntHs-2vCKg4XvDBnYRa4TPf7q8,5782
29
- polyapi_python-0.3.8.dev9.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
30
- polyapi_python-0.3.8.dev9.dist-info/top_level.txt,sha256=CEFllOnzowci_50RYJac-M54KD2IdAptFsayVVF_f04,8
31
- polyapi_python-0.3.8.dev9.dist-info/RECORD,,
27
+ polyapi_python-0.3.8.dev10.dist-info/licenses/LICENSE,sha256=6b_I7aPVp8JXhqQwdw7_B84Ca0S4JGjHj0sr_1VOdB4,1068
28
+ polyapi_python-0.3.8.dev10.dist-info/METADATA,sha256=gEaVycjq9LZDUwCA43SyffH-G52cN1CnB1OP004FHz8,5785
29
+ polyapi_python-0.3.8.dev10.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
30
+ polyapi_python-0.3.8.dev10.dist-info/top_level.txt,sha256=CEFllOnzowci_50RYJac-M54KD2IdAptFsayVVF_f04,8
31
+ polyapi_python-0.3.8.dev10.dist-info/RECORD,,