{-# LANGUAGE DataKinds #-}
{-# OPTIONS_GHC -Wno-orphans #-}
module Unison.Server.Orphans where
import Control.Lens
import Data.Aeson
import Data.Aeson qualified as Aeson
import Data.Binary
import Data.ByteString.Short (ShortByteString)
import Data.List.NonEmpty (NonEmpty (..))
import Data.OpenApi
import Data.Proxy
import Data.Text qualified as Text
import Servant
import Servant.Docs (DocCapture (DocCapture), DocQueryParam (..), ParamKind (..), ToCapture (..), ToParam (..))
import U.Codebase.HashTags
import Unison.Codebase.Editor.DisplayObject
import Unison.Codebase.Path qualified as Path
import Unison.Codebase.Path.Parse qualified as Path
import Unison.Codebase.ShortCausalHash (ShortCausalHash (..))
import Unison.Codebase.ShortCausalHash qualified as SCH
import Unison.ConstructorType (ConstructorType)
import Unison.ConstructorType qualified as CT
import Unison.Core.Project (ProjectBranchName (..), ProjectName (..))
import Unison.Hash (Hash (..))
import Unison.Hash qualified as Hash
import Unison.HashQualified qualified as HQ
import Unison.HashQualifiedPrime qualified as HQ'
import Unison.Name (Name)
import Unison.Name qualified as Name
import Unison.NameSegment.Internal (NameSegment (NameSegment))
import Unison.Prelude
import Unison.Project
import Unison.Reference qualified as Reference
import Unison.Referent qualified as Referent
import Unison.ShortHash (ShortHash)
import Unison.ShortHash qualified as SH
import Unison.Syntax.HashQualified qualified as HQ (parseText)
import Unison.Syntax.HashQualifiedPrime qualified as HQ' (parseText)
import Unison.Syntax.Name qualified as Name (parseTextEither, toText)
import Unison.Syntax.NameSegment qualified as NameSegment
import Unison.Util.Pretty (Width (..))
instance ToJSON Hash where
toJSON :: Hash -> Value
toJSON Hash
h = Text -> Value
String (Text -> Value) -> Text -> Value
forall a b. (a -> b) -> a -> b
$ Hash -> Text
Hash.toBase32HexText Hash
h
instance FromJSON Hash where
parseJSON :: Value -> Parser Hash
parseJSON = String -> (Text -> Parser Hash) -> Value -> Parser Hash
forall a. String -> (Text -> Parser a) -> Value -> Parser a
Aeson.withText String
"Hash" ((Text -> Parser Hash) -> Value -> Parser Hash)
-> (Text -> Parser Hash) -> Value -> Parser Hash
forall a b. (a -> b) -> a -> b
$ Hash -> Parser Hash
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Hash -> Parser Hash) -> (Text -> Hash) -> Text -> Parser Hash
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Hash
Hash.unsafeFromBase32HexText
deriving via Hash instance ToJSON CausalHash
deriving via Hash instance FromJSON CausalHash
instance ToJSON ShortHash where
toJSON :: ShortHash -> Value
toJSON = Text -> Value
Aeson.String (Text -> Value) -> (ShortHash -> Text) -> ShortHash -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortHash -> Text
SH.toText
instance ToJSONKey ShortHash where
toJSONKey :: ToJSONKeyFunction ShortHash
toJSONKey = (ShortHash -> Text)
-> ToJSONKeyFunction Text -> ToJSONKeyFunction ShortHash
forall a' a.
(a' -> a) -> ToJSONKeyFunction a -> ToJSONKeyFunction a'
forall (f :: * -> *) a' a.
Contravariant f =>
(a' -> a) -> f a -> f a'
contramap ShortHash -> Text
SH.toText (forall a. ToJSONKey a => ToJSONKeyFunction a
toJSONKey @Text)
instance FromJSON ShortHash where
parseJSON :: Value -> Parser ShortHash
parseJSON = String -> (Text -> Parser ShortHash) -> Value -> Parser ShortHash
forall a. String -> (Text -> Parser a) -> Value -> Parser a
Aeson.withText String
"ShortHash" \Text
txt ->
case Text -> Maybe ShortHash
SH.fromText Text
txt of
Maybe ShortHash
Nothing -> String -> Parser ShortHash
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser ShortHash) -> String -> Parser ShortHash
forall a b. (a -> b) -> a -> b
$ String
"Invalid Shorthash" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Text -> String
Text.unpack Text
txt
Just ShortHash
sh -> ShortHash -> Parser ShortHash
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ShortHash
sh
instance FromJSONKey ShortHash where
fromJSONKey :: FromJSONKeyFunction ShortHash
fromJSONKey =
(Text -> Parser ShortHash) -> FromJSONKeyFunction ShortHash
forall a. (Text -> Parser a) -> FromJSONKeyFunction a
Aeson.FromJSONKeyTextParser \Text
txt ->
case Text -> Maybe ShortHash
SH.fromText Text
txt of
Maybe ShortHash
Nothing -> String -> Parser ShortHash
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser ShortHash) -> String -> Parser ShortHash
forall a b. (a -> b) -> a -> b
$ String
"Invalid Shorthash" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Text -> String
Text.unpack Text
txt
Just ShortHash
sh -> ShortHash -> Parser ShortHash
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ShortHash
sh
instance FromHttpApiData ShortCausalHash where
parseUrlPiece :: Text -> Either Text ShortCausalHash
parseUrlPiece = Either Text ShortCausalHash
-> (ShortCausalHash -> Either Text ShortCausalHash)
-> Maybe ShortCausalHash
-> Either Text ShortCausalHash
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Text -> Either Text ShortCausalHash
forall a b. a -> Either a b
Left Text
"Invalid ShortCausalHash") ShortCausalHash -> Either Text ShortCausalHash
forall a b. b -> Either a b
Right (Maybe ShortCausalHash -> Either Text ShortCausalHash)
-> (Text -> Maybe ShortCausalHash)
-> Text
-> Either Text ShortCausalHash
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Maybe ShortCausalHash
SCH.fromText
instance ToHttpApiData ShortHash where
toQueryParam :: ShortHash -> Text
toQueryParam = ShortHash -> Text
SH.toText
instance FromHttpApiData ShortHash where
parseUrlPiece :: Text -> Either Text ShortHash
parseUrlPiece Text
txt =
HasCallStack => Text -> Text -> Text -> Text
Text -> Text -> Text -> Text
Text.replace Text
"@" Text
"#" Text
txt
Text -> (Text -> Either Text ShortHash) -> Either Text ShortHash
forall a b. a -> (a -> b) -> b
& \Text
t ->
( if Text -> Text -> Bool
Text.isPrefixOf Text
"#" Text
t
then Text
t
else (Text
"#" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
t)
)
Text -> (Text -> Maybe ShortHash) -> Maybe ShortHash
forall a b. a -> (a -> b) -> b
& Text -> Maybe ShortHash
SH.fromText
Maybe ShortHash
-> (Maybe ShortHash -> Either Text ShortHash)
-> Either Text ShortHash
forall a b. a -> (a -> b) -> b
& Either Text ShortHash
-> (ShortHash -> Either Text ShortHash)
-> Maybe ShortHash
-> Either Text ShortHash
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Text -> Either Text ShortHash
forall a b. a -> Either a b
Left Text
"Invalid ShortCausalHash") ShortHash -> Either Text ShortHash
forall a b. b -> Either a b
Right
instance ToSchema ShortHash where
declareNamedSchema :: Proxy ShortHash -> Declare (Definitions Schema) NamedSchema
declareNamedSchema Proxy ShortHash
_ = Proxy Text -> Declare (Definitions Schema) NamedSchema
forall a.
ToSchema a =>
Proxy a -> Declare (Definitions Schema) NamedSchema
declareNamedSchema (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @Text)
instance ToHttpApiData Reference.Reference where
toQueryParam :: Reference -> Text
toQueryParam = Reference -> Text
Reference.toText
instance ToHttpApiData Referent.Referent where
toQueryParam :: Referent -> Text
toQueryParam = Referent -> Text
Referent.toText
instance FromHttpApiData Reference.Reference where
parseUrlPiece :: Text -> Either Text Reference
parseUrlPiece Text
txt =
HasCallStack => Text -> Text -> Text -> Text
Text -> Text -> Text -> Text
Text.replace Text
"@" Text
"#" Text
txt
Text -> (Text -> Either Text Reference) -> Either Text Reference
forall a b. a -> (a -> b) -> b
& \Text
t ->
( if Text -> Text -> Bool
Text.isPrefixOf Text
"#" Text
t
then Text
t
else (Text
"#" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
t)
)
Text
-> (Text -> Either String Reference) -> Either String Reference
forall a b. a -> (a -> b) -> b
& Text -> Either String Reference
Reference.fromText
Either String Reference
-> (Either String Reference -> Either Text Reference)
-> Either Text Reference
forall a b. a -> (a -> b) -> b
& (String -> Text)
-> Either String Reference -> Either Text Reference
forall a c b. (a -> c) -> Either a b -> Either c b
mapLeft String -> Text
Text.pack
instance FromHttpApiData Referent.Referent where
parseUrlPiece :: Text -> Either Text Referent
parseUrlPiece Text
txt =
HasCallStack => Text -> Text -> Text -> Text
Text -> Text -> Text -> Text
Text.replace Text
"@" Text
"#" Text
txt
Text -> (Text -> Either Text Referent) -> Either Text Referent
forall a b. a -> (a -> b) -> b
& \Text
t ->
( if Text -> Text -> Bool
Text.isPrefixOf Text
"#" Text
t
then Text
t
else (Text
"#" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
t)
)
Text -> (Text -> Maybe Referent) -> Maybe Referent
forall a b. a -> (a -> b) -> b
& Text -> Maybe Referent
Referent.fromText
Maybe Referent
-> (Maybe Referent -> Either Text Referent) -> Either Text Referent
forall a b. a -> (a -> b) -> b
& Either Text Referent
-> (Referent -> Either Text Referent)
-> Maybe Referent
-> Either Text Referent
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Text -> Either Text Referent
forall a b. a -> Either a b
Left Text
"Invalid Referent") Referent -> Either Text Referent
forall a b. b -> Either a b
Right
instance ToSchema Reference where
declareNamedSchema :: Proxy Reference -> Declare (Definitions Schema) NamedSchema
declareNamedSchema Proxy Reference
_ = Proxy Text -> Declare (Definitions Schema) NamedSchema
forall a.
ToSchema a =>
Proxy a -> Declare (Definitions Schema) NamedSchema
declareNamedSchema (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @Text)
deriving via ShortByteString instance Binary Hash
deriving via Hash instance Binary CausalHash
deriving via Text instance ToHttpApiData ShortCausalHash
instance (ToJSON b, ToJSON a) => ToJSON (DisplayObject b a) where
toJSON :: DisplayObject b a -> Value
toJSON = \case
BuiltinObject b
b -> [Pair] -> Value
object [Key
"tag" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
Aeson..= Text -> Value
String Text
"BuiltinObject", Key
"contents" Key -> b -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
Aeson..= b
b]
MissingObject ShortHash
sh -> [Pair] -> Value
object [Key
"tag" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
Aeson..= Text -> Value
String Text
"MissingObject", Key
"contents" Key -> ShortHash -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
Aeson..= ShortHash
sh]
UserObject a
a -> [Pair] -> Value
object [Key
"tag" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
Aeson..= Text -> Value
String Text
"UserObject", Key
"contents" Key -> a -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
Aeson..= a
a]
instance (FromJSON a, FromJSON b) => FromJSON (DisplayObject b a) where
parseJSON :: Value -> Parser (DisplayObject b a)
parseJSON = String
-> (Object -> Parser (DisplayObject b a))
-> Value
-> Parser (DisplayObject b a)
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"DisplayObject" \Object
o -> do
Text
tag <- Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"tag"
case Text
tag of
Text
"BuiltinObject" -> b -> DisplayObject b a
forall b a. b -> DisplayObject b a
BuiltinObject (b -> DisplayObject b a) -> Parser b -> Parser (DisplayObject b a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser b
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"contents"
Text
"MissingObject" -> ShortHash -> DisplayObject b a
forall b a. ShortHash -> DisplayObject b a
MissingObject (ShortHash -> DisplayObject b a)
-> Parser ShortHash -> Parser (DisplayObject b a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser ShortHash
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"contents"
Text
"UserObject" -> a -> DisplayObject b a
forall b a. a -> DisplayObject b a
UserObject (a -> DisplayObject b a) -> Parser a -> Parser (DisplayObject b a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser a
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"contents"
Text
_ -> String -> Parser (DisplayObject b a)
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser (DisplayObject b a))
-> String -> Parser (DisplayObject b a)
forall a b. (a -> b) -> a -> b
$ String
"Invalid tag: " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Text -> String
Text.unpack Text
tag
deriving instance (ToSchema b, ToSchema a) => ToSchema (DisplayObject b a)
instance ToJSON Name where
toEncoding :: Name -> Encoding
toEncoding = Text -> Encoding
forall a. ToJSON a => a -> Encoding
toEncoding (Text -> Encoding) -> (Name -> Text) -> Name -> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name -> Text
Name.toText
toJSON :: Name -> Value
toJSON = Text -> Value
forall a. ToJSON a => a -> Value
toJSON (Text -> Value) -> (Name -> Text) -> Name -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name -> Text
Name.toText
instance ToJSONKey Name where
toJSONKey :: ToJSONKeyFunction Name
toJSONKey = (Name -> Text) -> ToJSONKeyFunction Text -> ToJSONKeyFunction Name
forall a' a.
(a' -> a) -> ToJSONKeyFunction a -> ToJSONKeyFunction a'
forall (f :: * -> *) a' a.
Contravariant f =>
(a' -> a) -> f a -> f a'
contramap Name -> Text
Name.toText (forall a. ToJSONKey a => ToJSONKeyFunction a
toJSONKey @Text)
instance ToSchema Name where
declareNamedSchema :: Proxy Name -> Declare (Definitions Schema) NamedSchema
declareNamedSchema Proxy Name
_ = Proxy Text -> Declare (Definitions Schema) NamedSchema
forall a.
ToSchema a =>
Proxy a -> Declare (Definitions Schema) NamedSchema
declareNamedSchema (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @Text)
instance ToJSON NameSegment where
toJSON :: NameSegment -> Value
toJSON = Text -> Value
forall a. ToJSON a => a -> Value
toJSON (Text -> Value) -> (NameSegment -> Text) -> NameSegment -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NameSegment -> Text
NameSegment.toEscapedText
instance ToJSONKey NameSegment where
toJSONKey :: ToJSONKeyFunction NameSegment
toJSONKey = (NameSegment -> Text)
-> ToJSONKeyFunction Text -> ToJSONKeyFunction NameSegment
forall a' a.
(a' -> a) -> ToJSONKeyFunction a -> ToJSONKeyFunction a'
forall (f :: * -> *) a' a.
Contravariant f =>
(a' -> a) -> f a -> f a'
contramap NameSegment -> Text
NameSegment.toEscapedText (forall a. ToJSONKey a => ToJSONKeyFunction a
toJSONKey @Text)
deriving anyclass instance ToParamSchema ShortCausalHash
instance ToParamSchema ShortHash where
toParamSchema :: Proxy ShortHash -> Schema
toParamSchema Proxy ShortHash
_ =
Schema
forall a. Monoid a => a
mempty
Schema -> (Schema -> Schema) -> Schema
forall a b. a -> (a -> b) -> b
& (Maybe OpenApiType -> Identity (Maybe OpenApiType))
-> Schema -> Identity Schema
forall s a. HasType s a => Lens' s a
Lens' Schema (Maybe OpenApiType)
type_ ((Maybe OpenApiType -> Identity (Maybe OpenApiType))
-> Schema -> Identity Schema)
-> OpenApiType -> Schema -> Schema
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ OpenApiType
OpenApiString
Schema -> (Schema -> Schema) -> Schema
forall a b. a -> (a -> b) -> b
& (Maybe Value -> Identity (Maybe Value))
-> Schema -> Identity Schema
forall s a. HasExample s a => Lens' s a
Lens' Schema (Maybe Value)
example ((Maybe Value -> Identity (Maybe Value))
-> Schema -> Identity Schema)
-> Value -> Schema -> Schema
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ Text -> Value
Aeson.String Text
"@abcdef"
instance ToParamSchema Reference.Reference where
toParamSchema :: Proxy Reference -> Schema
toParamSchema Proxy Reference
_ =
Schema
forall a. Monoid a => a
mempty
Schema -> (Schema -> Schema) -> Schema
forall a b. a -> (a -> b) -> b
& (Maybe OpenApiType -> Identity (Maybe OpenApiType))
-> Schema -> Identity Schema
forall s a. HasType s a => Lens' s a
Lens' Schema (Maybe OpenApiType)
type_ ((Maybe OpenApiType -> Identity (Maybe OpenApiType))
-> Schema -> Identity Schema)
-> OpenApiType -> Schema -> Schema
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ OpenApiType
OpenApiString
Schema -> (Schema -> Schema) -> Schema
forall a b. a -> (a -> b) -> b
& (Maybe Value -> Identity (Maybe Value))
-> Schema -> Identity Schema
forall s a. HasExample s a => Lens' s a
Lens' Schema (Maybe Value)
example ((Maybe Value -> Identity (Maybe Value))
-> Schema -> Identity Schema)
-> Value -> Schema -> Schema
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ Text -> Value
Aeson.String Text
"@abcdef"
instance ToParamSchema Referent.Referent where
toParamSchema :: Proxy Referent -> Schema
toParamSchema Proxy Referent
_ =
Schema
forall a. Monoid a => a
mempty
Schema -> (Schema -> Schema) -> Schema
forall a b. a -> (a -> b) -> b
& (Maybe OpenApiType -> Identity (Maybe OpenApiType))
-> Schema -> Identity Schema
forall s a. HasType s a => Lens' s a
Lens' Schema (Maybe OpenApiType)
type_ ((Maybe OpenApiType -> Identity (Maybe OpenApiType))
-> Schema -> Identity Schema)
-> OpenApiType -> Schema -> Schema
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ OpenApiType
OpenApiString
Schema -> (Schema -> Schema) -> Schema
forall a b. a -> (a -> b) -> b
& (Maybe Value -> Identity (Maybe Value))
-> Schema -> Identity Schema
forall s a. HasExample s a => Lens' s a
Lens' Schema (Maybe Value)
example ((Maybe Value -> Identity (Maybe Value))
-> Schema -> Identity Schema)
-> Value -> Schema -> Schema
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ Text -> Value
Aeson.String Text
"@abcdef"
instance ToParamSchema Name where
toParamSchema :: Proxy Name -> Schema
toParamSchema Proxy Name
_ =
Schema
forall a. Monoid a => a
mempty
Schema -> (Schema -> Schema) -> Schema
forall a b. a -> (a -> b) -> b
& (Maybe OpenApiType -> Identity (Maybe OpenApiType))
-> Schema -> Identity Schema
forall s a. HasType s a => Lens' s a
Lens' Schema (Maybe OpenApiType)
type_ ((Maybe OpenApiType -> Identity (Maybe OpenApiType))
-> Schema -> Identity Schema)
-> OpenApiType -> Schema -> Schema
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ OpenApiType
OpenApiString
Schema -> (Schema -> Schema) -> Schema
forall a b. a -> (a -> b) -> b
& (Maybe Value -> Identity (Maybe Value))
-> Schema -> Identity Schema
forall s a. HasExample s a => Lens' s a
Lens' Schema (Maybe Value)
example ((Maybe Value -> Identity (Maybe Value))
-> Schema -> Identity Schema)
-> Value -> Schema -> Schema
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ Text -> Value
Aeson.String Text
"base.List.map"
instance ToParamSchema Path.Path where
toParamSchema :: Proxy Path -> Schema
toParamSchema Proxy Path
_ =
Schema
forall a. Monoid a => a
mempty
Schema -> (Schema -> Schema) -> Schema
forall a b. a -> (a -> b) -> b
& (Maybe OpenApiType -> Identity (Maybe OpenApiType))
-> Schema -> Identity Schema
forall s a. HasType s a => Lens' s a
Lens' Schema (Maybe OpenApiType)
type_ ((Maybe OpenApiType -> Identity (Maybe OpenApiType))
-> Schema -> Identity Schema)
-> OpenApiType -> Schema -> Schema
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ OpenApiType
OpenApiString
Schema -> (Schema -> Schema) -> Schema
forall a b. a -> (a -> b) -> b
& (Maybe Value -> Identity (Maybe Value))
-> Schema -> Identity Schema
forall s a. HasExample s a => Lens' s a
Lens' Schema (Maybe Value)
example ((Maybe Value -> Identity (Maybe Value))
-> Schema -> Identity Schema)
-> Value -> Schema -> Schema
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ Text -> Value
Aeson.String Text
"base.List"
instance ToParamSchema Path.Relative where
toParamSchema :: Proxy Relative -> Schema
toParamSchema Proxy Relative
_ =
Schema
forall a. Monoid a => a
mempty
Schema -> (Schema -> Schema) -> Schema
forall a b. a -> (a -> b) -> b
& (Maybe OpenApiType -> Identity (Maybe OpenApiType))
-> Schema -> Identity Schema
forall s a. HasType s a => Lens' s a
Lens' Schema (Maybe OpenApiType)
type_ ((Maybe OpenApiType -> Identity (Maybe OpenApiType))
-> Schema -> Identity Schema)
-> OpenApiType -> Schema -> Schema
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ OpenApiType
OpenApiString
Schema -> (Schema -> Schema) -> Schema
forall a b. a -> (a -> b) -> b
& (Maybe Value -> Identity (Maybe Value))
-> Schema -> Identity Schema
forall s a. HasExample s a => Lens' s a
Lens' Schema (Maybe Value)
example ((Maybe Value -> Identity (Maybe Value))
-> Schema -> Identity Schema)
-> Value -> Schema -> Schema
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ Text -> Value
Aeson.String Text
"base.List"
instance ToParam (QueryParam "name" Name) where
toParam :: Proxy (QueryParam "name" Name) -> DocQueryParam
toParam Proxy (QueryParam "name" Name)
_ =
String -> [String] -> String -> ParamKind -> DocQueryParam
DocQueryParam
String
"name"
[]
String
"A definition name. See API documentation to determine how it should be qualified."
ParamKind
Normal
instance FromHttpApiData Name where
parseQueryParam :: Text -> Either Text Name
parseQueryParam = Text -> Either Text Name
Name.parseTextEither
deriving via Int instance FromHttpApiData Width
deriving via Int instance ToHttpApiData Width
deriving anyclass instance ToParamSchema Width
instance ToJSON ConstructorType where
toJSON :: ConstructorType -> Value
toJSON = \case
ConstructorType
CT.Data -> Text -> Value
String Text
"Data"
ConstructorType
CT.Effect -> Text -> Value
String Text
"Effect"
instance FromHttpApiData Path.Relative where
parseUrlPiece :: Text -> Either Text Relative
parseUrlPiece Text
txt = case String -> Either Text Path'
Path.parsePath' (Text -> String
Text.unpack Text
txt) of
Left Text
s -> Text -> Either Text Relative
forall a b. a -> Either a b
Left Text
s
Right (Path.RelativePath' Relative
p) -> Relative -> Either Text Relative
forall a b. b -> Either a b
Right Relative
p
Right (Path.AbsolutePath' Absolute
_) -> Text -> Either Text Relative
forall a b. a -> Either a b
Left (Text -> Either Text Relative) -> Text -> Either Text Relative
forall a b. (a -> b) -> a -> b
$ Text
"Expected relative path, but " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
txt Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" was absolute."
instance ToHttpApiData Path.Relative where
toUrlPiece :: Relative -> Text
toUrlPiece = Relative -> Text
forall a. Show a => a -> Text
tShow
instance FromHttpApiData Path.Absolute where
parseUrlPiece :: Text -> Either Text Absolute
parseUrlPiece Text
txt = case String -> Either Text Path'
Path.parsePath' (Text -> String
Text.unpack Text
txt) of
Left Text
s -> Text -> Either Text Absolute
forall a b. a -> Either a b
Left Text
s
Right (Path.RelativePath' Relative
_) -> Text -> Either Text Absolute
forall a b. a -> Either a b
Left (Text -> Either Text Absolute) -> Text -> Either Text Absolute
forall a b. (a -> b) -> a -> b
$ Text
"Expected absolute path, but " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
txt Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" was relative."
Right (Path.AbsolutePath' Absolute
p) -> Absolute -> Either Text Absolute
forall a b. b -> Either a b
Right Absolute
p
instance ToHttpApiData Path.Absolute where
toUrlPiece :: Absolute -> Text
toUrlPiece = Absolute -> Text
forall a. Show a => a -> Text
tShow
instance FromHttpApiData Path.Path' where
parseUrlPiece :: Text -> Either Text Path'
parseUrlPiece Text
txt = String -> Either Text Path'
Path.parsePath' (Text -> String
Text.unpack Text
txt)
instance ToHttpApiData Path.Path' where
toUrlPiece :: Path' -> Text
toUrlPiece = Path' -> Text
forall a. Show a => a -> Text
tShow
instance FromHttpApiData Path.Path where
parseUrlPiece :: Text -> Either Text Path
parseUrlPiece Text
txt = case String -> Either Text Path'
Path.parsePath' (Text -> String
Text.unpack Text
txt) of
Left Text
s -> Text -> Either Text Path
forall a b. a -> Either a b
Left Text
s
Right (Path.RelativePath' Relative
p) -> Path -> Either Text Path
forall a b. b -> Either a b
Right (Relative -> Path
Path.unrelative Relative
p)
Right (Path.AbsolutePath' Absolute
_) -> Text -> Either Text Path
forall a b. a -> Either a b
Left (Text -> Either Text Path) -> Text -> Either Text Path
forall a b. (a -> b) -> a -> b
$ Text
"Expected relative path, but " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
txt Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" was absolute."
instance ToCapture (Capture "hash" ShortHash) where
toCapture :: Proxy (Capture "hash" ShortHash) -> DocCapture
toCapture Proxy (Capture "hash" ShortHash)
_ =
String -> String -> DocCapture
DocCapture
String
"hash"
String
"A shorthash for a term or type. E.g. @abcdef, #abcdef, @@builtin, ##builtin, abcdef"
instance ToCapture (Capture "hash" Reference.Reference) where
toCapture :: Proxy (Capture "hash" Reference) -> DocCapture
toCapture Proxy (Capture "hash" Reference)
_ =
String -> String -> DocCapture
DocCapture
String
"hash"
String
"A hash reference for a type. E.g. @abcdef, #abcdef, @@builtin, ##builtin, abcdef"
instance ToCapture (Capture "hash" Referent.Referent) where
toCapture :: Proxy (Capture "hash" Referent) -> DocCapture
toCapture Proxy (Capture "hash" Referent)
_ =
String -> String -> DocCapture
DocCapture
String
"hash"
String
"A hash reference for a term. E.g. @abcdef, #abcdef, @@builtin, ##builtin, abcdef"
instance ToCapture (Capture "fqn" Name) where
toCapture :: Proxy (Capture "fqn" Name) -> DocCapture
toCapture Proxy (Capture "fqn" Name)
_ =
String -> String -> DocCapture
DocCapture
String
"fqn"
String
"The fully qualified name of a definition."
instance ToCapture (Capture "namespace" Path.Path) where
toCapture :: Proxy (Capture "namespace" Path) -> DocCapture
toCapture Proxy (Capture "namespace" Path)
_ =
String -> String -> DocCapture
DocCapture
String
"namespace"
String
"E.g. base.List"
instance ToJSON Path.Path where
toJSON :: Path -> Value
toJSON Path
p = Text -> Value
Aeson.String (Path -> Text
forall a. Show a => a -> Text
tShow Path
p)
instance ToJSON Path.Absolute where
toJSON :: Absolute -> Value
toJSON Absolute
p = Text -> Value
Aeson.String (Absolute -> Text
forall a. Show a => a -> Text
tShow Absolute
p)
instance ToSchema Path.Path where
declareNamedSchema :: Proxy Path -> Declare (Definitions Schema) NamedSchema
declareNamedSchema Proxy Path
_ = Proxy Text -> Declare (Definitions Schema) NamedSchema
forall a.
ToSchema a =>
Proxy a -> Declare (Definitions Schema) NamedSchema
declareNamedSchema (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @Text)
instance ToSchema Path.Absolute where
declareNamedSchema :: Proxy Absolute -> Declare (Definitions Schema) NamedSchema
declareNamedSchema Proxy Absolute
_ = Proxy Text -> Declare (Definitions Schema) NamedSchema
forall a.
ToSchema a =>
Proxy a -> Declare (Definitions Schema) NamedSchema
declareNamedSchema (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @Text)
instance ToJSON (HQ.HashQualified Name) where
toJSON :: HashQualified Name -> Value
toJSON = Text -> Value
Aeson.String (Text -> Value)
-> (HashQualified Name -> Text) -> HashQualified Name -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Name -> Text) -> HashQualified Name -> Text
forall n. (n -> Text) -> HashQualified n -> Text
HQ.toTextWith Name -> Text
Name.toText
instance ToJSON (HQ.HashQualified NameSegment) where
toJSON :: HashQualified NameSegment -> Value
toJSON = Text -> Value
Aeson.String (Text -> Value)
-> (HashQualified NameSegment -> Text)
-> HashQualified NameSegment
-> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (NameSegment -> Text) -> HashQualified NameSegment -> Text
forall n. (n -> Text) -> HashQualified n -> Text
HQ.toTextWith NameSegment -> Text
NameSegment.toEscapedText
instance ToJSON (HQ'.HashQualified Name) where
toJSON :: HashQualified Name -> Value
toJSON = Text -> Value
Aeson.String (Text -> Value)
-> (HashQualified Name -> Text) -> HashQualified Name -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Name -> Text) -> HashQualified Name -> Text
forall n. (n -> Text) -> HashQualified n -> Text
HQ'.toTextWith Name -> Text
Name.toText
instance ToJSON (HQ'.HashQualified NameSegment) where
toJSON :: HashQualified NameSegment -> Value
toJSON = Text -> Value
Aeson.String (Text -> Value)
-> (HashQualified NameSegment -> Text)
-> HashQualified NameSegment
-> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (NameSegment -> Text) -> HashQualified NameSegment -> Text
forall n. (n -> Text) -> HashQualified n -> Text
HQ'.toTextWith NameSegment -> Text
NameSegment.toEscapedText
instance FromJSON (HQ'.HashQualified Name) where
parseJSON :: Value -> Parser (HashQualified Name)
parseJSON = String
-> (Text -> Parser (HashQualified Name))
-> Value
-> Parser (HashQualified Name)
forall a. String -> (Text -> Parser a) -> Value -> Parser a
Aeson.withText String
"HashQualified'" \Text
txt ->
Parser (HashQualified Name)
-> (HashQualified Name -> Parser (HashQualified Name))
-> Maybe (HashQualified Name)
-> Parser (HashQualified Name)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (String -> Parser (HashQualified Name)
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Invalid HashQualified' Name") HashQualified Name -> Parser (HashQualified Name)
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe (HashQualified Name) -> Parser (HashQualified Name))
-> Maybe (HashQualified Name) -> Parser (HashQualified Name)
forall a b. (a -> b) -> a -> b
$ Text -> Maybe (HashQualified Name)
HQ'.parseText Text
txt
instance FromJSON (HQ.HashQualified Name) where
parseJSON :: Value -> Parser (HashQualified Name)
parseJSON = String
-> (Text -> Parser (HashQualified Name))
-> Value
-> Parser (HashQualified Name)
forall a. String -> (Text -> Parser a) -> Value -> Parser a
Aeson.withText String
"HashQualified" \Text
txt ->
Parser (HashQualified Name)
-> (HashQualified Name -> Parser (HashQualified Name))
-> Maybe (HashQualified Name)
-> Parser (HashQualified Name)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (String -> Parser (HashQualified Name)
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Invalid HashQualified Name") HashQualified Name -> Parser (HashQualified Name)
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe (HashQualified Name) -> Parser (HashQualified Name))
-> Maybe (HashQualified Name) -> Parser (HashQualified Name)
forall a b. (a -> b) -> a -> b
$ Text -> Maybe (HashQualified Name)
HQ.parseText Text
txt
instance FromJSON (HQ'.HashQualified NameSegment) where
parseJSON :: Value -> Parser (HashQualified NameSegment)
parseJSON = String
-> (Text -> Parser (HashQualified NameSegment))
-> Value
-> Parser (HashQualified NameSegment)
forall a. String -> (Text -> Parser a) -> Value -> Parser a
Aeson.withText String
"HashQualified'" \Text
txt -> do
HashQualified Name
hqName <- Parser (HashQualified Name)
-> (HashQualified Name -> Parser (HashQualified Name))
-> Maybe (HashQualified Name)
-> Parser (HashQualified Name)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (String -> Parser (HashQualified Name)
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Invalid HashQualified' NameSegment") HashQualified Name -> Parser (HashQualified Name)
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe (HashQualified Name) -> Parser (HashQualified Name))
-> Maybe (HashQualified Name) -> Parser (HashQualified Name)
forall a b. (a -> b) -> a -> b
$ Text -> Maybe (HashQualified Name)
HQ'.parseText Text
txt
HashQualified Name
-> (Name -> Parser NameSegment)
-> Parser (HashQualified NameSegment)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
t a -> (a -> f b) -> f (t b)
for HashQualified Name
hqName \Name
name -> case Name -> NonEmpty NameSegment
Name.segments Name
name of
(NameSegment
ns :| []) -> NameSegment -> Parser NameSegment
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure NameSegment
ns
NonEmpty NameSegment
_ -> String -> Parser NameSegment
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser NameSegment) -> String -> Parser NameSegment
forall a b. (a -> b) -> a -> b
$ String
"Expected a single name segment but received several: " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Text -> String
Text.unpack Text
txt
instance FromJSON (HQ.HashQualified NameSegment) where
parseJSON :: Value -> Parser (HashQualified NameSegment)
parseJSON = String
-> (Text -> Parser (HashQualified NameSegment))
-> Value
-> Parser (HashQualified NameSegment)
forall a. String -> (Text -> Parser a) -> Value -> Parser a
Aeson.withText String
"HashQualified" \Text
txt -> do
HashQualified Name
hqName <- Parser (HashQualified Name)
-> (HashQualified Name -> Parser (HashQualified Name))
-> Maybe (HashQualified Name)
-> Parser (HashQualified Name)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (String -> Parser (HashQualified Name)
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Invalid HashQualified' NameSegment") HashQualified Name -> Parser (HashQualified Name)
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe (HashQualified Name) -> Parser (HashQualified Name))
-> Maybe (HashQualified Name) -> Parser (HashQualified Name)
forall a b. (a -> b) -> a -> b
$ Text -> Maybe (HashQualified Name)
HQ.parseText Text
txt
HashQualified Name
-> (Name -> Parser NameSegment)
-> Parser (HashQualified NameSegment)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
t a -> (a -> f b) -> f (t b)
for HashQualified Name
hqName \Name
name -> case Name -> NonEmpty NameSegment
Name.segments Name
name of
(NameSegment
ns :| []) -> NameSegment -> Parser NameSegment
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure NameSegment
ns
NonEmpty NameSegment
_ -> String -> Parser NameSegment
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser NameSegment) -> String -> Parser NameSegment
forall a b. (a -> b) -> a -> b
$ String
"Expected a single name segment but received several: " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Text -> String
Text.unpack Text
txt
instance FromHttpApiData (HQ.HashQualified Name) where
parseQueryParam :: Text -> Either Text (HashQualified Name)
parseQueryParam Text
txt =
HasCallStack => Text -> Text -> Text -> Text
Text -> Text -> Text -> Text
Text.replace Text
"@" Text
"#" Text
txt
Text
-> (Text -> Maybe (HashQualified Name))
-> Maybe (HashQualified Name)
forall a b. a -> (a -> b) -> b
& Text -> Maybe (HashQualified Name)
HQ.parseText
Maybe (HashQualified Name)
-> (Maybe (HashQualified Name) -> Either Text (HashQualified Name))
-> Either Text (HashQualified Name)
forall a b. a -> (a -> b) -> b
& Either Text (HashQualified Name)
-> (HashQualified Name -> Either Text (HashQualified Name))
-> Maybe (HashQualified Name)
-> Either Text (HashQualified Name)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Text -> Either Text (HashQualified Name)
forall a b. a -> Either a b
Left Text
"Invalid Hash Qualified Name. Expected one of the following forms: name@hash, name, @hash") HashQualified Name -> Either Text (HashQualified Name)
forall a b. b -> Either a b
Right
instance FromHttpApiData (HQ'.HashQualified Name) where
parseQueryParam :: Text -> Either Text (HashQualified Name)
parseQueryParam Text
txt =
HasCallStack => Text -> Text -> Text -> Text
Text -> Text -> Text -> Text
Text.replace Text
"@" Text
"#" Text
txt
Text
-> (Text -> Maybe (HashQualified Name))
-> Maybe (HashQualified Name)
forall a b. a -> (a -> b) -> b
& Text -> Maybe (HashQualified Name)
HQ'.parseText
Maybe (HashQualified Name)
-> (Maybe (HashQualified Name) -> Either Text (HashQualified Name))
-> Either Text (HashQualified Name)
forall a b. a -> (a -> b) -> b
& Either Text (HashQualified Name)
-> (HashQualified Name -> Either Text (HashQualified Name))
-> Maybe (HashQualified Name)
-> Either Text (HashQualified Name)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Text -> Either Text (HashQualified Name)
forall a b. a -> Either a b
Left Text
"Invalid Hash Qualified Name. Expected one of the following forms: name@hash, name") HashQualified Name -> Either Text (HashQualified Name)
forall a b. b -> Either a b
Right
instance ToParamSchema (HQ.HashQualified n) where
toParamSchema :: Proxy (HashQualified n) -> Schema
toParamSchema Proxy (HashQualified n)
_ =
Schema
forall a. Monoid a => a
mempty
Schema -> (Schema -> Schema) -> Schema
forall a b. a -> (a -> b) -> b
& (Maybe OpenApiType -> Identity (Maybe OpenApiType))
-> Schema -> Identity Schema
forall s a. HasType s a => Lens' s a
Lens' Schema (Maybe OpenApiType)
type_ ((Maybe OpenApiType -> Identity (Maybe OpenApiType))
-> Schema -> Identity Schema)
-> OpenApiType -> Schema -> Schema
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ OpenApiType
OpenApiString
Schema -> (Schema -> Schema) -> Schema
forall a b. a -> (a -> b) -> b
& (Maybe Value -> Identity (Maybe Value))
-> Schema -> Identity Schema
forall s a. HasExample s a => Lens' s a
Lens' Schema (Maybe Value)
example ((Maybe Value -> Identity (Maybe Value))
-> Schema -> Identity Schema)
-> Value -> Schema -> Schema
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ Text -> Value
Aeson.String Text
"name@hash"
instance ToParamSchema (HQ'.HashQualified n) where
toParamSchema :: Proxy (HashQualified n) -> Schema
toParamSchema Proxy (HashQualified n)
_ =
Schema
forall a. Monoid a => a
mempty
Schema -> (Schema -> Schema) -> Schema
forall a b. a -> (a -> b) -> b
& (Maybe OpenApiType -> Identity (Maybe OpenApiType))
-> Schema -> Identity Schema
forall s a. HasType s a => Lens' s a
Lens' Schema (Maybe OpenApiType)
type_ ((Maybe OpenApiType -> Identity (Maybe OpenApiType))
-> Schema -> Identity Schema)
-> OpenApiType -> Schema -> Schema
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ OpenApiType
OpenApiString
Schema -> (Schema -> Schema) -> Schema
forall a b. a -> (a -> b) -> b
& (Maybe Value -> Identity (Maybe Value))
-> Schema -> Identity Schema
forall s a. HasExample s a => Lens' s a
Lens' Schema (Maybe Value)
example ((Maybe Value -> Identity (Maybe Value))
-> Schema -> Identity Schema)
-> Value -> Schema -> Schema
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ Text -> Value
Aeson.String Text
"name@hash"
instance ToHttpApiData Name where
toQueryParam :: Name -> Text
toQueryParam = Name -> Text
Name.toText
deriving newtype instance ToSchema NameSegment
deriving anyclass instance (ToSchema n) => ToSchema (HQ.HashQualified n)
deriving anyclass instance (ToSchema n) => ToSchema (HQ'.HashQualified n)
instance FromHttpApiData ProjectName where
parseQueryParam :: Text -> Either Text ProjectName
parseQueryParam = (TryFromException Text ProjectName -> Text)
-> Either (TryFromException Text ProjectName) ProjectName
-> Either Text ProjectName
forall a c b. (a -> c) -> Either a b -> Either c b
mapLeft TryFromException Text ProjectName -> Text
forall a. Show a => a -> Text
tShow (Either (TryFromException Text ProjectName) ProjectName
-> Either Text ProjectName)
-> (Text -> Either (TryFromException Text ProjectName) ProjectName)
-> Text
-> Either Text ProjectName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall target source.
TryFrom source target =>
source -> Either (TryFromException source target) target
tryInto @ProjectName
instance ToParamSchema ProjectName where
toParamSchema :: Proxy ProjectName -> Schema
toParamSchema Proxy ProjectName
_ =
Schema
forall a. Monoid a => a
mempty
Schema -> (Schema -> Schema) -> Schema
forall a b. a -> (a -> b) -> b
& (Maybe OpenApiType -> Identity (Maybe OpenApiType))
-> Schema -> Identity Schema
forall s a. HasType s a => Lens' s a
Lens' Schema (Maybe OpenApiType)
type_ ((Maybe OpenApiType -> Identity (Maybe OpenApiType))
-> Schema -> Identity Schema)
-> OpenApiType -> Schema -> Schema
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ OpenApiType
OpenApiString
Schema -> (Schema -> Schema) -> Schema
forall a b. a -> (a -> b) -> b
& (Maybe Value -> Identity (Maybe Value))
-> Schema -> Identity Schema
forall s a. HasExample s a => Lens' s a
Lens' Schema (Maybe Value)
example ((Maybe Value -> Identity (Maybe Value))
-> Schema -> Identity Schema)
-> Value -> Schema -> Schema
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ Text -> Value
Aeson.String Text
"[@handle/]name"
instance ToCapture (Capture "project-name" ProjectName) where
toCapture :: Proxy (Capture "project-name" ProjectName) -> DocCapture
toCapture Proxy (Capture "project-name" ProjectName)
_ =
String -> String -> DocCapture
DocCapture
String
"project-name"
String
"The name of a project. E.g. @handle/slug"
instance ToSchema ProjectName
deriving via Text instance ToJSON ProjectName
instance FromHttpApiData ProjectBranchName where
parseQueryParam :: Text -> Either Text ProjectBranchName
parseQueryParam = (TryFromException Text ProjectBranchName -> Text)
-> Either
(TryFromException Text ProjectBranchName) ProjectBranchName
-> Either Text ProjectBranchName
forall a c b. (a -> c) -> Either a b -> Either c b
mapLeft TryFromException Text ProjectBranchName -> Text
forall a. Show a => a -> Text
tShow (Either (TryFromException Text ProjectBranchName) ProjectBranchName
-> Either Text ProjectBranchName)
-> (Text
-> Either
(TryFromException Text ProjectBranchName) ProjectBranchName)
-> Text
-> Either Text ProjectBranchName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall target source.
TryFrom source target =>
source -> Either (TryFromException source target) target
tryInto @ProjectBranchName
instance ToSchema ProjectBranchName
instance ToParamSchema ProjectBranchName where
toParamSchema :: Proxy ProjectBranchName -> Schema
toParamSchema Proxy ProjectBranchName
_ =
Schema
forall a. Monoid a => a
mempty
Schema -> (Schema -> Schema) -> Schema
forall a b. a -> (a -> b) -> b
& (Maybe OpenApiType -> Identity (Maybe OpenApiType))
-> Schema -> Identity Schema
forall s a. HasType s a => Lens' s a
Lens' Schema (Maybe OpenApiType)
type_ ((Maybe OpenApiType -> Identity (Maybe OpenApiType))
-> Schema -> Identity Schema)
-> OpenApiType -> Schema -> Schema
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ OpenApiType
OpenApiString
Schema -> (Schema -> Schema) -> Schema
forall a b. a -> (a -> b) -> b
& (Maybe Value -> Identity (Maybe Value))
-> Schema -> Identity Schema
forall s a. HasExample s a => Lens' s a
Lens' Schema (Maybe Value)
example ((Maybe Value -> Identity (Maybe Value))
-> Schema -> Identity Schema)
-> Value -> Schema -> Schema
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ Text -> Value
Aeson.String Text
"[@handle/]name"
instance ToCapture (Capture "branch-name" ProjectBranchName) where
toCapture :: Proxy (Capture "branch-name" ProjectBranchName) -> DocCapture
toCapture Proxy (Capture "branch-name" ProjectBranchName)
_ =
String -> String -> DocCapture
DocCapture
String
"branch-name"
String
"The name of a branch in a project. E.g. @handle/name"
deriving via Text instance ToJSON ProjectBranchName