Skip to content

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

Copy link

@luckydonald luckydonald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably it makes sense to revert all changes in indent, so only the relevant changes are part of the MR.

p_required: bool
for p_name, p_schema, p_required in flatten_properties(
name, details, is_required, schema.get("$defs", {})
name, details, is_required, schema.get("$defs", {})
Copy link

@luckydonald luckydonald Sep 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example this indent change is unnecessary. This makes the diff bigger for no gain.
There are a lot more.

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.

2 participants