Go to file
siemensikkema 1df1daa937 Add LICENSE 2021-07-20 23:33:33 +02:00
Sources Add decoded tests 2021-07-20 23:05:26 +02:00
Tests Add tests for Checked 2021-07-20 23:22:20 +02:00
.gitignore First commit 2021-07-20 22:28:28 +02:00
LICENSE Add LICENSE 2021-07-20 23:33:33 +02:00
Package.swift First commit 2021-07-20 22:28:28 +02:00
README.md First commit 2021-07-20 22:28:28 +02:00

README.md

Validations

A Swift framework designed to make validating Decodable input convenient, type safe, versitile, and efficient.

Most APIs and server-side rendered webpages deal with input from the outside world. Not all input is acceptable; some rules must be followed. And when they aren't we should be able to provide clear feedback on what rules were violated. When there is more than one thing wrong with the input we should report all violations instead of just halting at the first error we encounter.

This framework is inspired from working with Vapors Validations. It is an attempt to address some of its pain points, which include:

  • the use of strings to refer to keys in the payload
  • needing to use clunky workarounds to build validations that involve comparing values within the input
  • as well as for those that require asynchronous operations (eg. looking up an email address in the database to see if it is unique)

Note: this framework is at a very early stage and much of the API is subject to change

Goals

By striving to fulfill the goals below, this framework aims to make writing good validations as painless as possible.

  • minimally repetitive code
  • type safety
  • enable complex validations eg. comparing values within a payload
  • usable in an asynchronous context.
  • a single decoding step
  • i18n ready

Structure

It consists of 3 targets: Decoded, Checked, and Validations. These incrementally provide the full functionality of this framework. But each can of course be used on its own.

Decoded: Capture success and error states from decoding

Decoded provides a layer on top of Swift's Codable that allows for capturing and collecting error states.

Checked: Assert successful decoding and obtain a convenient view into the data

Checked provides convenient access to (a hierarchy of) Decoded values and enables guaranteeing successful decoding.

Validations Describe the conditions under which data is valid with

Validations aims to add a powerful domain specific language (DSL) to express what input we should consider valid.