# Autogenerating API client models with dynamic Sourcery "Swift templates"

**URL:** <https://forums.swift.org/t/autogenerating-api-client-models-with-dynamic-sourcery-swift-templates/15146>\
**Category:** Sourcery\
**Created:** [August 10, 2018, 1:59pm UTC](https://forums.swift.org/t/autogenerating-api-client-models-with-dynamic-sourcery-swift-templates/15146 "2018-08-10T13:59:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![loudmouth](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/loudmouth/32/3612_2.png) [@loudmouth](https://forums.swift.org/u/loudmouth)\
**Post date:** [August 10, 2018, 1:59pm UTC](https://forums.swift.org/t/autogenerating-api-client-models-with-dynamic-sourcery-swift-templates/15146/1 "2018-08-10T13:59:47Z")

</div>

I have a open-source Swift package that interfaces with a RESTful JSON API. One of the features of this SDK is that if your model classes conform to a specific protocol and follow the proper formatting, you can deserialize your own types from this JSON API (the mechanism is an extension of `Swift.Decodable`.

Anyway, I'm investigating auto-generating the source code for API clients so users can save themselves the time of writing files on their own and I came across Sourcery. I also tried SwiftSyntax, but it really doesn't seem stable yet and the documentation was very sparse.

Anyway, I'd like to use Swift templates instead of Stencil templates so that I can make the proper networking calls to infer the client's model and then dynamically create the templates in Swift—the API & SDK enable introspecting the model to grab the relevant type info and property names.

Is this something you (all) would recommend doing with Sourcery? If so, is there a place where I can find documentation on Swift templates?

Thanks

---

<div class="post-metadata">

**Author:** ![loudmouth](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/loudmouth/32/3612_2.png) [@loudmouth](https://forums.swift.org/u/loudmouth)\
**Post date:** [August 27, 2018, 7:22am UTC](https://forums.swift.org/t/autogenerating-api-client-models-with-dynamic-sourcery-swift-templates/15146/2 "2018-08-27T07:22:45Z")

</div>

Hi, thought I would post my "solution" here just in case:

I have never done much metaprogramming so finding an approach to solve my problem took me some time, but once it clicked, I realized it was quite simple. I'm just using a simple templating language, Mustache, to create my templates and pump the relevant data from my API to generate models.
