-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | 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"
--   }
--   
@package json-spec-openapi @version 0.2.0.0 -- | This module provides tools for integrating the type-level JSON -- Specification with the "openapi" package. -- -- You can use toOpenApiSchema as a low-level tool to transform -- json-spec Specifications into openapi3 -- Schemas directly, irrespective of any particular business data -- type. -- -- More likely you will want to use -XDerivingVia along with -- EncodingSchema or DecodingSchema to derive -- ToSchema instances for your data types. -- -- 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 encode (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"
--   }
--   
-- -- If you needed more control over the content of the schema you might -- also consider doing something like this, e.g. in the case where you -- would like to allow additional properties: -- --
--   data User = User
--     {      name :: Text
--     , lastLogin :: UTCTime
--     }
--   instance HasJsonEncodingSpec User where
--     type EncodingSpec User =
--       JsonObject
--         '[ '("name", JsonString)
--          , '("last-login", JsonDateTime)
--          ]
--     toJSONStructure user =
--       (Field @"name" (name user),
--       (Field @"last-login" (lastLogin user),
--       ()))
--   instance ToSchema User where
--     declareNamedSchema _proxy =
--         pure $
--           NamedSchema
--             Nothing
--             (
--               toOpenApiSchema (EncodingSpec User)
--                 & set
--                     additionalProperties
--                     (Just (AdditionalPropertiesAllowed True))
--             )
--   
module Data.JsonSpec.OpenApi -- | Convert a Specification into an OpenApi Schema. The type -- class Schemaable is an internal and opaque implementation -- detail and not something you should have to worry about. -- -- It should already have an instance for every Specification that -- can be turned into a Schema. If it does not, then that is a -- bug. Please report it! :-) -- -- The limitations of this function are: -- -- toOpenApiSchema :: forall (spec :: Specification). Schemaable spec => Proxy spec -> (Definitions Schema, Schema) -- | Specifications that can be turned into OpenApi Schemas. -- -- This is intended to be an opaque implementation detail. The only -- reason it is exported is because there are some cases where you might -- need to be able to spell this constraint in code that builds off of -- this package. class Schemaable (spec :: Specification) -- | Helper for defining ToSchema instances based on -- HasJsonEncodingSpec using deriving via. -- -- Example: -- --
--   data MyType = ...
--     deriving ToSchema via (EncodingSchema MyType)
--   instance HasJsonEncodingSchema MyType where
--     ...
--   
newtype EncodingSchema a EncodingSchema :: a -> EncodingSchema a [unEncodingSchema] :: EncodingSchema a -> a -- | Helper for defining ToSchema instances based on -- HasJsonDecodingSpec using deriving via. -- -- Example: -- --
--   data MyType = ...
--     deriving ToSchema via (DecodingSchema MyType)
--   instance HasJsonDecodingSchema MyType where
--     ...
--   
newtype DecodingSchema a DecodingSchema :: a -> DecodingSchema a [unDecodingSchema] :: DecodingSchema a -> a instance (Data.JsonSpec.OpenApi.Defs more, Data.JsonSpec.OpenApi.Schemaable spec, GHC.TypeLits.KnownSymbol name) => Data.JsonSpec.OpenApi.Defs ('(name, spec) : more) instance Data.JsonSpec.OpenApi.Defs '[] instance (Data.JsonSpec.OpenApi.Defs defs, GHC.TypeLits.KnownSymbol name) => Data.JsonSpec.OpenApi.Refable ('Data.JsonSpec.Spec.JsonLet defs ('Data.JsonSpec.Spec.JsonRef name)) instance GHC.TypeLits.KnownSymbol name => Data.JsonSpec.OpenApi.Refable ('Data.JsonSpec.Spec.JsonRef name) instance Data.JsonSpec.OpenApi.Schemaable a => Data.JsonSpec.OpenApi.Refable a instance Data.JsonSpec.OpenApi.Schemaable spec => Data.JsonSpec.OpenApi.Schemaable ('Data.JsonSpec.Spec.JsonArray spec) instance Data.JsonSpec.OpenApi.Schemaable 'Data.JsonSpec.Spec.JsonBool instance Data.JsonSpec.OpenApi.Schemaable 'Data.JsonSpec.Spec.JsonDateTime instance (Data.JsonSpec.OpenApi.Schemaable left, Data.JsonSpec.OpenApi.Schemaable right) => Data.JsonSpec.OpenApi.Schemaable ('Data.JsonSpec.Spec.JsonEither left right) instance Data.JsonSpec.OpenApi.Schemaable 'Data.JsonSpec.Spec.JsonInt instance GHC.TypeError.Unsatisfiable (((((((Data.JsonSpec.OpenApi.T "`JsonRef \"" 'GHC.TypeError.:<>: Data.JsonSpec.OpenApi.T target) 'GHC.TypeError.:<>: Data.JsonSpec.OpenApi.T "\"` is not defined.\n") 'GHC.TypeError.:$$: Data.JsonSpec.OpenApi.T "You are trying to use a JsonRef as the \"top level\" ") 'GHC.TypeError.:$$: Data.JsonSpec.OpenApi.T "schema. We try to satisfy this request by looking up ") 'GHC.TypeError.:$$: Data.JsonSpec.OpenApi.T "the reference and inlining it. However in this case you ") 'GHC.TypeError.:$$: Data.JsonSpec.OpenApi.T "are trying to reference a schema which is not defined, ") 'GHC.TypeError.:$$: Data.JsonSpec.OpenApi.T "so this won't work.\n") => Data.JsonSpec.OpenApi.Schemaable ('Data.JsonSpec.Spec.JsonLet '[] ('Data.JsonSpec.Spec.JsonRef target)) instance (Data.JsonSpec.OpenApi.Defs defs, Data.JsonSpec.OpenApi.Schemaable spec) => Data.JsonSpec.OpenApi.Schemaable ('Data.JsonSpec.Spec.JsonLet defs spec) instance (GHC.TypeLits.KnownSymbol target, Data.JsonSpec.OpenApi.Schemaable def, Data.JsonSpec.OpenApi.Schemaable ('Data.JsonSpec.Spec.JsonLet more def)) => Data.JsonSpec.OpenApi.Schemaable ('Data.JsonSpec.Spec.JsonLet ('(target, def) : more) ('Data.JsonSpec.Spec.JsonRef target)) instance (GHC.TypeLits.KnownSymbol name, Data.JsonSpec.OpenApi.Schemaable def, Data.JsonSpec.OpenApi.Schemaable ('Data.JsonSpec.Spec.JsonLet more ('Data.JsonSpec.Spec.JsonRef target))) => Data.JsonSpec.OpenApi.Schemaable ('Data.JsonSpec.Spec.JsonLet ('(name, def) : more) ('Data.JsonSpec.Spec.JsonRef target)) instance Data.JsonSpec.OpenApi.Schemaable 'Data.JsonSpec.Spec.JsonNum instance Data.JsonSpec.OpenApi.Schemaable ('Data.JsonSpec.Spec.JsonObject '[]) instance (Data.JsonSpec.OpenApi.Schemaable ('Data.JsonSpec.Spec.JsonObject more), Data.JsonSpec.OpenApi.Refable spec, GHC.TypeLits.KnownSymbol key) => Data.JsonSpec.OpenApi.Schemaable ('Data.JsonSpec.Spec.JsonObject ('(key, spec) : more)) instance Data.JsonSpec.OpenApi.Schemaable 'Data.JsonSpec.Spec.JsonString instance GHC.TypeLits.KnownSymbol tag => Data.JsonSpec.OpenApi.Schemaable ('Data.JsonSpec.Spec.JsonTag tag) instance (Data.JsonSpec.OpenApi.Schemaable (Data.JsonSpec.Decode.DecodingSpec a), Data.Typeable.Internal.Typeable a) => Data.OpenApi.Internal.Schema.ToSchema (Data.JsonSpec.OpenApi.DecodingSchema a) instance (Data.JsonSpec.OpenApi.Schemaable (Data.JsonSpec.Encode.EncodingSpec a), Data.Typeable.Internal.Typeable a) => Data.OpenApi.Internal.Schema.ToSchema (Data.JsonSpec.OpenApi.EncodingSchema a)