json-spec-openapi: json-spec-openapi

[ json, library, mit, openapi ] [ Propose Tags ] [ Report a vulnerability ]
This version is deprecated.

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 :: UTCTime
  }
  deriving ToSchema via (EncodingSchema User) -- <-- ToSchema instance defined here
instance HasJsonEncodingSpec User where
  type EncodingSpec User =
    JsonObject
      '[ '("name", JsonString)
       , '("last-login", JsonDateTime)
       ]
  toJSONStructure user =
    (Field @"name" (name user),
    (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",
    "last-login"
  ],
  "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, 0.3.1.0, 0.3.1.1, 0.3.1.2, 1.0.0.0 (info)
Dependencies aeson (>=2.1.2.1 && <2.2), base (>=4.17 && <4.18), json-spec (>=0.2.0.0 && <0.3), lens (>=5.2.2 && <5.3), openapi3 (>=3.2.3 && <3.3), text (>=2.0.2 && <2.1) [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 2023-09-20T00:49:34Z
Distributions Stackage:1.0.0.0
Downloads 487 total (40 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.1.0.2

[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 :: UTCTime
  }
  deriving ToSchema via (EncodingSchema User) -- <-- ToSchema instance defined here
instance HasJsonEncodingSpec User where
  type EncodingSpec User =
    JsonObject
      '[ '("name", JsonString)
       , '("last-login", JsonDateTime)
       ]
  toJSONStructure user =
    (Field @"name" (name user),
    (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",
    "last-login"
  ],
  "type": "object"
}