Skip to content

Commit ae84ca5

Browse files
yizzyyizzy
authored andcommitted
chore: remove leftover OpenAPI example files; rename schema-fix func to ensure_upload_file_schema_references; tidy openapi package
1 parent 6be7867 commit ae84ca5

File tree

6 files changed

+12
-268
lines changed

6 files changed

+12
-268
lines changed

aws_lambda_powertools/event_handler/api_gateway.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2160,14 +2160,14 @@ def _apply_schema_fixes(self, output: dict[str, Any]) -> OpenAPI:
21602160
The final OpenAPI model with all fixes applied
21612161
"""
21622162
from aws_lambda_powertools.event_handler.openapi.models import OpenAPI
2163-
from aws_lambda_powertools.event_handler.openapi.params import fix_upload_file_schema_references
2163+
from aws_lambda_powertools.event_handler.openapi.params import ensure_upload_file_schema_references
21642164

21652165
# First create the OpenAPI model
21662166
result = OpenAPI(**output)
21672167

21682168
# Convert the model to a dict and apply the upload file schema fix
21692169
result_dict = result.model_dump(by_alias=True)
2170-
fixed_dict = fix_upload_file_schema_references(result_dict)
2170+
fixed_dict = ensure_upload_file_schema_references(result_dict)
21712171

21722172
# Reconstruct the model with the fixed dict
21732173
return OpenAPI(**fixed_dict)

aws_lambda_powertools/event_handler/openapi/__init__.py

Lines changed: 0 additions & 6 deletions
This file was deleted.

aws_lambda_powertools/event_handler/openapi/params.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,7 +1367,7 @@ def _create_model_field(
13671367
)
13681368

13691369

1370-
def fix_upload_file_schema_references(schema_dict: dict[str, Any]) -> dict[str, Any]:
1370+
def ensure_upload_file_schema_references(schema_dict: dict[str, Any]) -> dict[str, Any]:
13711371
"""
13721372
Fix missing component references for UploadFile in OpenAPI schemas.
13731373
@@ -1391,7 +1391,7 @@ def fix_upload_file_schema_references(schema_dict: dict[str, Any]) -> dict[str,
13911391
Example
13921392
-------
13931393
>>> schema = {"paths": {...}, "components": {...}}
1394-
>>> fixed_schema = fix_upload_file_schema_references(schema)
1394+
>>> fixed_schema = ensure_upload_file_schema_references(schema)
13951395
>>> # Now all $ref references in multipart/form-data schemas have matching components
13961396
"""
13971397
# Handle pydantic models that might be passed in

examples/event_handler/openapi_schema_fix_example.py

Lines changed: 0 additions & 170 deletions
This file was deleted.

examples/event_handler/schema_validation_test.py

Lines changed: 0 additions & 80 deletions
This file was deleted.

tests/functional/event_handler/_pydantic/test_uploadfile_coverage.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
_extract_endpoint_info_from_component_name,
1919
_find_missing_upload_file_components,
2020
_generate_component_title,
21-
fix_upload_file_schema_references,
21+
ensure_upload_file_schema_references,
2222
)
2323

2424

@@ -52,7 +52,7 @@ def upload_file(file: Annotated[UploadFile, File()]):
5252
schema = app.get_openapi_schema()
5353
# Convert to dict for processing by fix function
5454
schema_dict = schema.model_dump()
55-
fix_upload_file_schema_references(schema_dict)
55+
ensure_upload_file_schema_references(schema_dict)
5656

5757
# Verify components exist and are processed
5858
assert "components" in schema_dict
@@ -113,12 +113,12 @@ def test_schema_fix_edge_cases(self):
113113
"""Test schema fix function edge cases."""
114114
# Test with empty schema
115115
empty_schema = {}
116-
fix_upload_file_schema_references(empty_schema)
116+
ensure_upload_file_schema_references(empty_schema)
117117
assert empty_schema == {}
118118

119119
# Test with schema missing components
120120
schema_no_components = {"paths": {}}
121-
fix_upload_file_schema_references(schema_no_components)
121+
ensure_upload_file_schema_references(schema_no_components)
122122
# Should not crash and may or may not add components
123123

124124
def test_upload_file_multipart_handling(self):
@@ -131,7 +131,7 @@ def upload_multiple(primary: Annotated[UploadFile, File()], secondary: Annotated
131131

132132
schema = app.get_openapi_schema()
133133
schema_dict = schema.model_dump()
134-
fix_upload_file_schema_references(schema_dict)
134+
ensure_upload_file_schema_references(schema_dict)
135135

136136
# Verify multipart handling works without errors
137137
assert schema_dict is not None
@@ -226,7 +226,7 @@ def test_file_parameter_json_schema_extra(self):
226226
assert file_param.description == "Test file"
227227
assert hasattr(file_param, "json_schema_extra")
228228

229-
def test_fix_upload_file_schema_references_complex(self):
229+
def test_ensure_upload_file_schema_references_complex(self):
230230
"""Test schema fix with complex schema structures."""
231231
# Test with pydantic model that has model_dump method
232232
mock_schema = Mock()
@@ -246,7 +246,7 @@ def test_fix_upload_file_schema_references_complex(self):
246246
}
247247

248248
# Test fix function with model that has model_dump
249-
fix_upload_file_schema_references(mock_schema)
249+
ensure_upload_file_schema_references(mock_schema)
250250
mock_schema.model_dump.assert_called_once_with(by_alias=True)
251251

252252
def test_extract_endpoint_info_from_component_name(self):
@@ -341,7 +341,7 @@ def test_schema_dict_model_dump_handling(self):
341341
mock_schema.model_dump.return_value = {"paths": {}, "components": {"schemas": {}}}
342342

343343
# This should call model_dump and process the result
344-
fix_upload_file_schema_references(mock_schema)
344+
ensure_upload_file_schema_references(mock_schema)
345345
mock_schema.model_dump.assert_called_once_with(by_alias=True)
346346

347347
def test_openapi_validation_webkit_boundary_extraction(self):

0 commit comments

Comments
 (0)