Comments (5)
Pasting the comment here:
Hi @MCR2019 this makes sense, FastAPI supports it this way, so we could work on adding support in Powertools too. I'm converting this to a Feature Request ticket!
from powertools-lambda-python.
@MCR2019 I'm still trying to figure out what the best UX is for this feature, but in the meantime, in case you are blocked by this, here's a workaround:
from typing import Union
from pydantic import BaseModel, Field
from aws_lambda_powertools.event_handler import APIGatewayHttpResolver, Response
from aws_lambda_powertools.event_handler.openapi.types import COMPONENT_REF_PREFIX
app = APIGatewayHttpResolver(enable_validation=True)
class User(BaseModel):
id_: int = Field(..., alias="id")
name: str
class Order(BaseModel):
order_id: int
@app.get(
"/",
responses={
200: {
"description": "Hello 200",
"content": {"application/json": {"schema": {"$ref": COMPONENT_REF_PREFIX + "User"}}},
},
404: {
"description": "Hello 404",
"content": {"application/json": {"schema": {"$ref": COMPONENT_REF_PREFIX + "Order"}}},
},
},
)
def put(alternative_return: bool) -> Response[Union[User, Order]]:
if alternative_return:
return Response(404, body=Order(order_id=1))
else:
return Response(200, body=User(id=3, name="John"))
print(app.get_openapi_json_schema())
from powertools-lambda-python.
Thanks for the work around @rubenfonseca :)
from powertools-lambda-python.
⚠️ COMMENT VISIBILITY WARNING⚠️
This issue is now closed. Please be mindful that future comments are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.
from powertools-lambda-python.
This is now released under 2.32.0 version!
from powertools-lambda-python.
Related Issues (20)
- Maintenance: Fix codecov upload - missing token HOT 2
- Feature request: Support depth levels in feature flag keys HOT 3
- Feature request: ability to not throw error on full batch failure HOT 3
- [I Made This]: Bedrock agents with powertools HOT 2
- [Support Lambda Powertools]: BusPatrol HOT 3
- Bug: Register existing loggers function should use module logging, not source logger HOT 6
- Feature request: allow to provide an `appconfigdata` client in the `AppConfigStore` HOT 2
- Tech debt: Refactor parameters utility to use boto_config instead of config parameter
- Cookie class MaxAge produces invalid attribute, resulting to browser defaulting to session. HOT 4
- Bug: Recursive fails when using get_multiple in SSM parameters HOT 2
- Maintenance: downgrade AWS CDK to 2.145.0 HOT 1
- Bug: in_progress_expiration field is not set in Idempotency record when too close to lambda timeout HOT 6
- Bug: Defining security_schemes enforces the security on all endpoints HOT 4
- Bug: logger errors HOT 3
- Using `event_source` decorator with `tracer.capture_lambda_handler` decorator HOT 3
- Feature request: `validate()` to return validated payload HOT 5
- [I Made This]: Serverless multi-channel alerting solution based on user preferences HOT 2
- Docs: add mentions to Lambda layers in versioning policy HOT 2
- [Support Lambda Powertools]: Caylent HOT 4
- Feature request: Simplify experience in discovering how much time left before Idempotency record expiration HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from powertools-lambda-python.