9 releases

0.1.8 Feb 5, 2025
0.1.7 Jan 31, 2025
0.1.0 Dec 11, 2024

#118 in Template engine

Download history 148/week @ 2024-12-10 5/week @ 2024-12-17 210/week @ 2024-12-31 159/week @ 2025-01-07 198/week @ 2025-01-14 10/week @ 2025-01-21 222/week @ 2025-01-28 174/week @ 2025-02-04 33/week @ 2025-02-11

447 downloads per month

MIT/Apache

19KB
357 lines

mandolin

crates.io

Generate server code in Rust from openapi specification

Online demo with wasm: https://satoshi-misumi.github.io/mandolin/

Using mandolin

Render axum server code using builtin template

use mandolin;
use serde_yaml;
use std::fs;
fn main() {
  let input=serde_yaml::from_str(fs::read_to_string("./openapi/openapi.yaml").unwrap().as_str()).unwrap();
  let output=mandolin::Mandolin::new(input)
          .template(mandolin::templates::HEADER)
          .template(mandolin::templates::SCHEMA)
          .template(mandolin::templates::TRAIT)
          .template(mandolin::templates::SERVER_AXUM)
          .render()
          .unwrap();
  fs::write("./examples/server_builtin.out.rs", output).unwrap();
}

Render axum server code using custom template

use mandolin;
use serde_yaml;
use std::fs;
fn main() {
  let input=serde_yaml::from_str(fs::read_to_string("./openapi/openapi.yaml").unwrap().as_str()).unwrap();
  let output=mandolin::Mandolin::new(input)
          .template(fs::read_to_string("./templates/header.template").unwrap())
          .template(fs::read_to_string("./templates/schema.template").unwrap())
          .template(fs::read_to_string("./templates/trait.template").unwrap())
          .template(fs::read_to_string("./templates/server_axum.template").unwrap())
          .render()
          .unwrap();
  fs::write("./examples/server_custom.out.rs", output).unwrap();
}

version

  • 0.1.7 hotfix
  • 0.1.6 independent from regex, tera
  • 0.1.5 fix ref filter
  • 0.1.4 replace minijinja from tera
  • 0.1.3
    • simplify mandolin::Mandolin::new pub fn new(api: OpenAPI) -> Result<Self, serde_yaml::Error> into pub fn new(api: OpenAPI) -> Self
    • remove mandolin::Mandolin::template_from_path
    • move serde_yaml(deprecated) in dependency into in dev-dependency
    • update README.md
    • add examples
    • rename mandolin::builtin into mandolin::templates
    • exclude demo from crate
  • 0.1.0 publish

my favorite mandolin music

Dependencies

~2.5–3.5MB
~64K SLoC