Skygen is a Rust command line tool that turns an OpenAPI v3 specification into an idiomatic Rust SDK. It can generate SDKs for Cloudflare, DigitalOcean, Exoscale, Hetzner, Scaleway and any provider that publishes an OpenAPI spec.
cargo install --path ./skygenskygen generate --schema <schema-file> --output-dir <output-directory> --config <config-file>The CLI supports different log levels for debugging:
skygen --log-level debug generate --schema openapi.yaml --config config.toml --output-dir ./outputSupported log levels: trace, debug, info, warn, error (default: info)
Skygen uses a TOML configuration file to customize the generated SDK. Here's an example configuration:
crate_name = "cloudflare"
version = "0.1.0-alpha"
edition = "2021" # Optional, defaults to "2021"
description = "Unofficial Rust SDK for Cloudflare"
lib_status = "experimental" # Can be: active, deprecated, experimental
keywords = ["cloudflare", "api", "sdk"]
api_url = "https://api.cloudflare.com/client/v4"
authors = ["Cloudflavor GmbH <foss@cloudflavor.io>"]
# Optional filtering
include_only = ["User", "Account"] # Only include specified models
exclude = ["InternalModel"] # Exclude specific modelscrate_name: The name of the generated Rust crateversion: The version of the generated crateedition: The Rust edition to use (defaults to "2021")description: A brief description of the cratelib_status: The maintenance status of the library (e.g., "active", "deprecated", "experimental")keywords: A list of keywords for the crateapi_url: The base URL for the APIauthors: A list of authors for the crateinclude_only: (Optional) A list of models to include (if not specified, all models are included)exclude: (Optional) A list of models to exclude
skygen generate \
--schema path/to/openapi.yaml \
--config config.toml \
--output-dir ./outputThe output will contain a Cargo crate with a typical src/ layout and a Cargo.toml that exposes optional features like rustls, native-tls and http2.
The generated SDK includes:
src/lib.rs: Main library entry point with preludesrc/client.rs: HTTP client implementation with request/response handlingsrc/errors.rs: Comprehensive error types and handlingsrc/models/: Generated model types with proper module organizationsrc/models/mod.rs: Models module with organized re-exportssrc/apis/: Generated API operation functions grouped by resourceCargo.toml: Crate metadata with feature flags
src/
├─ lib.rs # Main entry point
├─ client.rs # HTTP client
├─ errors.rs # Error types
├─ models/
│ ├─ mod.rs # Models module
│ ├─ model1.rs # Individual models
│ └─ model2.rs
└─ apis/
├─ resource1.rs # API operations
└─ resource2.rs
- Full OpenAPI v3 specification support with comprehensive schema handling
- Advanced model generation with support for complex nested structures
- Composite type handling with intelligent variant naming for oneOf/anyOf/allOf
- Improved operation generation with better naming and organization
- Enhanced error handling with comprehensive error types
- Intelligent name collision resolution using field-based disambiguation
- Modular code organization with dedicated models module
- HTTP client with flexible request/response handling
- Feature flags for different TLS backends (rustls, native-tls) and HTTP/2
- Automatic code formatting with
cargo fmt - Debug logging for troubleshooting complex API specifications
- Inline model hoisting: Automatic extraction of inline schemas into proper model definitions
- Field-based disambiguation: Intelligent naming of similar models based on their field differences
- Operation grouping: Logical organization of API operations by resource type
- Response enum generation: Proper Rust enums for different API response types
- Parameter handling: Comprehensive support for path, query, header, and body parameters
See CONTRIBUTING.md for details.
For complex APIs with many similar models (like Cloudflare), you might encounter name collision errors:
thread 'main' panicked at 'inline model name collision for 'model_name': no unique fields to disambiguate; rename schema'
Solutions:
-
Use
--log-level debugto see detailed information about the collision:skygen --log-level debug generate --schema openapi.json --config config.toml --output-dir ./output
-
Simplify the API spec by removing unused or duplicate models
-
Use
include_onlyin config to generate only specific models:include_only = ["User", "Account", "Product"]
-
Use
excludeto skip problematic models:exclude = ["ProblemModel1", "ProblemModel2"]
For very large specs (10MB+), generation may take significant time and memory. Consider:
- Using
include_onlyto generate subsets of the API - Breaking the API into multiple smaller SDKs
- Increasing system memory limits
Apache‑2.0 – see the LICENSE file.