MIT licensed by Rick Owens
Maintained by [email protected]
This version can be pinned in stack with:json-spec-openapi-1.2.0.3@sha256:97b605c9e2c00676fb6f14a96bebe0e64a287bfbcc77059833103c7a98839899,2731

Module documentation for 1.2.0.3

json-spec-openapi

This package provides a way to produce openapi3 documentation from a json-spec specification.

Example

Given this data type:

data User = User
  {      name :: Text
  , lastLogin :: Maybe UTCTime
  }
  deriving ToSchema via (EncodingSchema User) -- <-- ToSchema instance defined here
instance HasJsonEncodingSpec User where
  type EncodingSpec User =
    JsonObject
      '[ Required "name" JsonString
       , Optional "last-login" JsonDateTime
       ]
  toJSONStructure user =
    (Field @"name" (name user),
    (fmap (Field @"last-login") (lastLogin user),
    ()))

Calling Data.Aeson.encode (Data.OpenApi3.toSchema (Proxy :: Proxy User)) will produce the following Schema:

{
  "additionalProperties": false,
  "properties": {
    "last-login": {
      "format": "date-time",
      "type": "string"
    },
    "name": {
      "type": "string"
    }
  },
  "required": [
    "name"
  ],
  "type": "object"
}

Changes

Changelog

All notable changes to this project will be documented in this file.

1.2.0.3

  • Updated the lower bound of openapi3 so the package no longer depends directly on insert-ordered-containers.

1.2.0.2

  • Added GHC 9.14 support.

1.2.0.1

  • Upgraded the json-spec dependency (adapts to json-spec 1.3 breaking change where JsonEither takes a type-level list of specs instead of two arguments).