#[openapi]Expand description
Generate OpenAPI specification without HTTP routing.
Generates OpenAPI 3.0 specs using the same naming conventions as #[http],
but without creating route handlers. Useful for:
- Schema-first development
- Documentation-only use cases
- Separate OpenAPI generation from HTTP routing
§Basic Usage
ⓘ
use server_less::openapi;
#[openapi]
impl UserService {
/// Create a new user
fn create_user(&self, name: String, email: String) -> User { /* ... */ }
/// Get user by ID
fn get_user(&self, id: String) -> Option<User> { /* ... */ }
}
// Generate spec:
let spec = UserService::openapi_spec();§With URL Prefix
ⓘ
#[openapi(prefix = "/api/v1")]
impl UserService { /* ... */ }§Generated Methods
openapi_spec() -> serde_json::Value- OpenAPI 3.0 specification
§Combining with #[http]
If you want separate control over OpenAPI generation:
ⓘ
// Option 1: Disable OpenAPI in http, use standalone macro
#[http(openapi = false)]
#[openapi(prefix = "/api")]
impl MyService { /* ... */ }
// Option 2: Just use http with default (openapi = true)
#[http]
impl MyService { /* ... */ }