-
Notifications
You must be signed in to change notification settings - Fork 420
Bug: OpenAPI schema invalid when using Pydantic v2 (latest) #3731
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
Comments
According to Pydantic docs: JSON Schema, Pydantic is compaible with OpenAPI 3.1.0. Running I will leave this issue open, since I believe this could be addressed in an automatic fashion: if Pydantic <2.0 use 3.0.0, else use 3.1.0. Also the summary should only be added if using OpenAPI version >=3.1.0. |
Hi @kbakk, thanks for filing the issue – we'll look into it to see if this is something we should add! |
cc @rubenfonseca who's oncall this week and might have missed. |
Looking at this now |
@kabkk Thank you for the very detailed explanation! I need to run some extra checks on this, but the major problem I have right now is that it's very hard to support multiple versions of OpenAPI spec with the same API. And on the other hand I'm not 100% comfortable in bumping the default to 3.1.0. Do you have any feedback on what would be the best for you? |
That was not my intention. The point is that the version of Pydantic you have installed (1.x or 2.x) will determine which API spec will be produced. In case Pydantic 1.x is installed, the default OpenAPI spec produced with I was thinking that |
thanks a lot for the feedback @kbakk :) We'll sync internally for a way out on this -- Ruben briefly mentioned it'd impact the upcoming Agent for Amazon Bedrock Event Handler feature at a first glance. Luckily all of this will go away on v3 too when we drop Pydantic v1. We'll come back to you as soon as we have a meaningful update to share - appreciate your patience!! |
Hi all, apologies for the late update. Here are my findings:
In my opinion we need to:
What do you think of this? |
|
This is now released under 2.35.0 version! |
Expected Behaviour
Using
ApiGatewayResolver.get_openapi_json_schema
should produce a valid OpenAPI schemaCurrent Behaviour
When using Pydantic version 2.6.1 (latest at the time of writing) the OpenAPI spec produced is invalid. This is not the case when using Pydantic version 1.10.14.
Errors seen in schema:
Note: This error is present when using both v1 and v2 of Pydantic.
Code snippet
Python code: handler.py
Possible Solution
No response
Steps to Reproduce
Run the provided script:
python handler.py > swagger.json
Then paste the JSON data in https://editor.swagger.io/ to see the errors (there are also tools like
spectral
which can be used to validate the output).Powertools for AWS Lambda (Python) version
latest
AWS Lambda function runtime
3.12
Packaging format used
PyPi
Debugging logs
No response
The text was updated successfully, but these errors were encountered: