#data-model #markdown #schema #attributes #generate #language-model #object

bin+lib mdmodels

A tool to generate models, code and schemas from markdown files

5 releases

new 0.1.5 Dec 5, 2024
0.1.4 Dec 2, 2024
0.1.3 Nov 17, 2024
0.1.1 Jul 1, 2024
0.1.0 Jul 1, 2024

#109 in Template engine

Download history 4/week @ 2024-08-24 9/week @ 2024-08-31 33/week @ 2024-09-14 61/week @ 2024-09-21 11/week @ 2024-09-28 2/week @ 2024-10-05 3/week @ 2024-10-12 1/week @ 2024-10-19 5/week @ 2024-11-02 117/week @ 2024-11-16 14/week @ 2024-11-23 238/week @ 2024-11-30

372 downloads per month
Used in 2 crates (via mdmodels-macro)

MIT license

265KB
4.5K SLoC

Rust 3.5K SLoC // 0.2% comments Jinja2 877 SLoC // 0.1% comments Shell 5 SLoC // 0.8% comments

MD-Models

Build Status

Welcome to Markdown Models (MD-Models), a powerful framework for research data management that prioritizes flexibility and efficiency.

With an adaptable markdown-based schema language, MD-Models automatically generates schemas and programming language representations. This markdown schema forms the foundation for object-oriented models, enabling seamless cross-format compatibility and simplifying modifications to data structures.

Check out the documentation for more information.

Example

The schema syntax uses Markdown to define data models in a clear and structured way. Each object is introduced with a header, followed by its attributes. Attributes are described with their type, a brief explanation, and optional metadata like terms. Nested or related objects are represented using array types or references to other objects.

---
prefixes:
  schema: http://schema.org/
---

### Person

- **name**
  - Type: string
  - Description: The name of the person
  - Term: schema:name
- age
  - Type: integer
  - Description: The age of the person
  - Term: schema:age
- addresses
  - Type: Address[]
  - Description: The address of the person

### Address

- street
  - Type: string
  - Description: The street of the address

Installation

In order to install the command line tool, you can use the following command:

git clone https://github.com/JR-1991/md-models
cd md-models
cargo install --path .

Command line usage

The command line tool can be used to convert markdown files to various formats. The following command will convert a markdown file to Python code:

md-models convert -i model.md -o lib.py -l python-dataclass

This will read the input file model.md and write the output to lib.py using the Python dataclass template. Alternatively, you can also pass a URL as input to fetch the model remotely. For an overview of all available templates, you can use the following command:

md-models --help

Available templates

The following templates are available:

  • python-dataclass: Python dataclass implementation with JSON-LD support
  • python-pydantic: PyDantic implementation with JSON-LD support
  • python-pydantic-xml: PyDantic implementation with XML support
  • xml-schema: XML schema definition
  • json-schema: JSON schema definition
  • shacl: SHACL shapes definition
  • shex: ShEx shapes definition

Development

This project uses GitHub Actions for continuous integration. The tests can be run using the following command:

cargo test
cargo clippy

Dependencies

~14–30MB
~465K SLoC