{"id":32150521,"url":"https://github.com/hebertialmeida/modelgen","last_synced_at":"2026-02-21T03:02:23.548Z","repository":{"id":43148819,"uuid":"92460109","full_name":"hebertialmeida/ModelGen","owner":"hebertialmeida","description":"🎰 A CLI to generate Models for many languages, based on a JSON Schema and a template.","archived":false,"fork":false,"pushed_at":"2019-07-09T16:21:28.000Z","size":434,"stargazers_count":47,"open_issues_count":1,"forks_count":8,"subscribers_count":3,"default_branch":"master","last_synced_at":"2026-01-15T12:47:45.916Z","etag":null,"topics":["cli","generator","immutable-objects","java","kotlin","model","modelgen","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hebertialmeida.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-26T01:39:56.000Z","updated_at":"2025-09-18T10:26:18.000Z","dependencies_parsed_at":"2022-09-22T01:11:05.623Z","dependency_job_id":null,"html_url":"https://github.com/hebertialmeida/ModelGen","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/hebertialmeida/ModelGen","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hebertialmeida%2FModelGen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hebertialmeida%2FModelGen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hebertialmeida%2FModelGen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hebertialmeida%2FModelGen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hebertialmeida","download_url":"https://codeload.github.com/hebertialmeida/ModelGen/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hebertialmeida%2FModelGen/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29672261,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-21T00:11:43.526Z","status":"online","status_checked_at":"2026-02-21T02:00:07.432Z","response_time":107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","generator","immutable-objects","java","kotlin","model","modelgen","swift"],"created_at":"2025-10-21T10:03:13.800Z","updated_at":"2026-02-21T03:02:23.535Z","avatar_url":"https://github.com/hebertialmeida.png","language":"Swift","readme":"# ModelGen 🎰\n\n**ModelGen** is a command-line tool for generating models from JSON Schemas. \n\n[![Build Status](https://travis-ci.org/hebertialmeida/ModelGen.svg?branch=master)](https://travis-ci.org/hebertialmeida/ModelGen) ![GitHub](https://img.shields.io/github/license/hebertialmeida/modelgen.svg?color=%234c1) [![codecov](https://codecov.io/gh/hebertialmeida/ModelGen/branch/master/graph/badge.svg)](https://codecov.io/gh/hebertialmeida/ModelGen)\n\n## Why?\n\nModels 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.\n\nThis 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.\n\nWe support the following languages:\n\n- [x] Swift\n- [x] Kotlin\n- [x] Java\n\nBut you can add support to any other language with few lines of code.\n\n## How it works?\n\nUnlike most of the model generators, it works with two files, the `.json` and [`.stencil`](https://github.com/kylef/Stencil) so you have full control on how you want your models to look like.\n\nThe 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.\n\n## Examples?\n\nTake a look at [Example](/Example) folder.\n\n## Requirements\n\n- Xcode 10.2+ and Swift 4.2+\n\n## Installation\n\n### Homebrew\n\nRun the following command to install using [homebrew](https://brew.sh/):\n\n```sh\n$ brew tap hebertialmeida/ModelGen https://github.com/hebertialmeida/ModelGen.git\n$ brew install ModelGen\n```\n\n### Manually\n\nRun the following commands to build and install manually:\n\n```terminal\n$ git clone https://github.com/hebertialmeida/ModelGen.git\n$ cd ModelGen\n$ make install\n```\n\n## Defining a schema\n\nModelGen takes a schema file as an input.\n\n```json\n{\n  \"title\": \"Company\",\n  \"type\": \"object\",\n  \"description\": \"Definition of a Company\",\n  \"identifier\": \"id\",\n  \"properties\": {\n    \"id\": {\"type\": \"integer\"},\n    \"name\": {\"type\": \"string\"},\n    \"logo\": {\"type\": \"string\", \"format\": \"uri\"},\n    \"subdomain\": {\"type\": \"string\"}\n  },\n  \"required\": [\"id\", \"name\", \"subdomain\"]\n}\n```\n\n## Defining a template\n\nModelGen takes a template to generate in the format you want.\n\n```swift\n//\n//  {{ spec.title }}.swift\n//  ModelGen\n//\n//  Generated by [ModelGen]: https://github.com/hebertialmeida/ModelGen\n//  Copyright © {% now \"yyyy\" %} ModelGen. All rights reserved.\n//\n\n{% if spec.description %}\n/// {{ spec.description }}\n{% endif %}\npublic struct {{ spec.title }} {\n{% for property in spec.properties %}\n{% if property.doc %}\n    /**\n     {{ property.doc }}\n     */\n{% endif %}\n    public let {{ property.name }}: {{ property.type }}{% if not property.required %}?{% endif %}\n{% endfor %}\n\n    // MARK: - Initializers\n\n{% map spec.properties into params using property %}{{ property.name }}: {{ property.type }}{% if not property.required %}?{% endif %}{% endmap %}\n    public init({{ params|join:\", \" }}) {\n{% for property in spec.properties %}\n        self.{{ property.name }} = {{ property.name }}\n{% endfor %}\n    }\n}\n\n// MARK: - Equatable\n\nextension {{ spec.title }}: Equatable {\n    static public func == (lhs: {{spec.title}}, rhs: {{spec.title}}) -\u003e Bool {\n{% for property in spec.properties %}\n        guard lhs.{{property.name}} == rhs.{{property.name}} else { return false }\n{% endfor %}\n        return true\n    }\n}\n```\n\n## Generating models\n\nTo make it easy you can create a `.modelgen.yml`\n\n```yaml\nspec: ../Specs/\noutput: ./Model/\ntemplate: template.stencil\nlanguage: swift\n```\n\nAnd then:\n```sh\n$ modelgen\n```\n\n#### Without the `.modelgen.yml` file\n\nGenerate from a directory:\n\n```sh\n$ modelgen --spec ./Specs --template template.stencil --output ./Model\n```\n\nGenerate a single file:\n \n```sh\n$ modelgen --spec company.json --template template.stencil --output Company.swift\n```\n\n## Generated output\n\n```swift\n//\n//  Company.swift\n//  ModelGen\n//\n//  Generated by [ModelGen]: https://github.com/hebertialmeida/ModelGen\n//  Copyright © 2019 ModelGen. All rights reserved.\n//\n\n/// Definition of a Company\npublic struct Company {\n    public let id: Int\n    public let logo: URL?\n    public let name: String\n    public let subdomain: String\n\n    // MARK: - Initializers\n\n    public init(id: Int, logo: URL?, name: String, subdomain: String) {\n        self.id = id\n        self.logo = logo\n        self.name = name\n        self.subdomain = subdomain\n    }\n}\n\n// MARK: - Equatable\n\nextension Company: Equatable {\n    static public func == (lhs: Company, rhs: Company) -\u003e Bool {\n        guard lhs.id == rhs.id else { return false }\n        guard lhs.logo == rhs.logo else { return false }\n        guard lhs.name == rhs.name else { return false }\n        guard lhs.subdomain == rhs.subdomain else { return false }\n        return true\n    }\n}\n```\n\n## Attributions\n\nThis tool is powered by:\n\n- [Stencil](https://github.com/kylef/Stencil) and few other libs by [Kyle Fuller](https://github.com/kylef)\n- [StencilSwiftKit](https://github.com/SwiftGen/StencilSwiftKit) by [SwiftGen](https://github.com/SwiftGen/)\n\nThe inital concept was based on [Peter Livesey's](https://github.com/plivesey) [pull request](https://github.com/SwiftGen/SwiftGen/pull/188) and inspired by [plank](https://github.com/pinterest/plank) from Pinterest.\n\nIf you want to contribute, don't hesitate to open an pull request.\n\n## License\n\nModelGen is available under the MIT license. See the [LICENSE](/LICENSE) file.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhebertialmeida%2Fmodelgen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhebertialmeida%2Fmodelgen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhebertialmeida%2Fmodelgen/lists"}