Sign inSign up

thecheatah/vapor-server-codegen

By thecheatah

•Updated almost 7 years ago

Swift Vapor Server Codegen

Image
0

231

thecheatah/vapor-server-codegen repository overview

⁠Git Repo

https://github.com/thecheatah/SwiftVapor-swagger-codegen⁠

⁠Swagger Codegen for the Vapor 4 framework

⁠Overview

Generates a package from a swagger spec file that can be imported by a Vapor 4⁠ project. The package will contain a routes.swift, protocols to implement the APIs and data models.

This package was originally generated by the Swagger Codegen⁠ tool.

This project was designed so that you start building your API using Vapor 4 from a swagger spec file. Then using this tool generate the Vapor Server interface as a package. Your Vapor project will depend on the new interface package and use the auto-generated routes.swift, API Interfaces and data models. See instructions below on how to consume the package's interfaces.

I hope that you find this project to be useful. I would like to see server side swift adopted more commonly as I love the swift language for its performance and other conveniences. Vapor is a low memory, low cpu web server and hope to see it become well established in the future. Now if you get an API swagger definition file, you can get starte fairly quickly using this project. And if you don't have a swagger spec file to start from, I would recommend starting to write an API by defining the swagger spec file first. This project should reduce the overhead of going from API design to compiling working code as you make changes to your APIs.

Let me know if you run into issues with this project or its documentation. Help is welcome!

Known Gaps⁠ were identified by the tests included in this project.

⁠Get Started Quickly using a Docker Image

I manage a docker image⁠ to simplify the codegen process.

Docker image is expected to mount the current working directry to the container's /output directory. You can run the codegen using the following:

docker run --rm -v "$(pwd):/output" thecheatah/vapor-server-codegen:4 -i api.yaml -o ./output --additional-properties projectName=MyProjectAPI

You can structure your directory like this:

|- MyProjectAPI
|-- build.sh
|-- api.yaml

build.sh can contain the following:

#!/bin/sh
docker run --rm -v "$(pwd):/output" thecheatah/vapor-server-codegen:4 -i api.yaml -o . --additional-properties projectName=MyProjectAPI

Running build.sh will create a swiftpm compatible package within the MyProjectAPI directory. You can commit this package and reference it from you Vapor Server using swiftpm.

|- MyProjectAPI
|-- build.sh
|-- api.yaml
|-- Package.swift
|-- Sources
|--- MyProjectAPI
|---- APIs
|----- etc.
|---- Models
|----- etc.
|---- routes.swift

Tag summary

Content type

Image

Digest

Size

72.4 MB

Last updated

almost 7 years ago

docker pull thecheatah/vapor-server-codegen:4