#[derive(EntityError)]
{
// Attributes available to this derive:
#[status]
}
Expand description
Derive macro for generating OpenAPI error response documentation.
§Overview
The EntityError derive macro generates OpenAPI response documentation
from error enum variants, using #[status(code)] attributes and doc
comments.
§Example
ⓘ
use entity_derive::EntityError;
use thiserror::Error;
use utoipa::ToSchema;
#[derive(Debug, Error, ToSchema, EntityError)]
pub enum UserError {
/// User with this email already exists
#[error("Email already exists")]
#[status(409)]
EmailExists,
/// User not found by ID
#[error("User not found")]
#[status(404)]
NotFound,
/// Invalid credentials provided
#[error("Invalid credentials")]
#[status(401)]
InvalidCredentials,
}§Generated Code
For UserError, generates:
UserErrorResponsesstruct with helper methodsstatus_codes()- returns all error status codesdescriptions()- returns all error descriptionsutoipa_responses()- returns tuples for OpenAPI responses
§Attributes
| Attribute | Required | Description |
|---|---|---|
#[status(code)] | Yes | HTTP status code (e.g., 404, 409, 500) |
/// Doc comment | No | Used as response description |