-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] (type-safe-api) openapi arrays in responses generate faulty python runtime code #904
Comments
My plan is to replace the call to I also think I should fix
While exploring models.ejs , it looks like it isn't properly handling the case where the field is an array of primitives. In this sample OpenAPI spec, this template generates the following code:
The only usage of this This bug appears to come from the complexity of this template. I think the from and to methods could be simplified, and therefore eliminate bugs, by only using Pydantic's built in methods, but that would be another issue and PR. |
The template wasn't handling models with arrays of primitives properly, and it was getting handled by the last else if statement for non-primitives. This change excludes arrays from the case. fix aws#904
The PR makes the minimal change to fix the current bug. My sample code's tests pass after whitespace corrections. |
Describe the bug
When an API response includes an array, the python generated handler wrapper calls
to_dict()
on the list causing anAttributeError
.Expected Behavior
The Lambda function successfully returns the response.
Current Behavior
When the response includes an array, Python raises the following exception and the Lambda fails:
Reproduction Steps
Here is a sample project with a few modifications to the default code. The handler unit test passes for
test_say_hello_should_return_list
, but fails fortest_response_to_json
andtest_handler
..projenrc.ts
packages/api/model/src/main/openapi/main.yaml
packages/api/handlers/python/myapi_python_handlers/say_hello.py
packages/api/handlers/python/test/test_say_hello.py
Possible Solution
I tried using
model_dump_json()
instead ofto_json()
in the handler wrapper, and my tests passed.From packages/api/generated/runtime/python/myapi_python_runtime/api/operation_config.py
Additional Information/Context
This did not occur in previous versions using OpenAPI generator.
PDK version used
0.25.16
What languages are you seeing this issue on?
Python
Environment details (OS name and version, etc.)
MacOS 15.3
The text was updated successfully, but these errors were encountered: