/swiftgen

swiftgen generates Swift code based on a JSON schema

Primary LanguageGoMIT LicenseMIT

Github Action CI Codecov Go Reference

Introduction

Are you over feeling the pain of manually updating your Swift models after finding out (the hard way) that your dependency's JSON schema changed?

swiftgen is a code generation tool for Swift that can help alleviate this pain point by automatically generating models based on a specified schema or structure. This can help ensure that your models are always up-to-date with the latest version of the API, and can save time and effort that would otherwise be spent manually updating models.

Building swiftgen

Prerequisites:

To build and install it:

go install github.com/kevherro/swiftgen@latest

The binary will be installed in $GOPATH/bin ($HOME/go/bin by default).

Basic usage

swiftgen can read a JSON schema file and convert it to Swift structs.

Generate Swift code based on a JSON schema file

% swiftgen --src <json_schema_file> --dest <swift_file>
Where
    json_schema_file: Path to the JSON schema file. Required.
    swift_file: Path to the destination Swift file. Required.

swiftgen project structure is heavily influenced by pprof. Thanks y'all!