json-spec-openapi: json-spec-openapi

[ json, library, mit, openapi ] [ Propose Tags ]

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

[Skip to Readme]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.1.0.1, 0.1.0.2, 0.1.0.3, 0.2.0.0, 0.2.1.0, 0.2.1.1, 0.3.0.0 (info)
Dependencies aeson (>=2.2.1.0 && <2.3), base (>=4.19.0.0 && <4.20), insert-ordered-containers (>=0.2.5.3 && <0.3), json-spec (>=0.3.0.0 && <0.4), lens (>=5.2.3 && <5.3), openapi3 (>=3.2.4 && <3.3), text (>=2.1 && <2.2) [details]
License MIT
Copyright 2022 Rick Owens
Author Rick Owens
Maintainer rick@owensmurray.com
Category JSON, OpenApi
Home page https://github.com/owensmurray/json-spec-openapi
Uploaded by rickowens at 2024-03-03T03:43:31Z
Distributions Stackage:0.3.0.0
Downloads 230 total (35 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for json-spec-openapi-0.3.0.0

[back to package description]

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