Replies: 3 comments
|
Hi @haoyuant I recommend simplifying the issue by separating it from DynamoDB. I wasn't sure what the model name "Season" represents, but I'll add my code, excluding the process of saving to DynamoDB, along with a screenshot of the actual output Swagger. Additionally, here are the official documents you should refer to. https://docs.powertools.aws.dev/lambda/python/latest/core/event_handler/api_gateway/#data-validation Here is my code. from typing import List
from aws_lambda_powertools.event_handler import APIGatewayRestResolver
from aws_lambda_powertools.utilities.parser import BaseModel
from aws_lambda_powertools.utilities.typing import LambdaContext
app = APIGatewayRestResolver(enable_validation=True)
app.enable_swagger(path="/swagger")
class Season(BaseModel):
user_id: str
season_id: str
@app.get("/seasons")
def get_seasons() -> List[Season]:
# TODO: Replace with actual data fetch from database
seasons = [
Season(user_id="1", season_id="1"),
Season(user_id="2", season_id="2"),
]
return seasons
@app.post("/seasons")
def create_season(season: Season) -> Season:
# TODO: Add logic to save season to database
return Season(user_id=season.user_id, season_id=season.season_id)
def lambda_handler(event: dict, context: LambdaContext) -> dict:
return app.resolve(event, context) |
0 replies
|
@haoyuant The OpenAPI spec used with the Swagger UI is generated based on type annotations with Pydantic models. You don't use type annotations |
0 replies
|
I'm closing this discussion as resolved. Please reopen if you need. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi, I followed the docs to enable swagger and it can load my endpoints correctly, however, when I expand any endpoint it only shows an infinite loading and throws the error
Unhandled Promise Rejection: TypeError: Right side of assignment cannot be destructured. And the backend throws a warning| Invoked functions/apis/season.handler | +1442ms /Users/haoyuantang/Library/Caches/pypoetry/virtualenvs/functions-UNII4JFY-py3.12/lib/python3.12/site-packages/aws_lambda_powertools/event_handler/api_gateway.py:1682: UserWarning: You are using Pydantic v2, which is incompatible with OpenAPI schema 3.0. Forcing OpenAPI 3.1 | +1442ms spec = self.get_openapi_schema(.Do I miss something?
Here is my backend code:
All reactions