fluorite_codegen 0.2.0

Generate rust/typescript codes from schemas specified by Yaml/JSON.
Documentation

Fluorite

Crates.io docs.rs CI

Generate Rust code from schemas specified by YAML.

Using fluorite in a Cargo Project

Please check the demo project for details. Add following dependencies first:

[dependencies]
serde = { version = "1.0", features = ["serde_derive"] }
fluorite = "0.1"
derive-new = "0.7"

[build-dependencies]
fluorite_codegen = "0.1"

Using fluorite_codegen in the build.rs to generate codes during the Cargo build process:

fn main() {
    let out_dir = std::env::var("OUT_DIR").unwrap();
    fluorite_codegen::compile(&["fluorite/demo.yaml"], out_dir.as_str()).unwrap();
}

Instruct your project to include the generated codes, e.g. in your lib or main file:

mod demo {
    include!(concat!(env!("OUT_DIR"), "/demo/mod.rs"));
}

Using fluorite as a CLI

$ fluorite --help
Generate Rust code from schemas specified by YAML.

Usage: fluorite <COMMAND>

Commands:
  rust  Generate Rust code
  help  Print this message or the help of the given subcommand(s)

Options:
  -h, --help     Print help
  -V, --version  Print version

$ fluorite rust --help
Usage: fluorite rust [OPTIONS] --output <OUTPUT>

Options:
  -i, --inputs <INPUTS>  Input definition files
  -o, --output <OUTPUT>  Output directory
  -s, --single-file      Output codes to a single mod file for each package
  -h, --help             Print help

Features

  • Supports Yaml schema definition, see example here
  • A codegen binary program
  • Language Support
    • Rust codegen used in Cargo build.rs script
    • TypeScript codegen
    • CodeGen API to add more language supports to fluorite

Schema Definition Features

More details can be found in definitions.rs.

  • User defined types:
    • Object
    • Enum
    • Union: to support polymorphic types during serialization/deserialization
  • Collection types:
    • List
    • Map
  • Primitive types
    • String
    • Bool
    • DateTime
    • UIntX
    • IntX
    • Float
  • Optional fields support
  • Any type fields support

Development

Make Commands

Command Description
make all Run format check, lint, and tests
make build Build the project
make release Build in release mode
make test Run all tests
make fmt Format code
make fmt-check Check code formatting
make lint Run clippy lints
make check Run cargo check
make clean Clean build artifacts