Swiftpack.co - Package - NicholasBellucci/Quill

Quill

A small extension of PigeonPost used to make the setup process easier. Quill, combined with Yams, decodes a YAML input file and converts the model to Swift code.

Requirements

Xcode 10.x or a Swift 4.2/5.x toolchain with Swift Package Manager. Quill is best used in a Run Script Phase but can also be used as a standalone script.

Installation

Add .package(url: "https://github.com/NicholasBellucci/Quill.git", from: "1.0.0") to your Package.swift file's dependencies.

For use with an Xcode project, a Package.swift file will need to be present in the projects directory. Unfortunetly, due to limiations, this cannot be added through File > Swift Packages > Add Package Dependency... as Xcode doesn't have the best support for executable packages.

An example Package.swift file would look like this:

import PackageDescription

let package = Package(
    name: "TestApp",
    dependencies: [
        .package(
            url: "https://github.com/NicholasBellucci/Quill.git", 
            from: "1.0.0"
        )
    ],
    targets: [
        .target(name: "TestApp", path: "TestApp")
    ]
)

Usage

To use Quill in an Xcode project, add a New Run Script Phase to a Target and add swift run quill --input {path to input YAML file} --output {path to output swift file} as the script.

Key YAML Components

These are the building blocks necessary for the input YAML file. If done incorrectly, Quill will throw a decoding error.

Environments

These are all of the APIs that plan to be used with the library. All words will be words and are determined based on a _ separator. For instance, rest_api_example would translate to enum RestApiExample

environments:
    typicode:
        #content
    rest_api_example:
        #content

Headers

The only requirement for the headers is that they are listed on separate lines.

headers:
    Authorization: "Bearer"
    Content-Type: "application/json"

Host

The host url for the API in question. Make sure to not include a forward slash at the end.

host: "https://jsonplaceholder.typicode.com"

Endpoints

The endpoints section includes all of the HTTP methods that will be used with the PigeonPost library. Currently, PigeonPost supports GET, POST, PUT, PATCH, DELETE, HEAD, and OPTIONS

endpoints:
    get:
        getPosts: "/posts"
        getPost: "/posts/{id}"
    post:
        createPost: "/posts"
    put:
        updatePost: "/posts/{id}"
    delete:
        deletePost: "/posts/{id}"

Make sure to only include the methods that are needed as well as their corresponding endpoints. The key for each endpoint path will be used as it's enum case. Also keep in mind that any indended associated values should be wrapped in curly braces. For instance, getPost: "/post/{id} would translate to case .getPost(let id: Any)

Full YAML Example

environments:
    typicode:
        headers:
            Content-Type: "application/json"
        host: "https://jsonplaceholder.typicode.com"
        endpoints:
            get:
                getPosts: "/posts"
                getPost: "/posts/{id}"
            post:
                createPost: "/posts"
            put:
                updatePost: "/posts/{id}"
            delete:
                deletePost: "/posts/{id}"
    rest_api_example:
        headers:
            Content-Type: "application/json"
        host: "http://dummy.restapiexample.com/api/v1"
        endpoints:
            get:
                employees: "/employees"
                employee: "/employee/{id}"
            post:
                createRecord: "/create"
            put:
                updateRecord: "/update/{id}"
            delete:
                deleteRecord: "/delete/{id}"

License

Quill is, and always will be, MIT licensed.

Github

link
Stars: 0
Help us keep the lights on

Dependencies

Used By

Total: 0

Releases

1.0.0 - Oct 31, 2019

Quill's first release 🎉