-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Swagger 2.0 data model -- -- Please see README.md @package swagger2 @version 2.0 module Data.Swagger.SchemaOptions -- | Options that specify how to encode your type to Swagger schema. data SchemaOptions SchemaOptions :: (String -> String) -> (String -> String) -> (String -> String) -> Bool -> Bool -> SchemaOptions -- | Function applied to field labels. Handy for removing common record -- prefixes for example. [fieldLabelModifier] :: SchemaOptions -> String -> String -- | Function applied to constructor tags which could be handy for -- lower-casing them for example. [constructorTagModifier] :: SchemaOptions -> String -> String -- | Function applied to datatype name. [datatypeNameModifier] :: SchemaOptions -> String -> String -- | If True the constructors of a datatype, with all -- nullary constructors, will be encoded to a string enumeration schema -- with the constructor tags as possible values. [allNullaryToStringTag] :: SchemaOptions -> Bool -- | Hide the field name when a record constructor has only one field, like -- a newtype. [unwrapUnaryRecords] :: SchemaOptions -> Bool -- | Default encoding SchemaOptions. -- --
-- SchemaOptions
-- { fieldLabelModifier = id
-- , constructorTagModifier = id
-- , datatypeNameModifier = id
-- , allNullaryToStringTag = True
-- , unwrapUnaryRecords = False
-- }
--
defaultSchemaOptions :: SchemaOptions
module Data.Swagger.Internal.Utils
swaggerFieldRules :: LensRules
gunfoldEnum :: String -> [a] -> (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c a
hashMapMapKeys :: (Eq k', Hashable k') => (k -> k') -> HashMap k v -> HashMap k' v
hashMapTraverseKeys :: (Eq k', Hashable k', Applicative f) => (k -> f k') -> HashMap k v -> f (HashMap k' v)
hashMapReadKeys :: (Eq k, Read k, Hashable k, Alternative f) => HashMap String v -> f (HashMap k v)
jsonPrefix :: String -> Options
parseOneOf :: ToJSON a => [a] -> Value -> Parser a
omitEmptiesExcept :: (Text -> Value -> Bool) -> Value -> Value
omitEmpties :: Value -> Value
genericToJSONWithSub :: (Generic a, GToJSON (Rep a)) => Text -> Options -> a -> Value
genericParseJSONWithSub :: (Generic a, GFromJSON (Rep a)) => Text -> Options -> Value -> Parser a
(<+>) :: Value -> Value -> Value
withDefaults :: (Value -> Parser a) -> [Pair] -> Value -> Parser a
genericMempty :: (Generic a, GMonoid (Rep a)) => a
genericMappend :: (Generic a, GMonoid (Rep a)) => a -> a -> a
class GMonoid f
gmempty :: GMonoid f => f p
gmappend :: GMonoid f => f p -> f p -> f p
class SwaggerMonoid m where swaggerMempty = mempty swaggerMappend = mappend
swaggerMempty :: SwaggerMonoid m => m
swaggerMappend :: SwaggerMonoid m => m -> m -> m
instance Data.Swagger.Internal.Utils.GMonoid GHC.Generics.U1
instance (Data.Swagger.Internal.Utils.GMonoid f, Data.Swagger.Internal.Utils.GMonoid g) => Data.Swagger.Internal.Utils.GMonoid (f GHC.Generics.:*: g)
instance Data.Swagger.Internal.Utils.SwaggerMonoid a => Data.Swagger.Internal.Utils.GMonoid (GHC.Generics.K1 i a)
instance Data.Swagger.Internal.Utils.GMonoid f => Data.Swagger.Internal.Utils.GMonoid (GHC.Generics.M1 i t f)
instance Data.Swagger.Internal.Utils.SwaggerMonoid [a]
instance GHC.Classes.Ord a => Data.Swagger.Internal.Utils.SwaggerMonoid (Data.Set.Base.Set a)
instance GHC.Classes.Ord k => Data.Swagger.Internal.Utils.SwaggerMonoid (Data.Map.Base.Map k v)
instance (GHC.Classes.Eq k, Data.Hashable.Class.Hashable k) => Data.Swagger.Internal.Utils.SwaggerMonoid (Data.HashMap.Base.HashMap k v)
instance Data.Swagger.Internal.Utils.SwaggerMonoid Data.Text.Internal.Text
instance Data.Swagger.Internal.Utils.SwaggerMonoid (GHC.Base.Maybe a)
module Data.Swagger.Declare
-- | A declare monad transformer parametrized by:
--
--
-- {-# LANGUAGE OverloadedStrings #-} -- allows to write Text literals
--
-- import Control.Lens
--
-- data Direction = Up | Down
--
-- instance ToParamSchema Direction where
-- toParamSchema = mempty
-- & type_ .~ SwaggerString
-- & enum_ .~ [ "Up", "Down" ]
--
--
-- Instead of manually writing your ToParamSchema
-- instance you can use a default generic implementation of
-- toParamSchema.
--
-- To do that, simply add deriving Generic clause to your
-- datatype and declare a ToParamSchema instance for your
-- datatype without giving definition for toParamSchema.
--
-- For instance, the previous example can be simplified into this:
--
--
-- {-# LANGUAGE DeriveGeneric #-}
--
-- import GHC.Generics (Generic)
--
-- data Direction = Up | Down deriving Generic
--
-- instance ToParamSchema Direction
--
class ToParamSchema a where toParamSchema = genericToParamSchema defaultSchemaOptions
-- | Convert a type into a plain parameter schema.
--
--
-- >>> encode $ toParamSchema (Proxy :: Proxy Integer)
-- "{\"type\":\"integer\"}"
--
toParamSchema :: ToParamSchema a => proxy a -> ParamSchema t
-- | Default plain schema for Bounded,
-- Integral types.
--
--
-- >>> encode $ toParamSchemaBoundedIntegral (Proxy :: Proxy Int8)
-- "{\"maximum\":127,\"minimum\":-128,\"type\":\"integer\"}"
--
toParamSchemaBoundedIntegral :: (Bounded a, Integral a) => proxy a -> ParamSchema t
timeParamSchema :: String -> ParamSchema t
-- | Format "date" corresponds to yyyy-mm-dd format.
-- | -- >>> toParamSchema (Proxy :: Proxy LocalTime) ^. format -- Just "yyyy-mm-ddThh:MM:ss" ---- |
-- >>> toParamSchema (Proxy :: Proxy ZonedTime) ^. format -- Just "yyyy-mm-ddThh:MM:ss+hhMM" ---- |
-- >>> toParamSchema (Proxy :: Proxy UTCTime) ^. format -- Just "yyyy-mm-ddThh:MM:ssZ" ---- |
-- >>> encode $ toParamSchema (Proxy :: Proxy ())
-- "{\"type\":\"string\",\"enum\":[\"_\"]}"
--
-- | A configurable generic ParamSchema creator.
--
--
-- >>> :set -XDeriveGeneric
--
-- >>> data Color = Red | Blue deriving Generic
--
-- >>> encode $ genericToParamSchema defaultSchemaOptions (Proxy :: Proxy Color)
-- "{\"type\":\"string\",\"enum\":[\"Red\",\"Blue\"]}"
--
genericToParamSchema :: (Generic a, GToParamSchema (Rep a)) => SchemaOptions -> proxy a -> ParamSchema t
class GToParamSchema (f :: * -> *)
gtoParamSchema :: GToParamSchema f => SchemaOptions -> proxy f -> ParamSchema t -> ParamSchema t
class GEnumParamSchema (f :: * -> *)
genumParamSchema :: GEnumParamSchema f => SchemaOptions -> proxy f -> ParamSchema t -> ParamSchema t
data Proxy3 a b c
Proxy3 :: Proxy3 a b c
instance Data.Swagger.Internal.ParamSchema.ToParamSchema GHC.Base.String
instance Data.Swagger.Internal.ParamSchema.ToParamSchema GHC.Types.Bool
instance Data.Swagger.Internal.ParamSchema.ToParamSchema GHC.Integer.Type.Integer
instance Data.Swagger.Internal.ParamSchema.ToParamSchema GHC.Types.Int
instance Data.Swagger.Internal.ParamSchema.ToParamSchema GHC.Int.Int8
instance Data.Swagger.Internal.ParamSchema.ToParamSchema GHC.Int.Int16
instance Data.Swagger.Internal.ParamSchema.ToParamSchema GHC.Int.Int32
instance Data.Swagger.Internal.ParamSchema.ToParamSchema GHC.Int.Int64
instance Data.Swagger.Internal.ParamSchema.ToParamSchema GHC.Types.Word
instance Data.Swagger.Internal.ParamSchema.ToParamSchema GHC.Word.Word8
instance Data.Swagger.Internal.ParamSchema.ToParamSchema GHC.Word.Word16
instance Data.Swagger.Internal.ParamSchema.ToParamSchema GHC.Word.Word32
instance Data.Swagger.Internal.ParamSchema.ToParamSchema GHC.Word.Word64
instance Data.Swagger.Internal.ParamSchema.ToParamSchema GHC.Types.Char
instance Data.Swagger.Internal.ParamSchema.ToParamSchema Data.Scientific.Scientific
instance Data.Swagger.Internal.ParamSchema.ToParamSchema GHC.Types.Double
instance Data.Swagger.Internal.ParamSchema.ToParamSchema GHC.Types.Float
instance Data.Swagger.Internal.ParamSchema.ToParamSchema Data.Time.Calendar.Days.Day
instance Data.Swagger.Internal.ParamSchema.ToParamSchema Data.Time.LocalTime.LocalTime.LocalTime
instance Data.Swagger.Internal.ParamSchema.ToParamSchema Data.Time.LocalTime.LocalTime.ZonedTime
instance Data.Swagger.Internal.ParamSchema.ToParamSchema Data.Time.Clock.UTC.UTCTime
instance Data.Swagger.Internal.ParamSchema.ToParamSchema Data.Time.Clock.UTC.NominalDiffTime
instance Data.Swagger.Internal.ParamSchema.ToParamSchema Data.Text.Internal.Text
instance Data.Swagger.Internal.ParamSchema.ToParamSchema Data.Text.Internal.Lazy.Text
instance Data.Swagger.Internal.ParamSchema.ToParamSchema Data.Monoid.All
instance Data.Swagger.Internal.ParamSchema.ToParamSchema Data.Monoid.Any
instance Data.Swagger.Internal.ParamSchema.ToParamSchema a => Data.Swagger.Internal.ParamSchema.ToParamSchema (Data.Monoid.Sum a)
instance Data.Swagger.Internal.ParamSchema.ToParamSchema a => Data.Swagger.Internal.ParamSchema.ToParamSchema (Data.Monoid.Product a)
instance Data.Swagger.Internal.ParamSchema.ToParamSchema a => Data.Swagger.Internal.ParamSchema.ToParamSchema (Data.Monoid.First a)
instance Data.Swagger.Internal.ParamSchema.ToParamSchema a => Data.Swagger.Internal.ParamSchema.ToParamSchema (Data.Monoid.Last a)
instance Data.Swagger.Internal.ParamSchema.ToParamSchema a => Data.Swagger.Internal.ParamSchema.ToParamSchema (Data.Monoid.Dual a)
instance Data.Swagger.Internal.ParamSchema.ToParamSchema a => Data.Swagger.Internal.ParamSchema.ToParamSchema [a]
instance Data.Swagger.Internal.ParamSchema.ToParamSchema a => Data.Swagger.Internal.ParamSchema.ToParamSchema (Data.Vector.Vector a)
instance Data.Swagger.Internal.ParamSchema.ToParamSchema a => Data.Swagger.Internal.ParamSchema.ToParamSchema (Data.Vector.Primitive.Vector a)
instance Data.Swagger.Internal.ParamSchema.ToParamSchema a => Data.Swagger.Internal.ParamSchema.ToParamSchema (Data.Vector.Storable.Vector a)
instance Data.Swagger.Internal.ParamSchema.ToParamSchema a => Data.Swagger.Internal.ParamSchema.ToParamSchema (Data.Vector.Unboxed.Base.Vector a)
instance Data.Swagger.Internal.ParamSchema.ToParamSchema a => Data.Swagger.Internal.ParamSchema.ToParamSchema (Data.Set.Base.Set a)
instance Data.Swagger.Internal.ParamSchema.ToParamSchema a => Data.Swagger.Internal.ParamSchema.ToParamSchema (Data.HashSet.HashSet a)
instance Data.Swagger.Internal.ParamSchema.ToParamSchema ()
instance Data.Swagger.Internal.ParamSchema.GToParamSchema f => Data.Swagger.Internal.ParamSchema.GToParamSchema (GHC.Generics.D1 d f)
instance GHC.Generics.Constructor c => Data.Swagger.Internal.ParamSchema.GToParamSchema (GHC.Generics.C1 c GHC.Generics.U1)
instance Data.Swagger.Internal.ParamSchema.GToParamSchema f => Data.Swagger.Internal.ParamSchema.GToParamSchema (GHC.Generics.C1 c (GHC.Generics.S1 s f))
instance Data.Swagger.Internal.ParamSchema.ToParamSchema c => Data.Swagger.Internal.ParamSchema.GToParamSchema (GHC.Generics.K1 i c)
instance (Data.Swagger.Internal.ParamSchema.GEnumParamSchema f, Data.Swagger.Internal.ParamSchema.GEnumParamSchema g) => Data.Swagger.Internal.ParamSchema.GToParamSchema (f GHC.Generics.:+: g)
instance (Data.Swagger.Internal.ParamSchema.GEnumParamSchema f, Data.Swagger.Internal.ParamSchema.GEnumParamSchema g) => Data.Swagger.Internal.ParamSchema.GEnumParamSchema (f GHC.Generics.:+: g)
instance GHC.Generics.Constructor c => Data.Swagger.Internal.ParamSchema.GEnumParamSchema (GHC.Generics.C1 c GHC.Generics.U1)
-- | Types and functions for working with Swagger parameter schema.
module Data.Swagger.ParamSchema
-- | Convert a type into a plain ParamSchema.
--
-- An example type and instance:
--
--
-- {-# LANGUAGE OverloadedStrings #-} -- allows to write Text literals
--
-- import Control.Lens
--
-- data Direction = Up | Down
--
-- instance ToParamSchema Direction where
-- toParamSchema = mempty
-- & type_ .~ SwaggerString
-- & enum_ .~ [ "Up", "Down" ]
--
--
-- Instead of manually writing your ToParamSchema
-- instance you can use a default generic implementation of
-- toParamSchema.
--
-- To do that, simply add deriving Generic clause to your
-- datatype and declare a ToParamSchema instance for your
-- datatype without giving definition for toParamSchema.
--
-- For instance, the previous example can be simplified into this:
--
--
-- {-# LANGUAGE DeriveGeneric #-}
--
-- import GHC.Generics (Generic)
--
-- data Direction = Up | Down deriving Generic
--
-- instance ToParamSchema Direction
--
class ToParamSchema a where toParamSchema = genericToParamSchema defaultSchemaOptions
-- | Convert a type into a plain parameter schema.
--
--
-- >>> encode $ toParamSchema (Proxy :: Proxy Integer)
-- "{\"type\":\"integer\"}"
--
toParamSchema :: ToParamSchema a => proxy a -> ParamSchema t
-- | A configurable generic ParamSchema creator.
--
--
-- >>> :set -XDeriveGeneric
--
-- >>> data Color = Red | Blue deriving Generic
--
-- >>> encode $ genericToParamSchema defaultSchemaOptions (Proxy :: Proxy Color)
-- "{\"type\":\"string\",\"enum\":[\"Red\",\"Blue\"]}"
--
genericToParamSchema :: (Generic a, GToParamSchema (Rep a)) => SchemaOptions -> proxy a -> ParamSchema t
-- | Default plain schema for Bounded,
-- Integral types.
--
--
-- >>> encode $ toParamSchemaBoundedIntegral (Proxy :: Proxy Int8)
-- "{\"maximum\":127,\"minimum\":-128,\"type\":\"integer\"}"
--
toParamSchemaBoundedIntegral :: (Bounded a, Integral a) => proxy a -> ParamSchema t
-- | Default schema for password string. "password" format is used
-- to hint UIs the input needs to be obscured.
passwordParamSchema :: ParamSchema t
-- | Default schema for binary data (any sequence of octets).
binaryParamSchema :: ParamSchema t
-- | Default schema for binary data (base64 encoded).
byteParamSchema :: ParamSchema t
-- | Options that specify how to encode your type to Swagger schema.
data SchemaOptions
SchemaOptions :: (String -> String) -> (String -> String) -> (String -> String) -> Bool -> Bool -> SchemaOptions
-- | Function applied to field labels. Handy for removing common record
-- prefixes for example.
[fieldLabelModifier] :: SchemaOptions -> String -> String
-- | Function applied to constructor tags which could be handy for
-- lower-casing them for example.
[constructorTagModifier] :: SchemaOptions -> String -> String
-- | Function applied to datatype name.
[datatypeNameModifier] :: SchemaOptions -> String -> String
-- | If True the constructors of a datatype, with all
-- nullary constructors, will be encoded to a string enumeration schema
-- with the constructor tags as possible values.
[allNullaryToStringTag] :: SchemaOptions -> Bool
-- | Hide the field name when a record constructor has only one field, like
-- a newtype.
[unwrapUnaryRecords] :: SchemaOptions -> Bool
-- | Default encoding SchemaOptions.
--
--
-- SchemaOptions
-- { fieldLabelModifier = id
-- , constructorTagModifier = id
-- , datatypeNameModifier = id
-- , allNullaryToStringTag = True
-- , unwrapUnaryRecords = False
-- }
--
defaultSchemaOptions :: SchemaOptions
module Data.Swagger.Internal.Schema
unnamed :: Schema -> NamedSchema
named :: Text -> Schema -> NamedSchema
plain :: Schema -> Declare (Definitions Schema) NamedSchema
unname :: NamedSchema -> NamedSchema
rename :: Maybe Text -> NamedSchema -> NamedSchema
-- | Convert a type into Schema.
--
-- An example type and instance:
--
--
-- {-# LANGUAGE OverloadedStrings #-} -- allows to write Text literals
-- {-# LANGUAGE OverloadedLists #-} -- allows to write Map and HashMap as lists
--
-- import Control.Lens
--
-- data Coord = Coord { x :: Double, y :: Double }
--
-- instance ToSchema Coord where
-- declareNamedSchema = pure (Just "Coord", schema)
-- where
-- schema = mempty
-- & type_ .~ SwaggerObject
-- & properties .~
-- [ ("x", toSchemaRef (Proxy :: Proxy Double))
-- , ("y", toSchemaRef (Proxy :: Proxy Double))
-- ]
-- & required .~ [ "x", "y" ]
--
--
-- Instead of manually writing your ToSchema instance you
-- can use a default generic implementation of
-- declareNamedSchema.
--
-- To do that, simply add deriving Generic clause to your
-- datatype and declare a ToSchema instance for your
-- datatype without giving definition for
-- declareNamedSchema.
--
-- For instance, the previous example can be simplified into this:
--
--
-- {-# LANGUAGE DeriveGeneric #-}
--
-- import GHC.Generics (Generic)
--
-- data Coord = Coord { x :: Double, y :: Double } deriving Generic
--
-- instance ToSchema Coord
--
class ToSchema a where declareNamedSchema = genericDeclareNamedSchema defaultSchemaOptions
-- | Convert a type into an optionally named schema together with all used
-- definitions. Note that the schema itself is included in definitions
-- only if it is recursive (and thus needs its definition in scope).
declareNamedSchema :: ToSchema a => proxy a -> Declare (Definitions Schema) NamedSchema
-- | Convert a type into a schema and declare all used schema definitions.
declareSchema :: ToSchema a => proxy a -> Declare (Definitions Schema) Schema
-- | Convert a type into an optionally named schema.
--
--
-- >>> toNamedSchema (Proxy :: Proxy String) ^. name
-- Nothing
--
-- >>> encode (toNamedSchema (Proxy :: Proxy String) ^. schema)
-- "{\"type\":\"string\"}"
--
--
--
-- >>> toNamedSchema (Proxy :: Proxy Day) ^. name
-- Just "Day"
--
-- >>> encode (toNamedSchema (Proxy :: Proxy Day) ^. schema)
-- "{\"format\":\"date\",\"type\":\"string\"}"
--
toNamedSchema :: ToSchema a => proxy a -> NamedSchema
-- | Get type's schema name according to its ToSchema
-- instance.
--
-- -- >>> schemaName (Proxy :: Proxy Int) -- Nothing ---- --
-- >>> schemaName (Proxy :: Proxy UTCTime) -- Just "UTCTime" --schemaName :: ToSchema a => proxy a -> Maybe Text -- | Convert a type into a schema. -- --
-- >>> encode $ toSchema (Proxy :: Proxy Int8)
-- "{\"maximum\":127,\"minimum\":-128,\"type\":\"integer\"}"
--
--
--
-- >>> encode $ toSchema (Proxy :: Proxy [Day])
-- "{\"items\":{\"$ref\":\"#/definitions/Day\"},\"type\":\"array\"}"
--
toSchema :: ToSchema a => proxy a -> Schema
-- | Convert a type into a referenced schema if possible. Only named
-- schemas can be referenced, nameless schemas are inlined.
--
--
-- >>> encode $ toSchemaRef (Proxy :: Proxy Integer)
-- "{\"type\":\"integer\"}"
--
--
--
-- >>> encode $ toSchemaRef (Proxy :: Proxy Day)
-- "{\"$ref\":\"#/definitions/Day\"}"
--
toSchemaRef :: ToSchema a => proxy a -> Referenced Schema
-- | Convert a type into a referenced schema if possible and declare all
-- used schema definitions. Only named schemas can be referenced,
-- nameless schemas are inlined.
--
-- Schema definitions are typically declared for every referenced schema.
-- If declareSchemaRef returns a reference, a
-- corresponding schema will be declared (regardless of whether it is
-- recusive or not).
declareSchemaRef :: ToSchema a => proxy a -> Declare (Definitions Schema) (Referenced Schema)
-- | Inline any referenced schema if its name satisfies given predicate.
--
-- NOTE: if a referenced schema is not found in definitions the
-- predicate is ignored and schema stays referenced.
--
-- WARNING: inlineSchemasWhen will produce
-- infinite schemas when inlining recursive schemas.
inlineSchemasWhen :: Data s => (Text -> Bool) -> (Definitions Schema) -> s -> s
-- | Inline any referenced schema if its name is in the given list.
--
-- NOTE: if a referenced schema is not found in definitions it
-- stays referenced even if it appears in the list of names.
--
-- WARNING: inlineSchemas will produce infinite
-- schemas when inlining recursive schemas.
inlineSchemas :: Data s => [Text] -> (Definitions Schema) -> s -> s
-- | Inline all schema references for which the definition can be found in
-- Definitions.
--
-- WARNING: inlineAllSchemas will produce infinite
-- schemas when inlining recursive schemas.
inlineAllSchemas :: Data s => (Definitions Schema) -> s -> s
-- | Convert a type into a schema without references.
--
--
-- >>> encode $ toInlinedSchema (Proxy :: Proxy [Day])
-- "{\"items\":{\"format\":\"date\",\"type\":\"string\"},\"type\":\"array\"}"
--
--
-- WARNING: toInlinedSchema will produce infinite
-- schema when inlining recursive schemas.
toInlinedSchema :: ToSchema a => proxy a -> Schema
-- | Inline all non-recursive schemas for which the definition can
-- be found in Definitions.
inlineNonRecursiveSchemas :: Data s => (Definitions Schema) -> s -> s
-- | Default schema for binary data (any sequence of octets).
binarySchema :: Schema
-- | Default schema for binary data (base64 encoded).
byteSchema :: Schema
-- | Default schema for password string. "password" format is used
-- to hint UIs the input needs to be obscured.
passwordSchema :: Schema
-- | Make an unrestrictive sketch of a Schema based on a
-- ToJSON instance. Produced schema can be used for
-- further refinement.
--
--
-- >>> encode $ sketchSchema "hello"
-- "{\"example\":\"hello\",\"type\":\"string\"}"
--
--
--
-- >>> encode $ sketchSchema (1, 2, 3)
-- "{\"example\":[1,2,3],\"items\":{\"type\":\"number\"},\"type\":\"array\"}"
--
--
--
-- >>> encode $ sketchSchema ("Jack", 25)
-- "{\"example\":[\"Jack\",25],\"items\":[{\"type\":\"string\"},{\"type\":\"number\"}],\"type\":\"array\"}"
--
--
--
-- >>> data Person = Person { name :: String, age :: Int } deriving (Generic)
--
-- >>> instance ToJSON Person
--
-- >>> encode $ sketchSchema (Person "Jack" 25)
-- "{\"example\":{\"age\":25,\"name\":\"Jack\"},\"required\":[\"age\",\"name\"],\"type\":\"object\",\"properties\":{\"age\":{\"type\":\"number\"},\"name\":{\"type\":\"string\"}}}"
--
sketchSchema :: ToJSON a => a -> Schema
-- | Make a restrictive sketch of a Schema based on a
-- ToJSON instance. Produced schema uses as much
-- constraints as possible.
--
--
-- >>> encode $ sketchStrictSchema "hello"
-- "{\"maxLength\":5,\"pattern\":\"hello\",\"minLength\":5,\"type\":\"string\",\"enum\":[\"hello\"]}"
--
--
--
-- >>> encode $ sketchStrictSchema (1, 2, 3)
-- "{\"minItems\":3,\"uniqueItems\":true,\"items\":[{\"maximum\":1,\"minimum\":1,\"multipleOf\":1,\"type\":\"number\",\"enum\":[1]},{\"maximum\":2,\"minimum\":2,\"multipleOf\":2,\"type\":\"number\",\"enum\":[2]},{\"maximum\":3,\"minimum\":3,\"multipleOf\":3,\"type\":\"number\",\"enum\":[3]}],\"maxItems\":3,\"type\":\"array\",\"enum\":[[1,2,3]]}"
--
--
--
-- >>> encode $ sketchStrictSchema ("Jack", 25)
-- "{\"minItems\":2,\"uniqueItems\":true,\"items\":[{\"maxLength\":4,\"pattern\":\"Jack\",\"minLength\":4,\"type\":\"string\",\"enum\":[\"Jack\"]},{\"maximum\":25,\"minimum\":25,\"multipleOf\":25,\"type\":\"number\",\"enum\":[25]}],\"maxItems\":2,\"type\":\"array\",\"enum\":[[\"Jack\",25]]}"
--
--
--
-- >>> data Person = Person { name :: String, age :: Int } deriving (Generic)
--
-- >>> instance ToJSON Person
--
-- >>> encode $ sketchStrictSchema (Person "Jack" 25)
-- "{\"minProperties\":2,\"required\":[\"age\",\"name\"],\"maxProperties\":2,\"type\":\"object\",\"enum\":[{\"age\":25,\"name\":\"Jack\"}],\"properties\":{\"age\":{\"maximum\":25,\"minimum\":25,\"multipleOf\":25,\"type\":\"number\",\"enum\":[25]},\"name\":{\"maxLength\":4,\"pattern\":\"Jack\",\"minLength\":4,\"type\":\"string\",\"enum\":[\"Jack\"]}}}"
--
sketchStrictSchema :: ToJSON a => a -> Schema
class GToSchema (f :: * -> *)
gdeclareNamedSchema :: GToSchema f => SchemaOptions -> proxy f -> Schema -> Declare (Definitions Schema) NamedSchema
timeSchema :: Text -> Schema
-- | Format "date" corresponds to yyyy-mm-dd format.
-- | -- >>> toSchema (Proxy :: Proxy LocalTime) ^. format -- Just "yyyy-mm-ddThh:MM:ss" ---- | Format "date" corresponds to -- yyyy-mm-ddThh:MM:ss(Z|+hh:MM) format. -- |
-- >>> toSchema (Proxy :: Proxy UTCTime) ^. format -- Just "yyyy-mm-ddThh:MM:ssZ" ---- | NOTE: This schema does not account for the uniqueness of keys. -- | Default schema for Bounded, Integral -- types. -- --
-- >>> encode $ toSchemaBoundedIntegral (Proxy :: Proxy Int16)
-- "{\"maximum\":32767,\"minimum\":-32768,\"type\":\"integer\"}"
--
toSchemaBoundedIntegral :: (Bounded a, Integral a) => proxy a -> Schema
-- | Default generic named schema for Bounded,
-- Integral types.
genericToNamedSchemaBoundedIntegral :: (Bounded a, Integral a, Generic a, Rep a ~ D1 d f, Datatype d) => SchemaOptions -> proxy a -> NamedSchema
-- | A configurable generic Schema creator.
genericDeclareSchema :: (Generic a, GToSchema (Rep a)) => SchemaOptions -> proxy a -> Declare (Definitions Schema) Schema
-- | A configurable generic NamedSchema creator. This
-- function applied to defaultSchemaOptions is used as
-- the default for declareNamedSchema when the type is an
-- instance of Generic.
genericDeclareNamedSchema :: (Generic a, GToSchema (Rep a)) => SchemaOptions -> proxy a -> Declare (Definitions Schema) NamedSchema
gdatatypeSchemaName :: Datatype d => SchemaOptions -> proxy d -> Maybe Text
-- | Lift a plain ParamSchema into a model
-- NamedSchema.
paramSchemaToNamedSchema :: (ToParamSchema a, Generic a, Rep a ~ D1 d f, Datatype d) => SchemaOptions -> proxy a -> NamedSchema
-- | Lift a plain ParamSchema into a model
-- Schema.
paramSchemaToSchema :: ToParamSchema a => proxy a -> Schema
nullarySchema :: Schema
gtoNamedSchema :: GToSchema f => SchemaOptions -> proxy f -> NamedSchema
gdeclareSchema :: GToSchema f => SchemaOptions -> proxy f -> Declare (Definitions Schema) Schema
-- | Single field constructor.
gdeclareSchemaRef :: GToSchema a => SchemaOptions -> proxy a -> Declare (Definitions Schema) (Referenced Schema)
appendItem :: Referenced Schema -> Maybe (SwaggerItems Schema) -> Maybe (SwaggerItems Schema)
withFieldSchema :: (Selector s, GToSchema f) => SchemaOptions -> proxy s f -> Bool -> Schema -> Declare (Definitions Schema) Schema
-- | Optional record fields.
-- | Record fields.
gdeclareNamedSumSchema :: GSumToSchema f => SchemaOptions -> proxy f -> Schema -> Declare (Definitions Schema) NamedSchema
type AllNullary = All
class GSumToSchema f
gsumToSchema :: GSumToSchema f => SchemaOptions -> proxy f -> Schema -> WriterT AllNullary (Declare (Definitions Schema)) Schema
gsumConToSchemaWith :: (GToSchema (C1 c f), Constructor c) => Referenced Schema -> SchemaOptions -> proxy (C1 c f) -> Schema -> Schema
gsumConToSchema :: (GToSchema (C1 c f), Constructor c) => SchemaOptions -> proxy (C1 c f) -> Schema -> Declare (Definitions Schema) Schema
data Proxy2 a b
Proxy2 :: Proxy2 a b
data Proxy3 a b c
Proxy3 :: Proxy3 a b c
instance Data.Swagger.Internal.Schema.ToSchema a => Data.Swagger.Internal.Schema.ToSchema [a]
instance Data.Swagger.Internal.Schema.ToSchema GHC.Base.String
instance Data.Swagger.Internal.Schema.ToSchema GHC.Types.Bool
instance Data.Swagger.Internal.Schema.ToSchema GHC.Integer.Type.Integer
instance Data.Swagger.Internal.Schema.ToSchema GHC.Types.Int
instance Data.Swagger.Internal.Schema.ToSchema GHC.Int.Int8
instance Data.Swagger.Internal.Schema.ToSchema GHC.Int.Int16
instance Data.Swagger.Internal.Schema.ToSchema GHC.Int.Int32
instance Data.Swagger.Internal.Schema.ToSchema GHC.Int.Int64
instance Data.Swagger.Internal.Schema.ToSchema GHC.Types.Word
instance Data.Swagger.Internal.Schema.ToSchema GHC.Word.Word8
instance Data.Swagger.Internal.Schema.ToSchema GHC.Word.Word16
instance Data.Swagger.Internal.Schema.ToSchema GHC.Word.Word32
instance Data.Swagger.Internal.Schema.ToSchema GHC.Word.Word64
instance Data.Swagger.Internal.Schema.ToSchema GHC.Types.Char
instance Data.Swagger.Internal.Schema.ToSchema Data.Scientific.Scientific
instance Data.Swagger.Internal.Schema.ToSchema GHC.Types.Double
instance Data.Swagger.Internal.Schema.ToSchema GHC.Types.Float
instance Data.Swagger.Internal.Schema.ToSchema a => Data.Swagger.Internal.Schema.ToSchema (GHC.Base.Maybe a)
instance (Data.Swagger.Internal.Schema.ToSchema a, Data.Swagger.Internal.Schema.ToSchema b) => Data.Swagger.Internal.Schema.ToSchema (Data.Either.Either a b)
instance Data.Swagger.Internal.Schema.ToSchema ()
instance (Data.Swagger.Internal.Schema.ToSchema a, Data.Swagger.Internal.Schema.ToSchema b) => Data.Swagger.Internal.Schema.ToSchema (a, b)
instance (Data.Swagger.Internal.Schema.ToSchema a, Data.Swagger.Internal.Schema.ToSchema b, Data.Swagger.Internal.Schema.ToSchema c) => Data.Swagger.Internal.Schema.ToSchema (a, b, c)
instance (Data.Swagger.Internal.Schema.ToSchema a, Data.Swagger.Internal.Schema.ToSchema b, Data.Swagger.Internal.Schema.ToSchema c, Data.Swagger.Internal.Schema.ToSchema d) => Data.Swagger.Internal.Schema.ToSchema (a, b, c, d)
instance (Data.Swagger.Internal.Schema.ToSchema a, Data.Swagger.Internal.Schema.ToSchema b, Data.Swagger.Internal.Schema.ToSchema c, Data.Swagger.Internal.Schema.ToSchema d, Data.Swagger.Internal.Schema.ToSchema e) => Data.Swagger.Internal.Schema.ToSchema (a, b, c, d, e)
instance (Data.Swagger.Internal.Schema.ToSchema a, Data.Swagger.Internal.Schema.ToSchema b, Data.Swagger.Internal.Schema.ToSchema c, Data.Swagger.Internal.Schema.ToSchema d, Data.Swagger.Internal.Schema.ToSchema e, Data.Swagger.Internal.Schema.ToSchema f) => Data.Swagger.Internal.Schema.ToSchema (a, b, c, d, e, f)
instance (Data.Swagger.Internal.Schema.ToSchema a, Data.Swagger.Internal.Schema.ToSchema b, Data.Swagger.Internal.Schema.ToSchema c, Data.Swagger.Internal.Schema.ToSchema d, Data.Swagger.Internal.Schema.ToSchema e, Data.Swagger.Internal.Schema.ToSchema f, Data.Swagger.Internal.Schema.ToSchema g) => Data.Swagger.Internal.Schema.ToSchema (a, b, c, d, e, f, g)
instance Data.Swagger.Internal.Schema.ToSchema Data.Time.Calendar.Days.Day
instance Data.Swagger.Internal.Schema.ToSchema Data.Time.LocalTime.LocalTime.LocalTime
instance Data.Swagger.Internal.Schema.ToSchema Data.Time.LocalTime.LocalTime.ZonedTime
instance Data.Swagger.Internal.Schema.ToSchema Data.Time.Clock.UTC.NominalDiffTime
instance Data.Swagger.Internal.Schema.ToSchema Data.Time.Clock.UTC.UTCTime
instance Data.Swagger.Internal.Schema.ToSchema Data.Text.Internal.Text
instance Data.Swagger.Internal.Schema.ToSchema Data.Text.Internal.Lazy.Text
instance Data.Swagger.Internal.Schema.ToSchema Data.IntSet.Base.IntSet
instance Data.Swagger.Internal.Schema.ToSchema a => Data.Swagger.Internal.Schema.ToSchema (Data.IntMap.Base.IntMap a)
instance Data.Swagger.Internal.Schema.ToSchema a => Data.Swagger.Internal.Schema.ToSchema (Data.Map.Base.Map GHC.Base.String a)
instance Data.Swagger.Internal.Schema.ToSchema a => Data.Swagger.Internal.Schema.ToSchema (Data.Map.Base.Map Data.Text.Internal.Text a)
instance Data.Swagger.Internal.Schema.ToSchema a => Data.Swagger.Internal.Schema.ToSchema (Data.Map.Base.Map Data.Text.Internal.Lazy.Text a)
instance Data.Swagger.Internal.Schema.ToSchema a => Data.Swagger.Internal.Schema.ToSchema (Data.HashMap.Base.HashMap GHC.Base.String a)
instance Data.Swagger.Internal.Schema.ToSchema a => Data.Swagger.Internal.Schema.ToSchema (Data.HashMap.Base.HashMap Data.Text.Internal.Text a)
instance Data.Swagger.Internal.Schema.ToSchema a => Data.Swagger.Internal.Schema.ToSchema (Data.HashMap.Base.HashMap Data.Text.Internal.Lazy.Text a)
instance Data.Swagger.Internal.Schema.ToSchema a => Data.Swagger.Internal.Schema.ToSchema (Data.Vector.Vector a)
instance Data.Swagger.Internal.Schema.ToSchema a => Data.Swagger.Internal.Schema.ToSchema (Data.Vector.Unboxed.Base.Vector a)
instance Data.Swagger.Internal.Schema.ToSchema a => Data.Swagger.Internal.Schema.ToSchema (Data.Vector.Storable.Vector a)
instance Data.Swagger.Internal.Schema.ToSchema a => Data.Swagger.Internal.Schema.ToSchema (Data.Vector.Primitive.Vector a)
instance Data.Swagger.Internal.Schema.ToSchema a => Data.Swagger.Internal.Schema.ToSchema (Data.Set.Base.Set a)
instance Data.Swagger.Internal.Schema.ToSchema a => Data.Swagger.Internal.Schema.ToSchema (Data.HashSet.HashSet a)
instance Data.Swagger.Internal.Schema.ToSchema Data.Monoid.All
instance Data.Swagger.Internal.Schema.ToSchema Data.Monoid.Any
instance Data.Swagger.Internal.Schema.ToSchema a => Data.Swagger.Internal.Schema.ToSchema (Data.Monoid.Sum a)
instance Data.Swagger.Internal.Schema.ToSchema a => Data.Swagger.Internal.Schema.ToSchema (Data.Monoid.Product a)
instance Data.Swagger.Internal.Schema.ToSchema a => Data.Swagger.Internal.Schema.ToSchema (Data.Monoid.First a)
instance Data.Swagger.Internal.Schema.ToSchema a => Data.Swagger.Internal.Schema.ToSchema (Data.Monoid.Last a)
instance Data.Swagger.Internal.Schema.ToSchema a => Data.Swagger.Internal.Schema.ToSchema (Data.Monoid.Dual a)
instance (Data.Swagger.Internal.Schema.GToSchema f, Data.Swagger.Internal.Schema.GToSchema g) => Data.Swagger.Internal.Schema.GToSchema (f GHC.Generics.:*: g)
instance (GHC.Generics.Datatype d, Data.Swagger.Internal.Schema.GToSchema f) => Data.Swagger.Internal.Schema.GToSchema (GHC.Generics.D1 d f)
instance Data.Swagger.Internal.Schema.GToSchema f => Data.Swagger.Internal.Schema.GToSchema (GHC.Generics.C1 c f)
instance GHC.Generics.Constructor c => Data.Swagger.Internal.Schema.GToSchema (GHC.Generics.C1 c GHC.Generics.U1)
instance (GHC.Generics.Selector s, Data.Swagger.Internal.Schema.GToSchema f) => Data.Swagger.Internal.Schema.GToSchema (GHC.Generics.C1 c (GHC.Generics.S1 s f))
instance (GHC.Generics.Selector s, Data.Swagger.Internal.Schema.ToSchema c) => Data.Swagger.Internal.Schema.GToSchema (GHC.Generics.S1 s (GHC.Generics.K1 i (GHC.Base.Maybe c)))
instance (GHC.Generics.Selector s, Data.Swagger.Internal.Schema.GToSchema f) => Data.Swagger.Internal.Schema.GToSchema (GHC.Generics.S1 s f)
instance Data.Swagger.Internal.Schema.ToSchema c => Data.Swagger.Internal.Schema.GToSchema (GHC.Generics.K1 i (GHC.Base.Maybe c))
instance Data.Swagger.Internal.Schema.ToSchema c => Data.Swagger.Internal.Schema.GToSchema (GHC.Generics.K1 i c)
instance (Data.Swagger.Internal.Schema.GSumToSchema f, Data.Swagger.Internal.Schema.GSumToSchema g) => Data.Swagger.Internal.Schema.GToSchema (f GHC.Generics.:+: g)
instance (Data.Swagger.Internal.Schema.GSumToSchema f, Data.Swagger.Internal.Schema.GSumToSchema g) => Data.Swagger.Internal.Schema.GSumToSchema (f GHC.Generics.:+: g)
instance (GHC.Generics.Constructor c, Data.Swagger.Internal.Schema.GToSchema f) => Data.Swagger.Internal.Schema.GSumToSchema (GHC.Generics.C1 c f)
instance (GHC.Generics.Constructor c, GHC.Generics.Selector s, Data.Swagger.Internal.Schema.GToSchema f) => Data.Swagger.Internal.Schema.GSumToSchema (GHC.Generics.C1 c (GHC.Generics.S1 s f))
instance GHC.Generics.Constructor c => Data.Swagger.Internal.Schema.GSumToSchema (GHC.Generics.C1 c GHC.Generics.U1)
-- | Types and functions for working with Swagger schema.
module Data.Swagger.Schema
-- | Convert a type into Schema.
--
-- An example type and instance:
--
--
-- {-# LANGUAGE OverloadedStrings #-} -- allows to write Text literals
-- {-# LANGUAGE OverloadedLists #-} -- allows to write Map and HashMap as lists
--
-- import Control.Lens
--
-- data Coord = Coord { x :: Double, y :: Double }
--
-- instance ToSchema Coord where
-- declareNamedSchema = pure (Just "Coord", schema)
-- where
-- schema = mempty
-- & type_ .~ SwaggerObject
-- & properties .~
-- [ ("x", toSchemaRef (Proxy :: Proxy Double))
-- , ("y", toSchemaRef (Proxy :: Proxy Double))
-- ]
-- & required .~ [ "x", "y" ]
--
--
-- Instead of manually writing your ToSchema instance you
-- can use a default generic implementation of
-- declareNamedSchema.
--
-- To do that, simply add deriving Generic clause to your
-- datatype and declare a ToSchema instance for your
-- datatype without giving definition for
-- declareNamedSchema.
--
-- For instance, the previous example can be simplified into this:
--
--
-- {-# LANGUAGE DeriveGeneric #-}
--
-- import GHC.Generics (Generic)
--
-- data Coord = Coord { x :: Double, y :: Double } deriving Generic
--
-- instance ToSchema Coord
--
class ToSchema a where declareNamedSchema = genericDeclareNamedSchema defaultSchemaOptions
-- | Convert a type into an optionally named schema together with all used
-- definitions. Note that the schema itself is included in definitions
-- only if it is recursive (and thus needs its definition in scope).
declareNamedSchema :: ToSchema a => proxy a -> Declare (Definitions Schema) NamedSchema
-- | Convert a type into a schema and declare all used schema definitions.
declareSchema :: ToSchema a => proxy a -> Declare (Definitions Schema) Schema
-- | Convert a type into a referenced schema if possible and declare all
-- used schema definitions. Only named schemas can be referenced,
-- nameless schemas are inlined.
--
-- Schema definitions are typically declared for every referenced schema.
-- If declareSchemaRef returns a reference, a
-- corresponding schema will be declared (regardless of whether it is
-- recusive or not).
declareSchemaRef :: ToSchema a => proxy a -> Declare (Definitions Schema) (Referenced Schema)
-- | Convert a type into a schema.
--
--
-- >>> encode $ toSchema (Proxy :: Proxy Int8)
-- "{\"maximum\":127,\"minimum\":-128,\"type\":\"integer\"}"
--
--
--
-- >>> encode $ toSchema (Proxy :: Proxy [Day])
-- "{\"items\":{\"$ref\":\"#/definitions/Day\"},\"type\":\"array\"}"
--
toSchema :: ToSchema a => proxy a -> Schema
-- | Convert a type into a referenced schema if possible. Only named
-- schemas can be referenced, nameless schemas are inlined.
--
--
-- >>> encode $ toSchemaRef (Proxy :: Proxy Integer)
-- "{\"type\":\"integer\"}"
--
--
--
-- >>> encode $ toSchemaRef (Proxy :: Proxy Day)
-- "{\"$ref\":\"#/definitions/Day\"}"
--
toSchemaRef :: ToSchema a => proxy a -> Referenced Schema
-- | Get type's schema name according to its ToSchema
-- instance.
--
-- -- >>> schemaName (Proxy :: Proxy Int) -- Nothing ---- --
-- >>> schemaName (Proxy :: Proxy UTCTime) -- Just "UTCTime" --schemaName :: ToSchema a => proxy a -> Maybe Text -- | Convert a type into a schema without references. -- --
-- >>> encode $ toInlinedSchema (Proxy :: Proxy [Day])
-- "{\"items\":{\"format\":\"date\",\"type\":\"string\"},\"type\":\"array\"}"
--
--
-- WARNING: toInlinedSchema will produce infinite
-- schema when inlining recursive schemas.
toInlinedSchema :: ToSchema a => proxy a -> Schema
-- | A configurable generic NamedSchema creator. This
-- function applied to defaultSchemaOptions is used as
-- the default for declareNamedSchema when the type is an
-- instance of Generic.
genericDeclareNamedSchema :: (Generic a, GToSchema (Rep a)) => SchemaOptions -> proxy a -> Declare (Definitions Schema) NamedSchema
-- | A configurable generic Schema creator.
genericDeclareSchema :: (Generic a, GToSchema (Rep a)) => SchemaOptions -> proxy a -> Declare (Definitions Schema) Schema
-- | Default generic named schema for Bounded,
-- Integral types.
genericToNamedSchemaBoundedIntegral :: (Bounded a, Integral a, Generic a, Rep a ~ D1 d f, Datatype d) => SchemaOptions -> proxy a -> NamedSchema
-- | Default schema for Bounded, Integral
-- types.
--
--
-- >>> encode $ toSchemaBoundedIntegral (Proxy :: Proxy Int16)
-- "{\"maximum\":32767,\"minimum\":-32768,\"type\":\"integer\"}"
--
toSchemaBoundedIntegral :: (Bounded a, Integral a) => proxy a -> Schema
-- | Lift a plain ParamSchema into a model
-- NamedSchema.
paramSchemaToNamedSchema :: (ToParamSchema a, Generic a, Rep a ~ D1 d f, Datatype d) => SchemaOptions -> proxy a -> NamedSchema
-- | Lift a plain ParamSchema into a model
-- Schema.
paramSchemaToSchema :: ToParamSchema a => proxy a -> Schema
-- | Default schema for password string. "password" format is used
-- to hint UIs the input needs to be obscured.
passwordSchema :: Schema
-- | Default schema for binary data (any sequence of octets).
binarySchema :: Schema
-- | Default schema for binary data (base64 encoded).
byteSchema :: Schema
-- | Make an unrestrictive sketch of a Schema based on a
-- ToJSON instance. Produced schema can be used for
-- further refinement.
--
--
-- >>> encode $ sketchSchema "hello"
-- "{\"example\":\"hello\",\"type\":\"string\"}"
--
--
--
-- >>> encode $ sketchSchema (1, 2, 3)
-- "{\"example\":[1,2,3],\"items\":{\"type\":\"number\"},\"type\":\"array\"}"
--
--
--
-- >>> encode $ sketchSchema ("Jack", 25)
-- "{\"example\":[\"Jack\",25],\"items\":[{\"type\":\"string\"},{\"type\":\"number\"}],\"type\":\"array\"}"
--
--
--
-- >>> data Person = Person { name :: String, age :: Int } deriving (Generic)
--
-- >>> instance ToJSON Person
--
-- >>> encode $ sketchSchema (Person "Jack" 25)
-- "{\"example\":{\"age\":25,\"name\":\"Jack\"},\"required\":[\"age\",\"name\"],\"type\":\"object\",\"properties\":{\"age\":{\"type\":\"number\"},\"name\":{\"type\":\"string\"}}}"
--
sketchSchema :: ToJSON a => a -> Schema
-- | Make a restrictive sketch of a Schema based on a
-- ToJSON instance. Produced schema uses as much
-- constraints as possible.
--
--
-- >>> encode $ sketchStrictSchema "hello"
-- "{\"maxLength\":5,\"pattern\":\"hello\",\"minLength\":5,\"type\":\"string\",\"enum\":[\"hello\"]}"
--
--
--
-- >>> encode $ sketchStrictSchema (1, 2, 3)
-- "{\"minItems\":3,\"uniqueItems\":true,\"items\":[{\"maximum\":1,\"minimum\":1,\"multipleOf\":1,\"type\":\"number\",\"enum\":[1]},{\"maximum\":2,\"minimum\":2,\"multipleOf\":2,\"type\":\"number\",\"enum\":[2]},{\"maximum\":3,\"minimum\":3,\"multipleOf\":3,\"type\":\"number\",\"enum\":[3]}],\"maxItems\":3,\"type\":\"array\",\"enum\":[[1,2,3]]}"
--
--
--
-- >>> encode $ sketchStrictSchema ("Jack", 25)
-- "{\"minItems\":2,\"uniqueItems\":true,\"items\":[{\"maxLength\":4,\"pattern\":\"Jack\",\"minLength\":4,\"type\":\"string\",\"enum\":[\"Jack\"]},{\"maximum\":25,\"minimum\":25,\"multipleOf\":25,\"type\":\"number\",\"enum\":[25]}],\"maxItems\":2,\"type\":\"array\",\"enum\":[[\"Jack\",25]]}"
--
--
--
-- >>> data Person = Person { name :: String, age :: Int } deriving (Generic)
--
-- >>> instance ToJSON Person
--
-- >>> encode $ sketchStrictSchema (Person "Jack" 25)
-- "{\"minProperties\":2,\"required\":[\"age\",\"name\"],\"maxProperties\":2,\"type\":\"object\",\"enum\":[{\"age\":25,\"name\":\"Jack\"}],\"properties\":{\"age\":{\"maximum\":25,\"minimum\":25,\"multipleOf\":25,\"type\":\"number\",\"enum\":[25]},\"name\":{\"maxLength\":4,\"pattern\":\"Jack\",\"minLength\":4,\"type\":\"string\",\"enum\":[\"Jack\"]}}}"
--
sketchStrictSchema :: ToJSON a => a -> Schema
-- | Inline all non-recursive schemas for which the definition can
-- be found in Definitions.
inlineNonRecursiveSchemas :: Data s => (Definitions Schema) -> s -> s
-- | Inline all schema references for which the definition can be found in
-- Definitions.
--
-- WARNING: inlineAllSchemas will produce infinite
-- schemas when inlining recursive schemas.
inlineAllSchemas :: Data s => (Definitions Schema) -> s -> s
-- | Inline any referenced schema if its name is in the given list.
--
-- NOTE: if a referenced schema is not found in definitions it
-- stays referenced even if it appears in the list of names.
--
-- WARNING: inlineSchemas will produce infinite
-- schemas when inlining recursive schemas.
inlineSchemas :: Data s => [Text] -> (Definitions Schema) -> s -> s
-- | Inline any referenced schema if its name satisfies given predicate.
--
-- NOTE: if a referenced schema is not found in definitions the
-- predicate is ignored and schema stays referenced.
--
-- WARNING: inlineSchemasWhen will produce
-- infinite schemas when inlining recursive schemas.
inlineSchemasWhen :: Data s => (Text -> Bool) -> (Definitions Schema) -> s -> s
-- | Options that specify how to encode your type to Swagger schema.
data SchemaOptions
SchemaOptions :: (String -> String) -> (String -> String) -> (String -> String) -> Bool -> Bool -> SchemaOptions
-- | Function applied to field labels. Handy for removing common record
-- prefixes for example.
[fieldLabelModifier] :: SchemaOptions -> String -> String
-- | Function applied to constructor tags which could be handy for
-- lower-casing them for example.
[constructorTagModifier] :: SchemaOptions -> String -> String
-- | Function applied to datatype name.
[datatypeNameModifier] :: SchemaOptions -> String -> String
-- | If True the constructors of a datatype, with all
-- nullary constructors, will be encoded to a string enumeration schema
-- with the constructor tags as possible values.
[allNullaryToStringTag] :: SchemaOptions -> Bool
-- | Hide the field name when a record constructor has only one field, like
-- a newtype.
[unwrapUnaryRecords] :: SchemaOptions -> Bool
-- | Default encoding SchemaOptions.
--
--
-- SchemaOptions
-- { fieldLabelModifier = id
-- , constructorTagModifier = id
-- , datatypeNameModifier = id
-- , allNullaryToStringTag = True
-- , unwrapUnaryRecords = False
-- }
--
defaultSchemaOptions :: SchemaOptions
-- | Helper traversals and functions for Swagger operations manipulations.
-- These might be useful when you already have Swagger specification
-- generated by something else.
module Data.Swagger.Operation
-- | All operations of a Swagger spec.
allOperations :: Traversal' Swagger Operation
-- | operationsOf sub will traverse only those operations
-- that are present in sub. Note that Operation
-- is determined by both path and method.
--
--
-- >>> let ok = (mempty :: Operation) & at 200 ?~ "OK"
--
-- >>> let api = (mempty :: Swagger) & paths .~ [("/user", mempty & get ?~ ok & post ?~ ok)]
--
-- >>> let sub = (mempty :: Swagger) & paths .~ [("/user", mempty & get ?~ mempty)]
--
-- >>> encode api
-- "{\"swagger\":\"2.0\",\"info\":{\"version\":\"\",\"title\":\"\"},\"paths\":{\"/user\":{\"post\":{\"responses\":{\"200\":{\"description\":\"OK\"}}},\"get\":{\"responses\":{\"200\":{\"description\":\"OK\"}}}}}}"
--
-- >>> encode $ api & operationsOf sub . at 404 ?~ "Not found"
-- "{\"swagger\":\"2.0\",\"info\":{\"version\":\"\",\"title\":\"\"},\"paths\":{\"/user\":{\"post\":{\"responses\":{\"200\":{\"description\":\"OK\"}}},\"get\":{\"responses\":{\"404\":{\"description\":\"Not found\"},\"200\":{\"description\":\"OK\"}}}}}}"
--
operationsOf :: Swagger -> Traversal' Swagger Operation
-- | Apply tags to all operations and update the global list of tags.
--
-- -- applyTags = applyTagsFor allOperations --applyTags :: [Tag] -> Swagger -> Swagger -- | Apply tags to a part of Swagger spec and update the global list of -- tags. applyTagsFor :: Traversal' Swagger Operation -> [Tag] -> Swagger -> Swagger -- | Set response for all operations. This will also update global schema -- definitions. -- -- If the response already exists it will be overwritten. -- --
-- setResponse = setResponseFor allOperations ---- -- Example: -- --
-- >>> let api = (mempty :: Swagger) & paths .~ [("/user", mempty & get ?~ mempty)]
--
-- >>> let res = declareResponse (Proxy :: Proxy Day)
--
-- >>> encode $ api & setResponse 200 res
-- "{\"swagger\":\"2.0\",\"info\":{\"version\":\"\",\"title\":\"\"},\"definitions\":{\"Day\":{\"format\":\"date\",\"type\":\"string\"}},\"paths\":{\"/user\":{\"get\":{\"responses\":{\"200\":{\"schema\":{\"$ref\":\"#/definitions/Day\"},\"description\":\"\"}}}}}}"
--
--
-- See also setResponseWith.
setResponse :: HttpStatusCode -> Declare (Definitions Schema) Response -> Swagger -> Swagger
-- | Set or update response for all operations. This will also update
-- global schema definitions.
--
-- If the response already exists, but it can't be dereferenced (invalid
-- $ref), then just the new response is used.
--
-- -- setResponseWith = setResponseForWith allOperations ---- -- See also setResponse. setResponseWith :: (Response -> Response -> Response) -> HttpStatusCode -> Declare (Definitions Schema) Response -> Swagger -> Swagger -- | Set response for specified operations. This will also update global -- schema definitions. -- -- If the response already exists it will be overwritten. -- -- See also setResponseForWith. setResponseFor :: Traversal' Swagger Operation -> HttpStatusCode -> Declare (Definitions Schema) Response -> Swagger -> Swagger -- | Set or update response for specified operations. This will also update -- global schema definitions. -- -- If the response already exists, but it can't be dereferenced (invalid -- $ref), then just the new response is used. -- -- See also setResponseFor. setResponseForWith :: Traversal' Swagger Operation -> (Response -> Response -> Response) -> HttpStatusCode -> Declare (Definitions Schema) Response -> Swagger -> Swagger -- | Prepend path piece to all operations of the spec. Leading and trailing -- slashes are trimmed/added automatically. -- --
-- >>> let api = (mempty :: Swagger) & paths .~ [("/info", mempty)]
--
-- >>> encode $ prependPath "user/{user_id}" api ^. paths
-- "{\"/user/{user_id}/info\":{}}"
--
prependPath :: FilePath -> Swagger -> Swagger
-- | Construct a response with Schema while declaring all
-- necessary schema definitions.
--
--
-- >>> encode $ runDeclare (declareResponse (Proxy :: Proxy Day)) mempty
-- "[{\"Day\":{\"format\":\"date\",\"type\":\"string\"}},{\"schema\":{\"$ref\":\"#/definitions/Day\"},\"description\":\"\"}]"
--
declareResponse :: ToSchema a => proxy a -> Declare (Definitions Schema) Response
-- | Validate JSON values with Swagger Schema.
module Data.Swagger.Internal.Schema.Validation
-- | Validate ToJSON instance matches
-- ToSchema for a given value. This can be used with
-- QuickCheck to ensure those instances are coherent:
--
-- -- validateToJSON (x :: Int) == [] ---- -- NOTE: validateToJSON does not perform string -- pattern validation. See -- validateToJSONWithPatternChecker. validateToJSON :: (ToJSON a, ToSchema a) => a -> [ValidationError] -- | Validate ToJSON instance matches -- ToSchema for a given value and pattern checker. This -- can be used with QuickCheck to ensure those instances are coherent. -- -- For validation without patterns see validateToJSON. validateToJSONWithPatternChecker :: (ToJSON a, ToSchema a) => (Pattern -> Text -> Bool) -> a -> [ValidationError] -- | Validation error message. type ValidationError = String -- | Validation result type. data Result a -- | Validation failed with a list of error messages. Failed :: [ValidationError] -> Result a -- | Validation passed. Passed :: a -> Result a -- | Validation configuration. data Config Config :: (Pattern -> Text -> Bool) -> Definitions Schema -> Config -- | Pattern checker for _paramSchemaPattern validation. [configPatternChecker] :: Config -> Pattern -> Text -> Bool -- | Schema definitions in scope to resolve references. [configDefinitions] :: Config -> Definitions Schema -- | Default Config: -- --
-- defaultConfig = Config
-- { configPatternChecker = \_pattern _str -> True
-- , configDefinitions = mempty
-- }
--
defaultConfig :: Config
-- | Value validation.
newtype Validation s a
Validation :: (Config -> s -> Result a) -> Validation s a
[runValidation] :: Validation s a -> Config -> s -> Result a
withConfig :: (Config -> Validation s a) -> Validation s a
withSchema :: (s -> Validation s a) -> Validation s a
-- | Issue an error message.
invalid :: String -> Validation schema a
-- | Validation passed.
valid :: Validation schema ()
-- | Validate schema's property given a lens into that property and
-- property checker.
check :: Lens' s (Maybe a) -> (a -> Validation s ()) -> Validation s ()
-- | Validate same value with different schema.
sub :: t -> Validation t a -> Validation s a
-- | Validate same value with a part of the original schema.
sub_ :: Getting a s a -> Validation a r -> Validation s r
-- | Validate value against a schema given schema reference and validation
-- function.
withRef :: Reference -> (Schema -> Validation s a) -> Validation s a
validateWithSchemaRef :: Referenced Schema -> Value -> Validation s ()
-- | Validate JSON Value with Swagger
-- Schema.
validateWithSchema :: Value -> Validation Schema ()
-- | Validate JSON Value with Swagger
-- ParamSchema.
validateWithParamSchema :: Value -> Validation (ParamSchema t) ()
validateInteger :: Scientific -> Validation (ParamSchema t) ()
validateNumber :: Scientific -> Validation (ParamSchema t) ()
validateString :: Text -> Validation (ParamSchema t) ()
validateArray :: Vector Value -> Validation (ParamSchema t) ()
validateObject :: HashMap Text Value -> Validation Schema ()
validateEnum :: Value -> Validation (ParamSchema t) ()
validateSchemaType :: Value -> Validation Schema ()
validateParamSchemaType :: Value -> Validation (ParamSchema t) ()
instance GHC.Base.Functor (Data.Swagger.Internal.Schema.Validation.Validation s)
instance GHC.Base.Functor Data.Swagger.Internal.Schema.Validation.Result
instance GHC.Show.Show a => GHC.Show.Show (Data.Swagger.Internal.Schema.Validation.Result a)
instance GHC.Classes.Eq a => GHC.Classes.Eq (Data.Swagger.Internal.Schema.Validation.Result a)
instance GHC.Base.Applicative Data.Swagger.Internal.Schema.Validation.Result
instance GHC.Base.Alternative Data.Swagger.Internal.Schema.Validation.Result
instance GHC.Base.Monad Data.Swagger.Internal.Schema.Validation.Result
instance GHC.Base.Applicative (Data.Swagger.Internal.Schema.Validation.Validation schema)
instance GHC.Base.Alternative (Data.Swagger.Internal.Schema.Validation.Validation schema)
instance Data.Profunctor.Unsafe.Profunctor Data.Swagger.Internal.Schema.Validation.Validation
instance Data.Profunctor.Choice.Choice Data.Swagger.Internal.Schema.Validation.Validation
instance GHC.Base.Monad (Data.Swagger.Internal.Schema.Validation.Validation s)
-- | Validate JSON values with Swagger Schema.
module Data.Swagger.Schema.Validation
-- | Validate ToJSON instance matches
-- ToSchema for a given value. This can be used with
-- QuickCheck to ensure those instances are coherent:
--
-- -- validateToJSON (x :: Int) == [] ---- -- NOTE: validateToJSON does not perform string -- pattern validation. See -- validateToJSONWithPatternChecker. validateToJSON :: (ToJSON a, ToSchema a) => a -> [ValidationError] -- | Validate ToJSON instance matches -- ToSchema for a given value and pattern checker. This -- can be used with QuickCheck to ensure those instances are coherent. -- -- For validation without patterns see validateToJSON. validateToJSONWithPatternChecker :: (ToJSON a, ToSchema a) => (Pattern -> Text -> Bool) -> a -> [ValidationError] -- | Validation error message. type ValidationError = String -- | Swagger™ is a project used to describe and document RESTful APIs. -- -- The Swagger specification defines a set of files required to describe -- such an API. These files can then be used by the Swagger-UI project to -- display the API and Swagger-Codegen to generate clients in various -- languages. Additional utilities can also take advantage of the -- resulting files, such as testing tools. module Data.Swagger -- | This is the root document object for the API specification. data Swagger Swagger :: Info -> Maybe Host -> Maybe FilePath -> Maybe [Scheme] -> MimeList -> MimeList -> HashMap FilePath PathItem -> Definitions Schema -> Definitions Param -> Definitions Response -> Definitions SecurityScheme -> [SecurityRequirement] -> Set Tag -> Maybe ExternalDocs -> Swagger -- | Provides metadata about the API. The metadata can be used by the -- clients if needed. [_swaggerInfo] :: Swagger -> Info -- | The host (name or ip) serving the API. It MAY include a port. If the -- host is not included, the host serving the documentation is to be used -- (including the port). [_swaggerHost] :: Swagger -> Maybe Host -- | The base path on which the API is served, which is relative to the -- host. If it is not included, the API is served directly under the -- host. The value MUST start with a leading slash (/). [_swaggerBasePath] :: Swagger -> Maybe FilePath -- | The transfer protocol of the API. If the schemes is not included, the -- default scheme to be used is the one used to access the Swagger -- definition itself. [_swaggerSchemes] :: Swagger -> Maybe [Scheme] -- | A list of MIME types the APIs can consume. This is global to all APIs -- but can be overridden on specific API calls. [_swaggerConsumes] :: Swagger -> MimeList -- | A list of MIME types the APIs can produce. This is global to all APIs -- but can be overridden on specific API calls. [_swaggerProduces] :: Swagger -> MimeList -- | The available paths and operations for the API. Holds the relative -- paths to the individual endpoints. The path is appended to the -- basePath in order to construct the full URL. [_swaggerPaths] :: Swagger -> HashMap FilePath PathItem -- | An object to hold data types produced and consumed by operations. [_swaggerDefinitions] :: Swagger -> Definitions Schema -- | An object to hold parameters that can be used across operations. This -- property does not define global parameters for all operations. [_swaggerParameters] :: Swagger -> Definitions Param -- | An object to hold responses that can be used across operations. This -- property does not define global responses for all operations. [_swaggerResponses] :: Swagger -> Definitions Response -- | Security scheme definitions that can be used across the specification. [_swaggerSecurityDefinitions] :: Swagger -> Definitions SecurityScheme -- | A declaration of which security schemes are applied for the API as a -- whole. The list of values describes alternative security schemes that -- can be used (that is, there is a logical OR between the security -- requirements). Individual operations can override this definition. [_swaggerSecurity] :: Swagger -> [SecurityRequirement] -- | A list of tags used by the specification with additional metadata. The -- order of the tags can be used to reflect on their order by the parsing -- tools. Not all tags that are used by the Operation Object must be -- declared. The tags that are not declared may be organized randomly or -- based on the tools' logic. Each tag name in the list MUST be unique. [_swaggerTags] :: Swagger -> Set Tag -- | Additional external documentation. [_swaggerExternalDocs] :: Swagger -> Maybe ExternalDocs -- | The host (name or ip) serving the API. It MAY include a port. data Host Host :: HostName -> Maybe PortNumber -> Host -- | Host name. [_hostName] :: Host -> HostName -- | Optional port. [_hostPort] :: Host -> Maybe PortNumber -- | The transfer protocol of the API. data Scheme Http :: Scheme Https :: Scheme Ws :: Scheme Wss :: Scheme -- | The object provides metadata about the API. The metadata can be used -- by the clients if needed, and can be presented in the Swagger-UI for -- convenience. data Info Info :: Text -> Maybe Text -> Maybe Text -> Maybe Contact -> Maybe License -> Text -> Info -- | The title of the application. [_infoTitle] :: Info -> Text -- | A short description of the application. GFM syntax can be used for -- rich text representation. [_infoDescription] :: Info -> Maybe Text -- | The Terms of Service for the API. [_infoTermsOfService] :: Info -> Maybe Text -- | The contact information for the exposed API. [_infoContact] :: Info -> Maybe Contact -- | The license information for the exposed API. [_infoLicense] :: Info -> Maybe License -- | Provides the version of the application API (not to be confused with -- the specification version). [_infoVersion] :: Info -> Text -- | Contact information for the exposed API. data Contact Contact :: Maybe Text -> Maybe URL -> Maybe Text -> Contact -- | The identifying name of the contact person/organization. [_contactName] :: Contact -> Maybe Text -- | The URL pointing to the contact information. [_contactUrl] :: Contact -> Maybe URL -- | The email address of the contact person/organization. [_contactEmail] :: Contact -> Maybe Text -- | License information for the exposed API. data License License :: Text -> Maybe URL -> License -- | The license name used for the API. [_licenseName] :: License -> Text -- | A URL to the license used for the API. [_licenseUrl] :: License -> Maybe URL -- | Describes the operations available on a single path. A -- PathItem may be empty, due to ACL constraints. The -- path itself is still exposed to the documentation viewer but they will -- not know which operations and parameters are available. data PathItem PathItem :: Maybe Operation -> Maybe Operation -> Maybe Operation -> Maybe Operation -> Maybe Operation -> Maybe Operation -> Maybe Operation -> [Referenced Param] -> PathItem -- | A definition of a GET operation on this path. [_pathItemGet] :: PathItem -> Maybe Operation -- | A definition of a PUT operation on this path. [_pathItemPut] :: PathItem -> Maybe Operation -- | A definition of a POST operation on this path. [_pathItemPost] :: PathItem -> Maybe Operation -- | A definition of a DELETE operation on this path. [_pathItemDelete] :: PathItem -> Maybe Operation -- | A definition of a OPTIONS operation on this path. [_pathItemOptions] :: PathItem -> Maybe Operation -- | A definition of a HEAD operation on this path. [_pathItemHead] :: PathItem -> Maybe Operation -- | A definition of a PATCH operation on this path. [_pathItemPatch] :: PathItem -> Maybe Operation -- | A list of parameters that are applicable for all the operations -- described under this path. These parameters can be overridden at the -- operation level, but cannot be removed there. The list MUST NOT -- include duplicated parameters. A unique parameter is defined by a -- combination of a name and location. [_pathItemParameters] :: PathItem -> [Referenced Param] -- | Describes a single API operation on a path. data Operation Operation :: Set TagName -> Maybe Text -> Maybe Text -> Maybe ExternalDocs -> Maybe Text -> Maybe MimeList -> Maybe MimeList -> [Referenced Param] -> Responses -> Maybe [Scheme] -> Maybe Bool -> [SecurityRequirement] -> Operation -- | A list of tags for API documentation control. Tags can be used for -- logical grouping of operations by resources or any other qualifier. [_operationTags] :: Operation -> Set TagName -- | A short summary of what the operation does. For maximum readability in -- the swagger-ui, this field SHOULD be less than 120 characters. [_operationSummary] :: Operation -> Maybe Text -- | A verbose explanation of the operation behavior. GFM syntax can be -- used for rich text representation. [_operationDescription] :: Operation -> Maybe Text -- | Additional external documentation for this operation. [_operationExternalDocs] :: Operation -> Maybe ExternalDocs -- | Unique string used to identify the operation. The id MUST be unique -- among all operations described in the API. Tools and libraries MAY use -- the it to uniquely identify an operation, therefore, it is recommended -- to follow common programming naming conventions. [_operationOperationId] :: Operation -> Maybe Text -- | A list of MIME types the operation can consume. This overrides the -- consumes. Just [] MAY be used to clear the -- global definition. [_operationConsumes] :: Operation -> Maybe MimeList -- | A list of MIME types the operation can produce. This overrides the -- produces. Just [] MAY be used to clear the -- global definition. [_operationProduces] :: Operation -> Maybe MimeList -- | A list of parameters that are applicable for this operation. If a -- parameter is already defined at the PathItem, the new -- definition will override it, but can never remove it. The list MUST -- NOT include duplicated parameters. A unique parameter is defined by a -- combination of a name and location. [_operationParameters] :: Operation -> [Referenced Param] -- | The list of possible responses as they are returned from executing -- this operation. [_operationResponses] :: Operation -> Responses -- | The transfer protocol for the operation. The value overrides -- schemes. [_operationSchemes] :: Operation -> Maybe [Scheme] -- | Declares this operation to be deprecated. Usage of the declared -- operation should be refrained. Default value is False. [_operationDeprecated] :: Operation -> Maybe Bool -- | A declaration of which security schemes are applied for this -- operation. The list of values describes alternative security schemes -- that can be used (that is, there is a logical OR between the security -- requirements). This definition overrides any declared top-level -- security. To remove a top-level security declaration, Just [] -- can be used. [_operationSecurity] :: Operation -> [SecurityRequirement] -- | Allows adding meta data to a single tag that is used by -- Operation. It is not mandatory to have a Tag per tag -- used there. data Tag Tag :: TagName -> Maybe Text -> Maybe ExternalDocs -> Tag -- | The name of the tag. [_tagName] :: Tag -> TagName -- | A short description for the tag. GFM syntax can be used for rich text -- representation. [_tagDescription] :: Tag -> Maybe Text -- | Additional external documentation for this tag. [_tagExternalDocs] :: Tag -> Maybe ExternalDocs -- | Tag name. type TagName = Text data SwaggerType t SwaggerString :: SwaggerType t SwaggerNumber :: SwaggerType t SwaggerInteger :: SwaggerType t SwaggerBoolean :: SwaggerType t SwaggerArray :: SwaggerType t SwaggerFile :: SwaggerType ParamOtherSchema SwaggerNull :: SwaggerType Schema SwaggerObject :: SwaggerType Schema type Format = Text -- | A list of definitions that can be used in references. type Definitions = HashMap Text -- | Determines the format of the array. data CollectionFormat t CollectionCSV :: CollectionFormat t CollectionSSV :: CollectionFormat t CollectionTSV :: CollectionFormat t CollectionPipes :: CollectionFormat t CollectionMulti :: CollectionFormat ParamOtherSchema -- | Describes a single operation parameter. A unique parameter is defined -- by a combination of a name and location. data Param Param :: Text -> Maybe Text -> Maybe Bool -> ParamAnySchema -> Param -- | The name of the parameter. Parameter names are case sensitive. [_paramName] :: Param -> Text -- | A brief description of the parameter. This could contain examples of -- use. GFM syntax can be used for rich text representation. [_paramDescription] :: Param -> Maybe Text -- | Determines whether this parameter is mandatory. If the parameter is in -- "path", this property is required and its value MUST be true. -- Otherwise, the property MAY be included and its default value is -- False. [_paramRequired] :: Param -> Maybe Bool -- | Parameter schema. [_paramSchema] :: Param -> ParamAnySchema data ParamAnySchema ParamBody :: (Referenced Schema) -> ParamAnySchema ParamOther :: ParamOtherSchema -> ParamAnySchema data ParamOtherSchema ParamOtherSchema :: ParamLocation -> Maybe Bool -> ParamSchema ParamOtherSchema -> ParamOtherSchema -- | The location of the parameter. [_paramOtherSchemaIn] :: ParamOtherSchema -> ParamLocation -- | Sets the ability to pass empty-valued parameters. This is valid only -- for either ParamQuery or ParamFormData -- and allows you to send a parameter with a name only or an empty value. -- Default value is False. [_paramOtherSchemaAllowEmptyValue] :: ParamOtherSchema -> Maybe Bool [_paramOtherSchemaParamSchema] :: ParamOtherSchema -> ParamSchema ParamOtherSchema data ParamLocation -- | Parameters that are appended to the URL. For example, in -- /items?id=###, the query parameter is id. ParamQuery :: ParamLocation -- | Custom headers that are expected as part of the request. ParamHeader :: ParamLocation -- | Used together with Path Templating, where the parameter value is -- actually part of the operation's URL. This does not include the host -- or base path of the API. For example, in -- items{itemId}, the path parameter is itemId. ParamPath :: ParamLocation -- | Used to describe the payload of an HTTP request when either -- application/x-www-form-urlencoded or -- multipart/form-data are used as the content type of the -- request (in Swagger's definition, the consumes property of an -- operation). This is the only parameter type that can be used to send -- files, thus supporting the ParamFile type. Since -- form parameters are sent in the payload, they cannot be declared -- together with a body parameter for the same operation. Form parameters -- have a different format based on the content-type used (for further -- details, consult -- http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4). ParamFormData :: ParamLocation type ParamName = Text data Header Header :: Maybe Text -> ParamSchema Header -> Header -- | A short description of the header. [_headerDescription] :: Header -> Maybe Text [_headerParamSchema] :: Header -> ParamSchema Header type HeaderName = Text data Example Example :: Map MediaType Value -> Example [getExample] :: Example -> Map MediaType Value data ParamSchema t ParamSchema :: Maybe Value -> SwaggerType t -> Maybe Format -> Maybe (SwaggerItems t) -> Maybe Scientific -> Maybe Bool -> Maybe Scientific -> Maybe Bool -> Maybe Integer -> Maybe Integer -> Maybe Pattern -> Maybe Integer -> Maybe Integer -> Maybe Bool -> Maybe [Value] -> Maybe Scientific -> ParamSchema t -- | Declares the value of the parameter that the server will use if none -- is provided, for example a "count" to control the number of -- results per page might default to 100 if not supplied by the -- client in the request. (Note: "default" has no meaning for required -- parameters.) Unlike JSON Schema this value MUST conform to the defined -- type for this parameter. [_paramSchemaDefault] :: ParamSchema t -> Maybe Value [_paramSchemaType] :: ParamSchema t -> SwaggerType t [_paramSchemaFormat] :: ParamSchema t -> Maybe Format [_paramSchemaItems] :: ParamSchema t -> Maybe (SwaggerItems t) [_paramSchemaMaximum] :: ParamSchema t -> Maybe Scientific [_paramSchemaExclusiveMaximum] :: ParamSchema t -> Maybe Bool [_paramSchemaMinimum] :: ParamSchema t -> Maybe Scientific [_paramSchemaExclusiveMinimum] :: ParamSchema t -> Maybe Bool [_paramSchemaMaxLength] :: ParamSchema t -> Maybe Integer [_paramSchemaMinLength] :: ParamSchema t -> Maybe Integer [_paramSchemaPattern] :: ParamSchema t -> Maybe Pattern [_paramSchemaMaxItems] :: ParamSchema t -> Maybe Integer [_paramSchemaMinItems] :: ParamSchema t -> Maybe Integer [_paramSchemaUniqueItems] :: ParamSchema t -> Maybe Bool [_paramSchemaEnum] :: ParamSchema t -> Maybe [Value] [_paramSchemaMultipleOf] :: ParamSchema t -> Maybe Scientific data Schema Schema :: Maybe Text -> Maybe Text -> [ParamName] -> Maybe [Schema] -> HashMap Text (Referenced Schema) -> Maybe Schema -> Maybe Text -> Maybe Bool -> Maybe Xml -> Maybe ExternalDocs -> Maybe Value -> Maybe Integer -> Maybe Integer -> ParamSchema Schema -> Schema [_schemaTitle] :: Schema -> Maybe Text [_schemaDescription] :: Schema -> Maybe Text [_schemaRequired] :: Schema -> [ParamName] [_schemaAllOf] :: Schema -> Maybe [Schema] [_schemaProperties] :: Schema -> HashMap Text (Referenced Schema) [_schemaAdditionalProperties] :: Schema -> Maybe Schema [_schemaDiscriminator] :: Schema -> Maybe Text [_schemaReadOnly] :: Schema -> Maybe Bool [_schemaXml] :: Schema -> Maybe Xml [_schemaExternalDocs] :: Schema -> Maybe ExternalDocs [_schemaExample] :: Schema -> Maybe Value [_schemaMaxProperties] :: Schema -> Maybe Integer [_schemaMinProperties] :: Schema -> Maybe Integer [_schemaParamSchema] :: Schema -> ParamSchema Schema -- | A Schema with an optional name. This name can be used -- in references. data NamedSchema NamedSchema :: Maybe Text -> Schema -> NamedSchema [_namedSchemaName] :: NamedSchema -> Maybe Text [_namedSchemaSchema] :: NamedSchema -> Schema -- | Items for SwaggerArray schemas. -- -- SwaggerItemsPrimitive should be used only for query -- params, headers and path pieces. The CollectionFormat -- t parameter specifies how elements of an array should be -- displayed. Note that fmt in SwaggerItemsPrimitive -- fmt schema specifies format for elements of type schema. -- This is different from the original Swagger's Items Object. -- -- SwaggerItemsObject should be used to specify -- homogenous array Schemas. -- -- SwaggerItemsArray should be used to specify tuple -- Schemas. data SwaggerItems t SwaggerItemsPrimitive :: Maybe (CollectionFormat t) -> ParamSchema t -> SwaggerItems t SwaggerItemsObject :: Referenced Schema -> SwaggerItems Schema SwaggerItemsArray :: [Referenced Schema] -> SwaggerItems Schema data Xml Xml :: Maybe Text -> Maybe Text -> Maybe Text -> Maybe Bool -> Maybe Bool -> Xml -- | Replaces the name of the element/attribute used for the described -- schema property. When defined within the SwaggerItems -- (items), it will affect the name of the individual XML elements within -- the list. When defined alongside type being array (outside the items), -- it will affect the wrapping element and only if wrapped is true. If -- wrapped is false, it will be ignored. [_xmlName] :: Xml -> Maybe Text -- | The URL of the namespace definition. Value SHOULD be in the form of a -- URL. [_xmlNamespace] :: Xml -> Maybe Text -- | The prefix to be used for the name. [_xmlPrefix] :: Xml -> Maybe Text -- | Declares whether the property definition translates to an attribute -- instead of an element. Default value is False. [_xmlAttribute] :: Xml -> Maybe Bool -- | MAY be used only for an array definition. Signifies whether the array -- is wrapped (for example, -- <books><book><book></books>) -- or unwrapped (<book><book>). Default value -- is False. The definition takes effect only when defined -- alongside type being array (outside the items). [_xmlWrapped] :: Xml -> Maybe Bool -- | A container for the expected responses of an operation. The container -- maps a HTTP response code to the expected response. It is not expected -- from the documentation to necessarily cover all possible HTTP response -- codes, since they may not be known in advance. However, it is expected -- from the documentation to cover a successful operation response and -- any known errors. data Responses Responses :: Maybe (Referenced Response) -> HashMap HttpStatusCode (Referenced Response) -> Responses -- | The documentation of responses other than the ones declared for -- specific HTTP response codes. It can be used to cover undeclared -- responses. [_responsesDefault] :: Responses -> Maybe (Referenced Response) -- | Any HTTP status code can be used as the property name (one property -- per HTTP status code). Describes the expected response for those HTTP -- status codes. [_responsesResponses] :: Responses -> HashMap HttpStatusCode (Referenced Response) -- | Describes a single response from an API Operation. data Response Response :: Text -> Maybe (Referenced Schema) -> HashMap HeaderName Header -> Maybe Example -> Response -- | A short description of the response. GFM syntax can be used for rich -- text representation. [_responseDescription] :: Response -> Text -- | A definition of the response structure. It can be a primitive, an -- array or an object. If this field does not exist, it means no content -- is returned as part of the response. As an extension to the Schema -- Object, its root type value may also be "file". This SHOULD be -- accompanied by a relevant produces mime-type. [_responseSchema] :: Response -> Maybe (Referenced Schema) -- | A list of headers that are sent with the response. [_responseHeaders] :: Response -> HashMap HeaderName Header -- | An example of the response message. [_responseExamples] :: Response -> Maybe Example type HttpStatusCode = Int data SecurityScheme SecurityScheme :: SecuritySchemeType -> Maybe Text -> SecurityScheme -- | The type of the security scheme. [_securitySchemeType] :: SecurityScheme -> SecuritySchemeType -- | A short description for security scheme. [_securitySchemeDescription] :: SecurityScheme -> Maybe Text data SecuritySchemeType SecuritySchemeBasic :: SecuritySchemeType SecuritySchemeApiKey :: ApiKeyParams -> SecuritySchemeType SecuritySchemeOAuth2 :: OAuth2Params -> SecuritySchemeType -- | Lists the required security schemes to execute this operation. The -- object can have multiple security schemes declared in it which are all -- required (that is, there is a logical AND between the schemes). newtype SecurityRequirement SecurityRequirement :: HashMap Text [Text] -> SecurityRequirement [getSecurityRequirement] :: SecurityRequirement -> HashMap Text [Text] data ApiKeyParams ApiKeyParams :: Text -> ApiKeyLocation -> ApiKeyParams -- | The name of the header or query parameter to be used. [_apiKeyName] :: ApiKeyParams -> Text -- | The location of the API key. [_apiKeyIn] :: ApiKeyParams -> ApiKeyLocation -- | The location of the API key. data ApiKeyLocation ApiKeyQuery :: ApiKeyLocation ApiKeyHeader :: ApiKeyLocation data OAuth2Params OAuth2Params :: OAuth2Flow -> HashMap Text Text -> OAuth2Params -- | The flow used by the OAuth2 security scheme. [_oauth2Flow] :: OAuth2Params -> OAuth2Flow -- | The available scopes for the OAuth2 security scheme. [_oauth2Scopes] :: OAuth2Params -> HashMap Text Text data OAuth2Flow OAuth2Implicit :: AuthorizationURL -> OAuth2Flow OAuth2Password :: TokenURL -> OAuth2Flow OAuth2Application :: TokenURL -> OAuth2Flow OAuth2AccessCode :: AuthorizationURL -> TokenURL -> OAuth2Flow -- | The authorization URL to be used for OAuth2 flow. This SHOULD be in -- the form of a URL. type AuthorizationURL = Text -- | The token URL to be used for OAuth2 flow. This SHOULD be in the form -- of a URL. type TokenURL = Text -- | Allows referencing an external resource for extended documentation. data ExternalDocs ExternalDocs :: Maybe Text -> URL -> ExternalDocs -- | A short description of the target documentation. GFM syntax can be -- used for rich text representation. [_externalDocsDescription] :: ExternalDocs -> Maybe Text -- | The URL for the target documentation. [_externalDocsUrl] :: ExternalDocs -> URL -- | A simple object to allow referencing other definitions in the -- specification. It can be used to reference parameters and responses -- that are defined at the top level for reuse. newtype Reference Reference :: Text -> Reference [getReference] :: Reference -> Text data Referenced a Ref :: Reference -> Referenced a Inline :: a -> Referenced a newtype MimeList MimeList :: [MediaType] -> MimeList [getMimeList] :: MimeList -> [MediaType] newtype URL URL :: Text -> URL [getUrl] :: URL -> Text