Features may change, and breaking changes can occur. Use with caution.
Gesha is a tool that generates Rust code from an OpenAPI specification.
It helps developers quickly create Rust applications that adhere to OpenAPI standards.
- Supports OpenAPI v3.0 Schema Object.
- Accurately expands inline-defined types.
- Correctly interprets
required
andnullable
attributes. - Comprehensively covers examples and their tests.
You can install the generator using Cargo:
cargo install gesha
Alternatively, you can build from source:
git clone https://github.com/x7c1/gesha.git
cd gesha
cargo build --release
To generate Rust code from an OpenAPI specification:
gesha --schema ./openapi.yaml --output ./generated.rs
--schema <FILE>
: Path to the OpenAPI specification file (YAML format).--output <FILE>
: Path to the generated Rust code file.
Given an OpenAPI specification (openapi.yaml
):
openapi: 3.0.4
info:
title: Example API
version: 1.0.0
paths:
/pets:
get:
operationId: getPets
responses:
'200':
description: A list of pets
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
components:
schemas:
Pet:
type: object
required:
- id
- name
properties:
id:
type: integer
name:
type: string
Run the generator:
gesha --schema ./openapi.yaml --output ./generated.rs
This will generate Rust code in the generated.rs
file.
cat ./generated.rs
You will see something like this:
pub mod schemas {
use serde::Deserialize;
use serde::Serialize;
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct Pet {
pub id: i64,
pub name: String,
}
}
For more detailed examples, check out the following directory:
Contributions are not yet fully accepted, as the project is still under development and far from complete. We really appreciate your interest in contributing, and please check back later!
This project is licensed under the MIT License.