Skip to content
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

Feature: Event handler Swagger doesnt add 422 response to openapi when adding custom responses #3600

Closed
ran-isenberg opened this issue Jan 6, 2024 · 6 comments · Fixed by #3995
Assignees
Labels
event_handlers feature-request feature request help wanted Could use a second pair of eyes/hands openapi-schema

Comments

@ran-isenberg
Copy link
Contributor

ran-isenberg commented Jan 6, 2024

Expected Behaviour

422 is a built in schema that i as a user don't control, i expect it to be there even though I'm adding other responses (501 , 404 etc.).

Current Behaviour

422 is omitted from schema when adding a custom response.
In addition, the 422 schema says there's a msg: string in the schema but in my tests i didnt get that fields, maybe it's optional?

Code snippet

See:
https://github.com/ran-isenberg/aws-lambda-handler-cookbook/pull/784/files#diff-03a550a2c5158da1b1459e42e5799bdfe3809d2563dfb16014d3ea3bcd7cd043R20

Possible Solution

No response

Steps to Reproduce

add the snippet, go to /swagger

Powertools for AWS Lambda (Python) version

latest

AWS Lambda function runtime

3.12

Packaging format used

PyPi

Debugging logs

No response

@ran-isenberg ran-isenberg added bug Something isn't working triage Pending triage from maintainers labels Jan 6, 2024
@leandrodamascena
Copy link
Contributor

Assigning myself to answer it tomorrow!

@leandrodamascena leandrodamascena self-assigned this Jan 9, 2024
@leandrodamascena leandrodamascena added feature-request feature request event_handlers and removed bug Something isn't working triage Pending triage from maintainers labels Jan 9, 2024
@leandrodamascena leandrodamascena moved this from Triage to Backlog in Powertools for AWS Lambda (Python) Jan 9, 2024
@leandrodamascena leandrodamascena changed the title Bug: Event handler Swagger doesnt add 422 response to openapi when adding custom responses Feature: Event handler Swagger doesnt add 422 response to openapi when adding custom responses Jan 9, 2024
@leandrodamascena
Copy link
Contributor

Hi @ran-isenberg! I've changed this issue to a feature request. We agree that adding 422 should be mandatory even when the customer creates custom responses on specific routes, but we need to investigate whether it is possible to allow clients to customize the 422 response if necessary.

I'm adding this feature to our backlog and will probably deliver it in the next releases.

Thanks for reporting this and helping us to improve this new feature.

@leandrodamascena leandrodamascena added help wanted Could use a second pair of eyes/hands openapi-schema labels Jan 22, 2024
@ran-isenberg
Copy link
Contributor Author

ran-isenberg commented Jan 22, 2024

I found a workaround for now @leandrodamascena
I added it manually and i created a proper pydantic code.
Here's the pydantic class:

from typing import Annotated, List, Optional, Union

from pydantic import BaseModel, Field



class PydanticError(BaseModel):
    loc: Annotated[List[Union[str, int]], Field(description='Error location')]
    type: Annotated[str, Field(description='Error type')]
    msg: Annotated[Optional[str], Field(description='Error message')]


class InvalidRestApiRequest(BaseModel):
    details: Annotated[List[PydanticError], Field(description='Error details')]

here's the code:

responses={
        200: {
            'description': 'The created order',
            'content': {'application/json': {'model': MyModel}},
        },
        442: {
            'description': 'Invalid create order request',
            'content': {'application/json': {'model': InvalidRestApiRequest}},
        },
        501: {
            'description': 'Internal server error',
            'content': {'application/json': {'model': MyErrorModel}},
        },

@rubenfonseca
Copy link
Contributor

I'm looking at this today, see if there's a way to move forward.

Copy link
Contributor

⚠️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.

@github-actions github-actions bot added the pending-release Fix or implementation already in dev waiting to be released label Mar 21, 2024
Copy link
Contributor

This is now released under 2.36.0 version!

@github-actions github-actions bot removed the pending-release Fix or implementation already in dev waiting to be released label Mar 27, 2024
@leandrodamascena leandrodamascena moved this from Coming soon to Shipped in Powertools for AWS Lambda (Python) Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
event_handlers feature-request feature request help wanted Could use a second pair of eyes/hands openapi-schema
Projects
Status: Shipped
Development

Successfully merging a pull request may close this issue.

3 participants