utoipa_repr
A derive macro for utoipa that provides ToSchema_repr functionality, similar to how serde_repr works for serde.
This crate allows you to generate OpenAPI schema for enums with #[repr(...)] attributes, representing them as their underlying integer types in the schema instead of as enum variants.
Installation
Add this to your Cargo.toml:
[]
= "0.1"
= "5.0"
Usage
Basic Example
use ToSchema_repr;
// The generated OpenAPI schema will represent this as:
// {
// "type": "integer",
// "format": "int32",
// "minimum": 0
// }
With Signed Integer Types
use ToSchema_repr;
// The generated OpenAPI schema will be:
// {
// "type": "integer",
// "format": "int32"
// }
Supported Types
The following repr types are supported:
- Unsigned integers:
u8,u16,u32,u64,u128,usize - Signed integers:
i8,i16,i32,i64,i128,isize
Schema Generation
- Unsigned types generate schemas with
"minimum": 0constraint - Signed types generate schemas without minimum constraint
- All types currently use
"format": "int32"in the generated schema
Additional repr Attributes
The macro safely ignores other repr attributes like align and packed:
// align(8) is ignored, u16 is used
Error Handling
The macro will produce compile-time errors in the following cases:
- Missing
#[repr(...)]attribute - Unsupported
reprtype - Invalid
reprsyntax
License
Licensed under either of Apache License, Version 2.0, or MIT License at your option.