pyopenapi-gen 2.7.2__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.
- pyopenapi_gen/__init__.py +224 -0
- pyopenapi_gen/__main__.py +6 -0
- pyopenapi_gen/cli.py +62 -0
- pyopenapi_gen/context/CLAUDE.md +284 -0
- pyopenapi_gen/context/file_manager.py +52 -0
- pyopenapi_gen/context/import_collector.py +382 -0
- pyopenapi_gen/context/render_context.py +726 -0
- pyopenapi_gen/core/CLAUDE.md +224 -0
- pyopenapi_gen/core/__init__.py +0 -0
- pyopenapi_gen/core/auth/base.py +22 -0
- pyopenapi_gen/core/auth/plugins.py +89 -0
- pyopenapi_gen/core/cattrs_converter.py +810 -0
- pyopenapi_gen/core/exceptions.py +20 -0
- pyopenapi_gen/core/http_status_codes.py +218 -0
- pyopenapi_gen/core/http_transport.py +222 -0
- pyopenapi_gen/core/loader/__init__.py +12 -0
- pyopenapi_gen/core/loader/loader.py +174 -0
- pyopenapi_gen/core/loader/operations/__init__.py +12 -0
- pyopenapi_gen/core/loader/operations/parser.py +161 -0
- pyopenapi_gen/core/loader/operations/post_processor.py +62 -0
- pyopenapi_gen/core/loader/operations/request_body.py +90 -0
- pyopenapi_gen/core/loader/parameters/__init__.py +10 -0
- pyopenapi_gen/core/loader/parameters/parser.py +186 -0
- pyopenapi_gen/core/loader/responses/__init__.py +10 -0
- pyopenapi_gen/core/loader/responses/parser.py +111 -0
- pyopenapi_gen/core/loader/schemas/__init__.py +11 -0
- pyopenapi_gen/core/loader/schemas/extractor.py +275 -0
- pyopenapi_gen/core/pagination.py +64 -0
- pyopenapi_gen/core/parsing/__init__.py +13 -0
- pyopenapi_gen/core/parsing/common/__init__.py +1 -0
- pyopenapi_gen/core/parsing/common/ref_resolution/__init__.py +9 -0
- pyopenapi_gen/core/parsing/common/ref_resolution/helpers/__init__.py +0 -0
- pyopenapi_gen/core/parsing/common/ref_resolution/helpers/cyclic_properties.py +66 -0
- pyopenapi_gen/core/parsing/common/ref_resolution/helpers/direct_cycle.py +33 -0
- pyopenapi_gen/core/parsing/common/ref_resolution/helpers/existing_schema.py +22 -0
- pyopenapi_gen/core/parsing/common/ref_resolution/helpers/list_response.py +54 -0
- pyopenapi_gen/core/parsing/common/ref_resolution/helpers/missing_ref.py +52 -0
- pyopenapi_gen/core/parsing/common/ref_resolution/helpers/new_schema.py +50 -0
- pyopenapi_gen/core/parsing/common/ref_resolution/helpers/stripped_suffix.py +51 -0
- pyopenapi_gen/core/parsing/common/ref_resolution/resolve_schema_ref.py +86 -0
- pyopenapi_gen/core/parsing/common/type_parser.py +73 -0
- pyopenapi_gen/core/parsing/context.py +187 -0
- pyopenapi_gen/core/parsing/cycle_helpers.py +126 -0
- pyopenapi_gen/core/parsing/keywords/__init__.py +1 -0
- pyopenapi_gen/core/parsing/keywords/all_of_parser.py +81 -0
- pyopenapi_gen/core/parsing/keywords/any_of_parser.py +84 -0
- pyopenapi_gen/core/parsing/keywords/array_items_parser.py +72 -0
- pyopenapi_gen/core/parsing/keywords/one_of_parser.py +77 -0
- pyopenapi_gen/core/parsing/keywords/properties_parser.py +98 -0
- pyopenapi_gen/core/parsing/schema_finalizer.py +169 -0
- pyopenapi_gen/core/parsing/schema_parser.py +804 -0
- pyopenapi_gen/core/parsing/transformers/__init__.py +0 -0
- pyopenapi_gen/core/parsing/transformers/inline_enum_extractor.py +285 -0
- pyopenapi_gen/core/parsing/transformers/inline_object_promoter.py +120 -0
- pyopenapi_gen/core/parsing/unified_cycle_detection.py +293 -0
- pyopenapi_gen/core/postprocess_manager.py +260 -0
- pyopenapi_gen/core/spec_fetcher.py +148 -0
- pyopenapi_gen/core/streaming_helpers.py +84 -0
- pyopenapi_gen/core/telemetry.py +69 -0
- pyopenapi_gen/core/utils.py +456 -0
- pyopenapi_gen/core/warning_collector.py +83 -0
- pyopenapi_gen/core/writers/code_writer.py +135 -0
- pyopenapi_gen/core/writers/documentation_writer.py +222 -0
- pyopenapi_gen/core/writers/line_writer.py +217 -0
- pyopenapi_gen/core/writers/python_construct_renderer.py +321 -0
- pyopenapi_gen/core_package_template/README.md +21 -0
- pyopenapi_gen/emit/models_emitter.py +143 -0
- pyopenapi_gen/emitters/CLAUDE.md +286 -0
- pyopenapi_gen/emitters/client_emitter.py +51 -0
- pyopenapi_gen/emitters/core_emitter.py +181 -0
- pyopenapi_gen/emitters/docs_emitter.py +44 -0
- pyopenapi_gen/emitters/endpoints_emitter.py +247 -0
- pyopenapi_gen/emitters/exceptions_emitter.py +187 -0
- pyopenapi_gen/emitters/mocks_emitter.py +185 -0
- pyopenapi_gen/emitters/models_emitter.py +426 -0
- pyopenapi_gen/generator/CLAUDE.md +352 -0
- pyopenapi_gen/generator/client_generator.py +567 -0
- pyopenapi_gen/generator/exceptions.py +7 -0
- pyopenapi_gen/helpers/CLAUDE.md +325 -0
- pyopenapi_gen/helpers/__init__.py +1 -0
- pyopenapi_gen/helpers/endpoint_utils.py +532 -0
- pyopenapi_gen/helpers/type_cleaner.py +334 -0
- pyopenapi_gen/helpers/type_helper.py +112 -0
- pyopenapi_gen/helpers/type_resolution/__init__.py +1 -0
- pyopenapi_gen/helpers/type_resolution/array_resolver.py +57 -0
- pyopenapi_gen/helpers/type_resolution/composition_resolver.py +79 -0
- pyopenapi_gen/helpers/type_resolution/finalizer.py +105 -0
- pyopenapi_gen/helpers/type_resolution/named_resolver.py +172 -0
- pyopenapi_gen/helpers/type_resolution/object_resolver.py +216 -0
- pyopenapi_gen/helpers/type_resolution/primitive_resolver.py +109 -0
- pyopenapi_gen/helpers/type_resolution/resolver.py +47 -0
- pyopenapi_gen/helpers/url_utils.py +14 -0
- pyopenapi_gen/http_types.py +20 -0
- pyopenapi_gen/ir.py +165 -0
- pyopenapi_gen/py.typed +1 -0
- pyopenapi_gen/types/CLAUDE.md +140 -0
- pyopenapi_gen/types/__init__.py +11 -0
- pyopenapi_gen/types/contracts/__init__.py +13 -0
- pyopenapi_gen/types/contracts/protocols.py +106 -0
- pyopenapi_gen/types/contracts/types.py +28 -0
- pyopenapi_gen/types/resolvers/__init__.py +7 -0
- pyopenapi_gen/types/resolvers/reference_resolver.py +71 -0
- pyopenapi_gen/types/resolvers/response_resolver.py +177 -0
- pyopenapi_gen/types/resolvers/schema_resolver.py +498 -0
- pyopenapi_gen/types/services/__init__.py +5 -0
- pyopenapi_gen/types/services/type_service.py +165 -0
- pyopenapi_gen/types/strategies/__init__.py +5 -0
- pyopenapi_gen/types/strategies/response_strategy.py +310 -0
- pyopenapi_gen/visit/CLAUDE.md +272 -0
- pyopenapi_gen/visit/client_visitor.py +477 -0
- pyopenapi_gen/visit/docs_visitor.py +38 -0
- pyopenapi_gen/visit/endpoint/__init__.py +1 -0
- pyopenapi_gen/visit/endpoint/endpoint_visitor.py +292 -0
- pyopenapi_gen/visit/endpoint/generators/__init__.py +1 -0
- pyopenapi_gen/visit/endpoint/generators/docstring_generator.py +123 -0
- pyopenapi_gen/visit/endpoint/generators/endpoint_method_generator.py +222 -0
- pyopenapi_gen/visit/endpoint/generators/mock_generator.py +140 -0
- pyopenapi_gen/visit/endpoint/generators/overload_generator.py +252 -0
- pyopenapi_gen/visit/endpoint/generators/request_generator.py +103 -0
- pyopenapi_gen/visit/endpoint/generators/response_handler_generator.py +705 -0
- pyopenapi_gen/visit/endpoint/generators/signature_generator.py +83 -0
- pyopenapi_gen/visit/endpoint/generators/url_args_generator.py +207 -0
- pyopenapi_gen/visit/endpoint/processors/__init__.py +1 -0
- pyopenapi_gen/visit/endpoint/processors/import_analyzer.py +78 -0
- pyopenapi_gen/visit/endpoint/processors/parameter_processor.py +171 -0
- pyopenapi_gen/visit/exception_visitor.py +90 -0
- pyopenapi_gen/visit/model/__init__.py +0 -0
- pyopenapi_gen/visit/model/alias_generator.py +93 -0
- pyopenapi_gen/visit/model/dataclass_generator.py +553 -0
- pyopenapi_gen/visit/model/enum_generator.py +212 -0
- pyopenapi_gen/visit/model/model_visitor.py +198 -0
- pyopenapi_gen/visit/visitor.py +97 -0
- pyopenapi_gen-2.7.2.dist-info/METADATA +1169 -0
- pyopenapi_gen-2.7.2.dist-info/RECORD +137 -0
- pyopenapi_gen-2.7.2.dist-info/WHEEL +4 -0
- pyopenapi_gen-2.7.2.dist-info/entry_points.txt +2 -0
- pyopenapi_gen-2.7.2.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
# helpers/ - Legacy Compatibility Layer
|
|
2
|
+
|
|
3
|
+
## Why This Folder?
|
|
4
|
+
Backward compatibility during transition to unified type system. Delegates to new `types/` system while maintaining old API surface for gradual migration.
|
|
5
|
+
|
|
6
|
+
## Key Dependencies
|
|
7
|
+
- **Delegates to**: `../types/services/UnifiedTypeService`
|
|
8
|
+
- **Used by**: Legacy code that hasn't migrated to unified system
|
|
9
|
+
- **Status**: Transitional - prefer `types/` for new code
|
|
10
|
+
|
|
11
|
+
## Critical Architecture
|
|
12
|
+
|
|
13
|
+
### 1. Legacy → Unified Delegation
|
|
14
|
+
```python
|
|
15
|
+
# type_helper.py
|
|
16
|
+
class TypeHelper:
|
|
17
|
+
@staticmethod
|
|
18
|
+
def get_python_type_for_schema(schema: IRSchema, all_schemas: Dict[str, IRSchema],
|
|
19
|
+
context: RenderContext, required: bool = True,
|
|
20
|
+
resolve_alias_target: bool = False) -> str:
|
|
21
|
+
"""Legacy API - delegates to UnifiedTypeService"""
|
|
22
|
+
type_service = UnifiedTypeService(all_schemas)
|
|
23
|
+
return type_service.resolve_schema_type(
|
|
24
|
+
schema, context, required, resolve_underlying=resolve_alias_target
|
|
25
|
+
)
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### 2. Type Resolution Subdirectory
|
|
29
|
+
```python
|
|
30
|
+
# type_resolution/ - Legacy individual resolvers
|
|
31
|
+
# These now delegate to unified system components
|
|
32
|
+
array_resolver.py → types/resolvers/schema_resolver.py
|
|
33
|
+
composition_resolver.py → types/resolvers/schema_resolver.py
|
|
34
|
+
object_resolver.py → types/resolvers/schema_resolver.py
|
|
35
|
+
primitive_resolver.py → types/resolvers/schema_resolver.py
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Migration Strategy
|
|
39
|
+
|
|
40
|
+
### 1. Deprecation Pattern
|
|
41
|
+
```python
|
|
42
|
+
import warnings
|
|
43
|
+
from ..types.services import UnifiedTypeService
|
|
44
|
+
|
|
45
|
+
def legacy_function(schema: IRSchema, context: RenderContext) -> str:
|
|
46
|
+
"""
|
|
47
|
+
DEPRECATED: Use UnifiedTypeService.resolve_schema_type() instead.
|
|
48
|
+
This function will be removed in version 2.0.
|
|
49
|
+
"""
|
|
50
|
+
warnings.warn(
|
|
51
|
+
"legacy_function is deprecated. Use UnifiedTypeService.resolve_schema_type()",
|
|
52
|
+
DeprecationWarning,
|
|
53
|
+
stacklevel=2
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
# Delegate to new system
|
|
57
|
+
type_service = UnifiedTypeService({})
|
|
58
|
+
return type_service.resolve_schema_type(schema, context)
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### 2. API Compatibility
|
|
62
|
+
```python
|
|
63
|
+
# Maintain old signatures while delegating
|
|
64
|
+
def get_return_type(operation: IROperation, context: RenderContext,
|
|
65
|
+
schemas: Dict[str, IRSchema]) -> Tuple[str, bool]:
|
|
66
|
+
"""Legacy endpoint_utils function"""
|
|
67
|
+
type_service = UnifiedTypeService(schemas)
|
|
68
|
+
return type_service.resolve_operation_response_with_unwrap_info(operation, context)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Critical Components
|
|
72
|
+
|
|
73
|
+
### type_helper.py
|
|
74
|
+
**Purpose**: Main legacy entry point for type resolution
|
|
75
|
+
```python
|
|
76
|
+
class TypeHelper:
|
|
77
|
+
@staticmethod
|
|
78
|
+
def get_python_type_for_schema(schema: IRSchema, all_schemas: Dict[str, IRSchema],
|
|
79
|
+
context: RenderContext, required: bool = True,
|
|
80
|
+
resolve_alias_target: bool = False) -> str:
|
|
81
|
+
"""
|
|
82
|
+
Legacy type resolution - delegates to UnifiedTypeService
|
|
83
|
+
|
|
84
|
+
Args:
|
|
85
|
+
schema: Schema to resolve
|
|
86
|
+
all_schemas: All schemas in spec (for references)
|
|
87
|
+
context: Render context for imports
|
|
88
|
+
required: Whether field is required (affects Optional[])
|
|
89
|
+
resolve_alias_target: Whether to resolve through aliases
|
|
90
|
+
|
|
91
|
+
Returns:
|
|
92
|
+
Python type string
|
|
93
|
+
"""
|
|
94
|
+
type_service = UnifiedTypeService(all_schemas)
|
|
95
|
+
return type_service.resolve_schema_type(
|
|
96
|
+
schema, context, required, resolve_underlying=resolve_alias_target
|
|
97
|
+
)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### endpoint_utils.py
|
|
101
|
+
**Purpose**: Legacy endpoint-specific utilities
|
|
102
|
+
```python
|
|
103
|
+
def get_return_type(operation: IROperation, context: RenderContext,
|
|
104
|
+
schemas: Dict[str, IRSchema]) -> Tuple[str, bool]:
|
|
105
|
+
"""
|
|
106
|
+
Legacy function for getting operation return type
|
|
107
|
+
|
|
108
|
+
Returns:
|
|
109
|
+
Tuple of (python_type, was_unwrapped)
|
|
110
|
+
"""
|
|
111
|
+
type_service = UnifiedTypeService(schemas)
|
|
112
|
+
return type_service.resolve_operation_response_with_unwrap_info(operation, context)
|
|
113
|
+
|
|
114
|
+
def get_endpoint_return_types(operation: IROperation, context: RenderContext,
|
|
115
|
+
schemas: Dict[str, IRSchema]) -> Dict[str, str]:
|
|
116
|
+
"""Legacy function for getting all response types"""
|
|
117
|
+
type_service = UnifiedTypeService(schemas)
|
|
118
|
+
return type_service.resolve_all_response_types(operation, context)
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### type_resolution/ Subdirectory
|
|
122
|
+
**Purpose**: Legacy individual type resolvers
|
|
123
|
+
|
|
124
|
+
#### array_resolver.py
|
|
125
|
+
```python
|
|
126
|
+
def resolve_array_type(schema: IRSchema, context: RenderContext,
|
|
127
|
+
all_schemas: Dict[str, IRSchema]) -> str:
|
|
128
|
+
"""Legacy array type resolution"""
|
|
129
|
+
type_service = UnifiedTypeService(all_schemas)
|
|
130
|
+
return type_service.resolve_schema_type(schema, context)
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
#### composition_resolver.py
|
|
134
|
+
```python
|
|
135
|
+
def resolve_composition_type(schema: IRSchema, context: RenderContext,
|
|
136
|
+
all_schemas: Dict[str, IRSchema]) -> str:
|
|
137
|
+
"""Legacy composition (allOf/oneOf/anyOf) resolution"""
|
|
138
|
+
type_service = UnifiedTypeService(all_schemas)
|
|
139
|
+
return type_service.resolve_schema_type(schema, context)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## Usage Patterns (Legacy)
|
|
143
|
+
|
|
144
|
+
### 1. Type Resolution
|
|
145
|
+
```python
|
|
146
|
+
# OLD WAY (still works, but deprecated)
|
|
147
|
+
from pyopenapi_gen.helpers.type_helper import TypeHelper
|
|
148
|
+
|
|
149
|
+
python_type = TypeHelper.get_python_type_for_schema(
|
|
150
|
+
schema, all_schemas, context, required=True
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
# NEW WAY (preferred)
|
|
154
|
+
from pyopenapi_gen.types.services import UnifiedTypeService
|
|
155
|
+
|
|
156
|
+
type_service = UnifiedTypeService(all_schemas)
|
|
157
|
+
python_type = type_service.resolve_schema_type(schema, context, required=True)
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### 2. Endpoint Type Resolution
|
|
161
|
+
```python
|
|
162
|
+
# OLD WAY (still works, but deprecated)
|
|
163
|
+
from pyopenapi_gen.helpers.endpoint_utils import get_return_type
|
|
164
|
+
|
|
165
|
+
return_type, was_unwrapped = get_return_type(operation, context, schemas)
|
|
166
|
+
|
|
167
|
+
# NEW WAY (preferred)
|
|
168
|
+
from pyopenapi_gen.types.services import UnifiedTypeService
|
|
169
|
+
|
|
170
|
+
type_service = UnifiedTypeService(schemas)
|
|
171
|
+
return_type, was_unwrapped = type_service.resolve_operation_response_with_unwrap_info(
|
|
172
|
+
operation, context
|
|
173
|
+
)
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## Migration Guide
|
|
177
|
+
|
|
178
|
+
### 1. Type Helper Migration
|
|
179
|
+
```python
|
|
180
|
+
# Before
|
|
181
|
+
from pyopenapi_gen.helpers.type_helper import TypeHelper
|
|
182
|
+
|
|
183
|
+
class MyVisitor:
|
|
184
|
+
def resolve_type(self, schema: IRSchema) -> str:
|
|
185
|
+
return TypeHelper.get_python_type_for_schema(
|
|
186
|
+
schema, self.all_schemas, self.context, required=True
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
# After
|
|
190
|
+
from pyopenapi_gen.types.services import UnifiedTypeService
|
|
191
|
+
|
|
192
|
+
class MyVisitor:
|
|
193
|
+
def __init__(self, all_schemas: Dict[str, IRSchema]):
|
|
194
|
+
self.type_service = UnifiedTypeService(all_schemas)
|
|
195
|
+
|
|
196
|
+
def resolve_type(self, schema: IRSchema) -> str:
|
|
197
|
+
return self.type_service.resolve_schema_type(
|
|
198
|
+
schema, self.context, required=True
|
|
199
|
+
)
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### 2. Endpoint Utils Migration
|
|
203
|
+
```python
|
|
204
|
+
# Before
|
|
205
|
+
from pyopenapi_gen.helpers.endpoint_utils import get_return_type
|
|
206
|
+
|
|
207
|
+
def generate_method(self, operation: IROperation):
|
|
208
|
+
return_type, was_unwrapped = get_return_type(operation, self.context, self.schemas)
|
|
209
|
+
|
|
210
|
+
# After
|
|
211
|
+
from pyopenapi_gen.types.services import UnifiedTypeService
|
|
212
|
+
|
|
213
|
+
def generate_method(self, operation: IROperation):
|
|
214
|
+
return_type, was_unwrapped = self.type_service.resolve_operation_response_with_unwrap_info(
|
|
215
|
+
operation, self.context
|
|
216
|
+
)
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## Testing Strategy
|
|
220
|
+
|
|
221
|
+
### 1. Compatibility Tests
|
|
222
|
+
```python
|
|
223
|
+
def test_type_helper__legacy_api__matches_unified_service():
|
|
224
|
+
"""Ensure legacy API produces same results as unified service"""
|
|
225
|
+
|
|
226
|
+
# Test with legacy API
|
|
227
|
+
legacy_result = TypeHelper.get_python_type_for_schema(
|
|
228
|
+
schema, all_schemas, context, required=True
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
# Test with unified service
|
|
232
|
+
type_service = UnifiedTypeService(all_schemas)
|
|
233
|
+
unified_result = type_service.resolve_schema_type(
|
|
234
|
+
schema, context, required=True
|
|
235
|
+
)
|
|
236
|
+
|
|
237
|
+
assert legacy_result == unified_result
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### 2. Deprecation Warning Tests
|
|
241
|
+
```python
|
|
242
|
+
def test_legacy_function__emits_deprecation_warning():
|
|
243
|
+
"""Ensure legacy functions emit deprecation warnings"""
|
|
244
|
+
|
|
245
|
+
with warnings.catch_warnings(record=True) as w:
|
|
246
|
+
warnings.simplefilter("always")
|
|
247
|
+
|
|
248
|
+
# Call legacy function
|
|
249
|
+
TypeHelper.get_python_type_for_schema(schema, all_schemas, context)
|
|
250
|
+
|
|
251
|
+
# Check warning was emitted
|
|
252
|
+
assert len(w) == 1
|
|
253
|
+
assert issubclass(w[0].category, DeprecationWarning)
|
|
254
|
+
assert "deprecated" in str(w[0].message)
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
## Removal Timeline
|
|
258
|
+
|
|
259
|
+
### Phase 1: Deprecation (Current)
|
|
260
|
+
- Add deprecation warnings to all legacy functions
|
|
261
|
+
- Update internal code to use unified system
|
|
262
|
+
- Maintain backward compatibility
|
|
263
|
+
|
|
264
|
+
### Phase 2: Migration (Future)
|
|
265
|
+
- Remove legacy functions
|
|
266
|
+
- Update all external references
|
|
267
|
+
- Remove helpers/ directory
|
|
268
|
+
|
|
269
|
+
## Extension Points
|
|
270
|
+
|
|
271
|
+
### Custom Legacy Adapters
|
|
272
|
+
```python
|
|
273
|
+
class CustomLegacyAdapter:
|
|
274
|
+
"""Adapt old custom APIs to unified system"""
|
|
275
|
+
|
|
276
|
+
def __init__(self, type_service: UnifiedTypeService):
|
|
277
|
+
self.type_service = type_service
|
|
278
|
+
|
|
279
|
+
def old_custom_method(self, schema: IRSchema) -> str:
|
|
280
|
+
# Convert old API to new unified service call
|
|
281
|
+
return self.type_service.resolve_schema_type(schema, context)
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
## Critical Implementation Details
|
|
285
|
+
|
|
286
|
+
### Error Handling
|
|
287
|
+
```python
|
|
288
|
+
def legacy_function(schema: IRSchema) -> str:
|
|
289
|
+
"""Legacy function with error handling"""
|
|
290
|
+
try:
|
|
291
|
+
# Delegate to unified system
|
|
292
|
+
return unified_function(schema)
|
|
293
|
+
except Exception as e:
|
|
294
|
+
# Convert unified errors to legacy error format
|
|
295
|
+
raise LegacyError(f"Legacy function failed: {e}")
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
### Performance Considerations
|
|
299
|
+
```python
|
|
300
|
+
# Cache UnifiedTypeService instances to avoid recreation
|
|
301
|
+
_type_service_cache = {}
|
|
302
|
+
|
|
303
|
+
def get_cached_type_service(schemas: Dict[str, IRSchema]) -> UnifiedTypeService:
|
|
304
|
+
"""Get cached type service for performance"""
|
|
305
|
+
schema_hash = hash(frozenset(schemas.keys()))
|
|
306
|
+
|
|
307
|
+
if schema_hash not in _type_service_cache:
|
|
308
|
+
_type_service_cache[schema_hash] = UnifiedTypeService(schemas)
|
|
309
|
+
|
|
310
|
+
return _type_service_cache[schema_hash]
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
## Common Pitfalls
|
|
314
|
+
|
|
315
|
+
1. **Direct Usage**: Using legacy functions in new code
|
|
316
|
+
2. **Missing Warnings**: Not emitting deprecation warnings
|
|
317
|
+
3. **Inconsistent Results**: Legacy and unified APIs returning different results
|
|
318
|
+
4. **Performance**: Creating new UnifiedTypeService instances repeatedly
|
|
319
|
+
|
|
320
|
+
## Best Practices
|
|
321
|
+
|
|
322
|
+
1. **Prefer Unified System**: Use `types/` for all new code
|
|
323
|
+
2. **Emit Warnings**: Always emit deprecation warnings in legacy functions
|
|
324
|
+
3. **Test Compatibility**: Ensure legacy and unified APIs return same results
|
|
325
|
+
4. **Document Migration**: Provide clear migration paths in docstrings
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# This file makes 'helpers' a package.
|