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

Default error schema 422 #1396

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

begyy
Copy link

@begyy begyy commented Jan 22, 2025

Added a default schema for 422 status codes, similar to FastAPI. The functionality ensures that a schema is only added if http422 is not already present in the response.

if http422 not in result:
    model = operation._create_response_model_multiple({http422: DefaultValidationError})[http422]
    schema = self._create_schema_from_model(model)[0]
    result[http422] = {
        "description": "Validation error",
        "content": {self.api.renderer.media_type: {"schema": schema}},
    }

The function operation._create_response_model_multiple({http422: DefaultValidationError})[http422] is a method within the class that generates the model. If you know of a better approach to create this model without directly invoking the class method, please suggest improvements, and I will update the implementation accordingly. 🙂

@begyy
Copy link
Author

begyy commented Jan 22, 2025

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant