module Composite.Swagger.Base where

import Control.Lens (Unwrapped, Wrapped, (&), (?~))
import Composite.Swagger.OrphanInstances ()
import Data.Proxy (Proxy (Proxy))
import Data.Swagger
  ( Definitions, NamedSchema(NamedSchema), Schema, SwaggerType(SwaggerObject), ToSchema
  , declareSchema, type_ )
import Data.Swagger.Declare (Declare)
import qualified Data.Text as Text

-- |Given a 'Control.Lens.Wrapped' and an underlying 'Data.Swagger.ToSchema' instance, create a
-- Schema with the given name surrounding the underlying instance.
wrappedSchema :: (Wrapped wrap, ToSchema (Unwrapped wrap)) => Proxy wrap -> String -> Declare (Definitions Schema) NamedSchema
wrappedSchema :: forall wrap.
(Wrapped wrap, ToSchema (Unwrapped wrap)) =>
Proxy wrap -> String -> Declare (Definitions Schema) NamedSchema
wrappedSchema (Proxy wrap
Proxy :: Proxy wrap) String
name = do
  Schema
s <- forall a.
ToSchema a =>
Proxy a -> Declare (Definitions Schema) Schema
declareSchema (forall {k} (t :: k). Proxy t
Proxy :: Proxy (Unwrapped wrap))
  forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Maybe Text -> Schema -> NamedSchema
NamedSchema (forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
name) Schema
s
    forall a b. a -> (a -> b) -> b
& forall s a. HasType s a => Lens' s a
type_ forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ SwaggerType 'SwaggerKindSchema
SwaggerObject