-
Notifications
You must be signed in to change notification settings - Fork 407
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
Cannot use models generated by datamodel-codegen
from OpenAPI 3.0 spec with property-level example:
s
#4476
Comments
hey @nlykkei , thank you for reporting it - got any code snippet to make it easier to reproduce it? Edit: |
@leandrodamascena are you able to look into it tomorrow? had a rough day today and w/ development setup suddenly broken it was hard to concentrate. It almost looks like either input or a type we can't deserialize ( |
Hey @nlykkei! Thanks for reporting this situation. In your from aws_lambda_powertools.event_handler import APIGatewayRestResolver
from pydantic import AnyUrl, BaseModel, ConfigDict, Field
app = APIGatewayRestResolver(enable_validation=True)
class Pagination(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
)
next: AnyUrl = Field(..., example="http://www.example.com/some/path?cursor=SW0gYW4gb3BhcXVlIGN1cnNvcg==")
"""
The next page uri
"""
current: int
"""
The current page number
"""
total: int
"""
The total number of pages
"""
@app.get("/hello")
def hello() -> Pagination:
...
def lambda_handler(event, context):
print(app.get_openapi_json_schema())
app.resolve(event, context) Perhaps you genuinely desire to utilize the Please let me know if you have any additional question. Thanks |
@leandrodamascena Thank you for such swift response! However, while Pydantic's After all, AWS Lambda Powertools generates OpenAPI 3.1.x, so the
Consider the following example: OpenAPI 3.0.x:
When I generate models from this using:
The following models are output:
Which results in invalid OpenAPI 3.0.x models, but valid OpenAPI 3.1.x models? Indeed, if I change
But as we're using Pydantic 2.x, and AWS Lambda Powertools therefore enforces OpenAPI 3.1.x, it should have accepted the OpenAPI 3.1.x model with |
Hi @nlykkei, thanks for such detailed response. Just to avoid back and forth and to have a clear understanding based on your last message, I assume now you are using Pydantic v2 + OpenAPI 3.1.x and not OpenAPI 3.0 and I understood this before, right? If yes, I agree with you that we can fix this and improve the experience to allow defining examples with just a simple list of strings or a complex I made some local tests here and could generate the OpenAPI spec with this change. app.pyfrom aws_lambda_powertools.event_handler import APIGatewayRestResolver
from pydantic import AnyUrl, BaseModel, ConfigDict, Field
app = APIGatewayRestResolver(enable_validation=True)
class Pagination(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
)
next: AnyUrl = Field(..., examples=["http://www.example.com/some/path?cursor=SW0gYW4gb3BhcXVlIGN1cnNvcg=="])
"""
The next page uri
"""
current: int
"""
The current page number
"""
total: int
"""
The total number of pages
"""
@app.get("/hello")
def hello() -> Pagination:
...
def lambda_handler(event, context):
print(app.get_openapi_json_schema())
app.resolve(event, context) Want to submit a PR to fix this? We are planning to release a new version next Thursday (13/06) and may include this fix. Please let me know if you can't, so I can send the PR to fix this. Thanks. |
We're using Pydantic 2, which makes AWS Lambda Powertools generate OpenAPI 3.1.x for the Swagger UI, which happens automatically by As AWS Lambda Powertools doesn't support OpenAPI 3.0.x or extended attributes ( In any case, virtually all Python-based LEGO teams use
Would you provide a link? :) |
We will update this issue and next steps later today. |
Rescheduling this for tomorrow due to some unexpected internal demands. |
Hello everyone! I'm adding this fix in the next release, which is happening this week. |
|
This is now released under 3.1.0 version! |
Expected Behaviour
I would like to use models generated by datamodel-codegen from OpenAPI 3.0 spec with property-level
example:
sCurrent Behaviour
The following
components.schemas.LddProjectsList
:Results in the following model being output by
datamodel-codegen
:When using the
Pagination
model with AWS Lambda Powertools REST API Event Handler, as part ofResponse[T]
, the following error is generated when attempting to generate OpenAPI 3.0 spec, as it expects either a validdict
orExample
:Code snippet
Possible Solution
No response
Steps to Reproduce
See current behavior
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: