Swiftpack.co - Package - mattpolzin/OpenAPIReflection

OpenAPI support

See parent library at https://github.com/mattpolzin/OpenAPIKit

OpenAPIReflection

A subset of supported Swift types require a JSONEncoder either to make an educated guess at the JSONSchema for the type or in order to turn arbitrary types into AnyCodable for use as schema examples or allowed values.

Swift enums produce schemas with allowed values specified as long as they conform to CaseIterable, Encodable, and AnyJSONCaseIterable (the last of which is free given the former two).

enum CodableEnum: String, CaseIterable, AnyJSONCaseIterable, Codable {
  case one
  case two
}

let schema = CodableEnum.caseIterableOpenAPISchemaGuess(using: JSONEncoder())
// ^ equivalent, although not equatable, to:
let sameSchema = JSONSchema.string(
  allowedValues: "one", "two"
)

Swift structs produce a best-guess schema as long as they conform to Sampleable and Encodable

struct Nested: Encodable, Sampleable {
  let string: String
  let array: [Int]

  // `Sampleable` just enables mirroring, although you could use it to produce
  // OpenAPI examples as well.
  static let sample: Self = .init(
    string: "",
    array: []
  )
}

let schema = Nested.genericOpenAPISchemaGuess(using: JSONEncoder())
// ^ equivalent and indeed equatable to:
let sameSchema = JSONSchema.object(
  properties: [
    "string": .string,
    "array": .array(items: .integer)
  ]
)

Github

link
Stars: 12

Used By

Total: 0

Releases

Version 1.0.0 Alpha 1 - 2020-09-11 03:46:47

Building out first official release against OpenAPIKit v2.

Can you git me now? - 2020-09-09 14:11:25

Switch to Swift Package Manager dependency URLs that contain the .git extension. This is not required by SwiftPM, but if a project does not consistently use the .git extension on dependency URLs (or not) then SwiftPM can get into trouble. The majority of open source projects use or suggest using the .git extension, so this project will standardize in that direction as well.

Update to OpenAPIKit v1.0 - 2020-05-14 00:49:52

⚠️ Breaking Changes ⚠️ Updates to OpenAPIKit v1.0 which introduced a number of breaking changes (although it will now be stable for duration of the v1 major version).

Bump OpenAPIKit version - 2020-05-09 00:33:19

⚠️ Breaking Changes ⚠️ In addition to the breaking changes in OpenAPIKit 0.29.x -> 0.30.x, this version removes support for pre-Swift 5.2 toolchains.

Update OpenAPIKit version - 2020-04-22 02:18:04

Fix date encoding bug - 2020-04-06 03:49:45

Update to OpenAPIKit 0.28.0 - 2020-04-06 03:27:44

Fix infinite recursion bug and json case iterable bug. - 2020-03-20 03:54:56

Initial Release - 2020-03-05 08:03:31

Just port some stuff from OpenAPIKit into this new package.