schema_to_emmylua 0.2.0

A tool to convert JSON schema to EmmyLua annotations.
Documentation
  • Coverage
  • 37.5%
    3 out of 8 items documented0 out of 1 items with examples
  • Size
  • Source code size: 37.85 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 456.83 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 6s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • EmmyLuaLs/emmylua-analyzer-rust
    472 82 99
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • CppCXY

schema_to_emmylua

A tool and library that converts JSON Schema into EmmyLua annotations.

Concise and suitable for automatically generating Lua/EmmyLua comments from backend or normalized JSON Schema (for IDE type hints and static checking).

Features

  • Supports basic JSON Schema types: object, array, string, number, integer, boolean, null
  • Generates @class, @field, @alias and other EmmyLua annotations
  • Provides CLI and library interfaces, can be embedded into build pipelines

Install / Build

Build via Rust (requires Rust toolchain):

cargo install schema_to_emmylua

CLI Usage

Convert schema.json to stdout:

schema_to_emmylua schema_to_emmylua <schema.json> [output.lua]

Library Usage (Example)

Add dependency (Cargo.toml):

schema_to_emmylua = "0.1.0"

Example code:

let schema = r#"
{
    "type": "object",
    "properties": {
        "name": { "type": "string" },
        "age": { "type": "integer" }
    },
    "required": ["name"]
}
"#;

let converter = SchemaConverter::new(true);
let emmylua = converter.convert_from_str(&schema);

Input Example (schema.json)

{
    "type": "object",
    "properties": {
        "name": { "type": "string" },
        "age": { "type": "integer" },
        "tags": {
            "type": "array",
            "items": { "type": "string" }
        }
    },
    "required": ["name"]
}

Generated EmmyLua Example

---@class Person
---@field public name string
---@field public age integer|nil
---@field public tags string[]|nil

License

MIT License