ModelGen is a command-line tool for generating models from JSON Schemas.
Why?
Models are usually boilerplate code, why not generate them and forget? It will save you time writing boilerplate and eliminate model errors as your application scales in complexity.
This means that adding a property to a data object is truly a one-line change — no copy-paste required. If you want to refactor all your models it is simple as changing the template and regenerate them.
We support the following languages:
Swift
Kotlin
Java
But you can add support to any other language with few lines of code.
How it works?
Unlike most of the model generators, it works with two files, the .json and .stencil so you have full control on how you want your models to look like.
The Models are defined in JSON, based on JSON Schema but not limited to, basically anything you add on schema you can use the template. It is an extensible and language-independent specification.
ModelGen 🎰
ModelGen is a command-line tool for generating models from JSON Schemas.
Why?
Models are usually boilerplate code, why not generate them and forget? It will save you time writing boilerplate and eliminate model errors as your application scales in complexity.
This means that adding a property to a data object is truly a one-line change — no copy-paste required. If you want to refactor all your models it is simple as changing the template and regenerate them.
We support the following languages:
But you can add support to any other language with few lines of code.
How it works?
Unlike most of the model generators, it works with two files, the
.json
and.stencil
so you have full control on how you want your models to look like.The Models are defined in JSON, based on JSON Schema but not limited to, basically anything you add on schema you can use the template. It is an extensible and language-independent specification.
Examples?
Take a look at Example folder.
Requirements
Installation
Homebrew
Run the following command to install using homebrew:
Manually
Run the following commands to build and install manually:
Defining a schema
ModelGen takes a schema file as an input.
Defining a template
ModelGen takes a template to generate in the format you want.
Generating models
To make it easy you can create a
.modelgen.yml
And then:
Without the
.modelgen.yml
fileGenerate from a directory:
Generate a single file:
Generated output
Attributions
This tool is powered by:
The inital concept was based on Peter Livesey’s pull request and inspired by plank from Pinterest.
If you want to contribute, don’t hesitate to open an pull request.
License
ModelGen is available under the MIT license. See the LICENSE file.