This post is meant to illustrate the current state of tooling for Server Side Swift projects written from the perspective of someone who is still very new to Swift, and is probably making some assumptions that may prove to be incorrect.
I recently began a personal project in which I wanted to use Kubernetes (K8s) & Swift. To get started I created a library that was going to house all the K8s types, and the HTTP Client for communicating with the K8s API. With the goal of importing this library into all the other projects I had planned. Lucky enough for me, K8s uses the OpenAPI Spec, so generating the client code should be easy. I was mistaken, for Swift that is not the case. Specifically for any Swift client that you wanted to run on Linux. At the time of writing this, there did not exist a Swift Client that the Open-API code generation tool could generate that could be ran on Linux. I had concluded, with the help of others, that if I wanted a Pure-Swift Kubernetes library that could be ran on Linux, I would have to write the HTTP Client code myself.
This project is still in the very early stages, and I am still learning Swift.
All is not lost however, the Open-Api generator could generate the model code for the entire K8s API, which is a big win! What I mean by model code is, that the Request/Response types, all the Resource types (Pod, Deployment, Service, etc). There is a bit of a down side here too, the latest version of the Open-Api Generator for Swift is 4.2. At face value this seems like a minor issue to me because the library I was building was targeted for Swift 5.0 and later. I don’t think there would be any breaking changes in 4.2 to 5.0 in this case, but something to note.
I also noticed a lack of Codable support. It was not clear to me how I could get Codable support fo the the types the generator would generate without having basically write the types myself. Which defeats the purpose of the Open-Api Code Generator all together.
As it stands today, the Swifternetes project is off the ground, if even by an inch! Along the way I have learned a lot, and hopefully will consider to do so. The reason for this post is to discuss my experiences trying to build this library, and possible areas of focus for the Server Working Group in 2020
Tools I used:
The Kubernetes Specific generator
- This uses the defined spec and the Open-API generator to generate the model code
- In order to use this tool you must create a swift.sh, and a swift.xml. I can post my version of this file upon request.
- This was used to generate the model code
Areas of Potential Interest
- Give the Open-Api Code Generator for Swift that ability to produce clients that can be compiled and ran on Linux.
- Add support for the new AsyncHTTPClient as one of the client the Open-Api Code generator can generate.
- Update the Open-Api Code Generator for Swift to 5.0 and later
- Give the Open-Api Code Generator for Swift the ability to generate models that conform to Codable
I look forward to the discussion to follow!