Skip to main content

asyncapi

Attribute Macro asyncapi 

Source
#[asyncapi]
Expand description

Generate AsyncAPI specification for event-driven services.

AsyncAPI is to WebSockets/messaging what OpenAPI is to REST.

§Example

use server_less::asyncapi;

struct ChatService;

#[asyncapi(title = "Chat API", server = "ws://localhost:8080")]
impl ChatService {
    /// Send a message to a room
    fn send_message(&self, room: String, content: String) -> bool { true }

    /// Get message history
    fn get_history(&self, room: String, limit: Option<u32>) -> Vec<String> { vec![] }
}

// Get AsyncAPI spec
let spec = ChatService::asyncapi_spec();
let json = ChatService::asyncapi_json();

// Write to file
ChatService::write_asyncapi("asyncapi.json")?;