MIT licensed by Rick Owens
Maintained by [email protected]
This version can be pinned in stack with:json-spec-openapi-0.3.0.0@sha256:252c858adeac121b7b3206892e379cfdf7a4e5dce3e36e4a9da1f691e347b640,2738

Module documentation for 0.3.0.0

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"
}