fluorite_codegen

Crates.iofluorite_codegen
lib.rsfluorite_codegen
version0.1.9
sourcesrc
created_at2023-12-26 10:05:48.373478
updated_at2024-04-14 19:27:03.625958
descriptionGenerate rust/typescript codes from schemas specified by Yaml/JSON.
homepage
repositoryhttps://github.com/zhxiaogg/fluorite
max_upload_size
id1080817
size54,148
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