Visitar URL original
GitHub - rifmj/protofolio Β· GitHub
Skip to content

About

No description, website, or topics provided.

Resources

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Latest commit

Β 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

protofolio πŸš€

CI codecov MSRV

Generate AsyncAPI 3.0 specs from your Rust code ✨
Just like utoipa does for OpenAPI, but for async messaging! 🎯

Overview

protofolio provides procedural macros and runtime support to generate AsyncAPI 3.0 specifications directly from your Rust code. This ensures your documentation stays in sync with your code automatically. No more manual spec maintenance! πŸŽ‰

Quick Start ⚑

Get up and running in minutes! Here's a taste:

use protofolio::AsyncApi;
use protofolio_derive::{AsyncApi, AsyncApiMessage};
use serde::{Deserialize, Serialize};
use schemars::JsonSchema;

// Define your message type
#[derive(Serialize, Deserialize, JsonSchema, AsyncApiMessage)]
#[asyncapi(channel = "events", messageId = "event-v1")]
pub struct Event {
    pub id: String,
    pub data: String,
}

// Define your AsyncAPI specification
#[derive(AsyncApi)]
#[asyncapi(
    info(title = "My API", version = "1.0.0"),
    channels("events"),
    messages(Event)
)]
pub struct MyApi;

// Generate the spec 🎨
let spec = MyApi::asyncapi();
let json = MyApi::asyncapi_json()?;

See the Getting Started Guide for installation and detailed instructions. πŸ“š

Features ✨

  • 🎯 Code-first approach: Generate AsyncAPI specs from Rust types
  • πŸ” Compile-time validation: Channel and message references validated at compile time
  • πŸ›‘οΈ Type safety: Documentation always matches your code
  • 🌐 Multi-protocol support: Built-in support for NATS, Kafka, and MQTT
  • πŸ“„ YAML and JSON output: Generate specs in both YAML and JSON formats
  • πŸ“˜ TypeScript generation: CLI tool to generate TypeScript types from AsyncAPI specs
  • 🏷️ Enhanced attributes: Support for messageId, name, title, contentType, tags, and more
  • 🎨 Root-level tags: Reusable tag definitions at the specification level for better organization
  • πŸ”— Components and $ref references: Reusable messages, schemas, parameters, bindings, and traits with component references
  • βœ… Validation: Built-in validation for generated specifications
  • 🎭 Error handling: Both panic-on-error (asyncapi()) and Result-based (try_asyncapi()) APIs
  • ⚑ Schema caching: Automatic caching of generated JSON schemas for performance
  • πŸ”§ Extensible: Structured for easy expansion to other protocols

Documentation πŸ“š

Guides πŸ“–

  • πŸš€ Getting Started - Installation, requirements, and quick start
  • πŸ’¬ Messages - How to define and configure message types
  • πŸ”„ Operations - How to define publish/subscribe operations
  • πŸ” Security - How to define and use security schemes
  • βœ… Validation - Understanding validation and error handling
  • πŸ“˜ TypeScript Generation - Generate TypeScript types from AsyncAPI specs
  • ⭐ Best Practices - Recommended patterns and conventions

Examples πŸ’‘

Reference πŸ”

Other Documentation

Installation πŸ“¦

Add to your Cargo.toml:

[dependencies]
protofolio = "0.1.0"
protofolio-derive = "0.1.0"
serde = { version = "1.0", features = ["derive"] }
schemars = { version = "1.0", features = ["derive"] }

Requirements: Rust 1.80 or later. Your message types must implement Serialize, Deserialize, and JsonSchema.

See the Getting Started Guide for detailed installation instructions. πŸŽ“

Project Structure

This is a Rust workspace containing:

  • protofolio/ - Main runtime library with AsyncAPI data structures
  • protofolio-derive/ - Procedural macros for code generation
  • protofolio-cli/ - CLI tool for generating TypeScript types from AsyncAPI specs

Status 🎯

This crate is in active development. Here's what's currently available:

  • βœ… Basic AsyncAPI 3.0 spec generation
  • βœ… Multi-protocol support (NATS, Kafka, MQTT)
  • βœ… Message and channel mapping
  • βœ… JSON Schema generation from Rust types with automatic caching
  • βœ… JSON and YAML output formats
  • βœ… Enhanced message attributes (messageId, name, title, contentType, tags)
  • βœ… Channel parameters and bindings support
  • βœ… Specification validation
  • βœ… Comprehensive error handling (try_asyncapi() with Result types)
  • βœ… Operations support (publish/subscribe with full attribute support)
  • βœ… Protocol-specific bindings for NATS, Kafka, and MQTT
  • βœ… Security schemes (userPassword, apiKey, http, oauth2, etc.)
  • βœ… External documentation support (Info, Message, Operation)
  • βœ… Info fields (contact, license, termsOfService)
  • βœ… Server variables (templated URLs with variable definitions)
  • βœ… Message examples (single or multiple example payloads)
  • βœ… Message headers (schema definition for message headers)
  • βœ… Components and $ref references (reusable messages, schemas, parameters, bindings, and traits)
  • βœ… Correlation IDs (message correlation tracking with location expressions)
  • βœ… Channel address field (required AsyncAPI 3.0 field)
  • βœ… Operation ID field (unique operation identifiers)
  • βœ… Root-level tags (reusable tag definitions at specification level)
  • βœ… TypeScript type generation (CLI tool for generating TypeScript types from AsyncAPI specs)

🚧 Coming soon:

  • Full AsyncAPI 3.0 feature set

License

This project is licensed under either of

at your option.

About

No description, website, or topics provided.

Resources

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages