fluorite

Crates.iofluorite
lib.rsfluorite
version0.1.9
sourcesrc
created_at2023-12-25 03:50:02.887233
updated_at2024-04-14 19:26:49.97993
descriptionGenerate rust/typescript codes from schemas specified by Yaml/JSON.
homepage
repositoryhttps://github.com/zhxiaogg/fluorite
max_upload_size
id1080026
size9,841
Xiaoguang Zhang (zhxiaogg)

documentation

https://docs.rs/fluorite

README

Fluorite

Crates.io docs.rs

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

The Fluorite Schema definition code is generated by fluorite rust -i src/fluorite/definition.yaml -o ./src/definitions/.

Using fluorite in a Cargo Project

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

[dependencies]
serde = "<serde-version>"
fluorite = "0.1"
derive-new = "0.6"

[build-dependencies]
fluorite_codegen = "0.1"

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

fn main() {
    let out_dir = std::env::var("OUT_DIR").unwrap();
    fluorite::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/typescript codes from schemas specified by Yaml/JSON.

Usage: fluorite [OPTIONS] --output <OUTPUT>

Options:
  -i, --inputs <INPUTS>  Input definition files
  -o, --output <OUTPUT>  Output directory
  -t, --target <TARGET>  Target language [default: rust] [possible values: rust]
  -h, --help             Print help
  -V, --version          Print version

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
  • Support for JSON schema definition (no plan)

Schema Definition Features

More details can be found in definitions.rs.

  • User defined types:
    • Object
    • Enum
    • ObjectEnum: to support polymorphic types during serialization/deserialization
  • Collection types:
    • List
    • Map
  • Primitive types
    • String
    • Bool
    • (WIP) DateTime
    • UIntX
    • IntX
    • Float
  • Optional fields support
  • Any type fields support
Commit count: 38

cargo fmt