Skip to content

Commit c3a517c

Browse files
committed
doc(servant-foreign): Inflection docs & module docs
1 parent 0743ca7 commit c3a517c

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

servant-foreign/src/Servant/Foreign.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
-- | Generalizes all the data needed to make code generation work with
22
-- arbitrary programming languages.
3+
--
4+
-- See documentation of 'HasForeignType' for a simple example. 'listFromAPI' returns a list of all your endpoints and their foreign types, given a mapping from Haskell types to foreign types (conventionally called `ftypes` below).
35
module Servant.Foreign
46
( ArgType(..)
57
, HeaderArg(..)

servant-foreign/src/Servant/Foreign/Inflections.hs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,31 @@ import Prelude hiding
2020
(head, tail)
2121
import Servant.Foreign.Internal
2222

23+
-- | Simply concat each part of the FunctionName together.
24+
--
25+
-- @[ "get", "documents", "by", "id" ] → "getdocumentsbyid"@
26+
concatCase :: FunctionName -> Text
27+
concatCase = view concatCaseL
28+
2329
concatCaseL :: Getter FunctionName Text
2430
concatCaseL = _FunctionName . to mconcat
2531

26-
-- | Function name builder that simply concat each part together
27-
concatCase :: FunctionName -> Text
28-
concatCase = view concatCaseL
32+
-- | Use the snake_case convention.
33+
-- Each part is separated by a single underscore character.
34+
--
35+
-- @[ "get", "documents", "by", "id" ] → "get_documents_by_id"@
36+
snakeCase :: FunctionName -> Text
37+
snakeCase = view snakeCaseL
2938

3039
snakeCaseL :: Getter FunctionName Text
3140
snakeCaseL = _FunctionName . to (intercalate "_")
3241

33-
-- | Function name builder using the snake_case convention.
34-
-- each part is separated by a single underscore character.
35-
snakeCase :: FunctionName -> Text
36-
snakeCase = view snakeCaseL
42+
-- | Use the camelCase convention.
43+
-- The first part is lower case, every other part starts with an upper case character.
44+
--
45+
-- @[ "get", "documents", "by", "id" ] → "getDocumentsById"@
46+
camelCase :: FunctionName -> Text
47+
camelCase = view camelCaseL
3748

3849
camelCaseL :: Getter FunctionName Text
3950
camelCaseL = _FunctionName . to convert
@@ -42,8 +53,3 @@ camelCaseL = _FunctionName . to convert
4253
convert (p:ps) = mconcat $ p : map capitalize ps
4354
capitalize "" = ""
4455
capitalize name = C.toUpper (head name) `cons` tail name
45-
46-
-- | Function name builder using the CamelCase convention.
47-
-- each part begins with an upper case character.
48-
camelCase :: FunctionName -> Text
49-
camelCase = view camelCaseL

servant-foreign/src/Servant/Foreign/Internal.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
{-# LANGUAGE TypeOperators #-}
1414
{-# LANGUAGE UndecidableInstances #-}
1515

16-
-- | Generalizes all the data needed to make code generation work with
17-
-- arbitrary programming languages.
1816
module Servant.Foreign.Internal where
1917

2018
import Prelude ()
@@ -40,6 +38,9 @@ import Servant.API.Modifiers
4038
(RequiredArgument)
4139
import Servant.API.TypeLevel
4240

41+
-- | Canonical name of the endpoint, can be used to generate a function name.
42+
--
43+
-- You can use the functions in "Servant.Foreign.Inflections", like 'Servant.Foreign.Inflections.camelCase' to transform to `Text`.
4344
newtype FunctionName = FunctionName { unFunctionName :: [Text] }
4445
deriving (Data, Show, Eq, Semigroup, Monoid, Typeable)
4546

0 commit comments

Comments
 (0)