Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly pluralize resource names #85

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rest-gen/rest-gen.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ library
, hslogger >= 1.1 && < 1.3
, hxt >= 9.2 && < 9.4
, json-schema >= 0.6 && < 0.8
, Plural >= 0.0.2 && < 1.0
, pretty >= 1.0 && < 1.2
, process >= 1.0 && < 1.3
, rest-core >= 0.31 && < 0.34
Expand Down
7 changes: 4 additions & 3 deletions rest-gen/src/Rest/Gen/Base/ActionInfo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import qualified Data.Foldable as F
import qualified Data.JSON.Schema as J
import qualified Data.Label.Total as L
import qualified Data.List.NonEmpty as NList
import Language.English.Plural (plural)
import qualified Language.Haskell.Exts.Parser as H
import qualified Language.Haskell.Exts.Syntax as H

Expand Down Expand Up @@ -527,8 +528,8 @@ mkActionDescription res ai =
Retrieve -> "Retrieve " ++ targetS ++ " data"
Create -> "Create " ++ targetS
Delete -> "Delete " ++ targetS
DeleteMany -> "Delete many " ++ targetS
List -> "List " ++ targetS ++ "s"
DeleteMany -> "Delete many " ++ plural targetS
List -> "List " ++ plural targetS
Update -> "Update " ++ targetS
UpdateMany -> "Update many " ++ targetS
UpdateMany -> "Update many " ++ plural targetS
Modify -> "Modify " ++ targetS
25 changes: 21 additions & 4 deletions rest-gen/tests/Runner.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,13 @@ main = do
, testCase "Selects should show up only once." testSingleSelect
, testCase "Removes should show up only once." testSingleRemove
, testCase "Listing should have List type." testListingType
, testCase "Listing pluralization" testListingPluralization
]

testListingParams :: Assertion
testListingParams = assertEqual "Parameters" ["offset", "count"] (params actionInfo)
where
[actionInfo] = resourceToActionInfo resource
resource :: Resource IO IO Void () Void
resource = mkResourceId { name = "resource", schema = Schema (Just (Many ())) (Named []), list = listHandler }
listHandler () = mkListing id $ \_ -> return []
[actionInfo] = resourceToActionInfo baseResource

testSingleSelect :: Assertion
testSingleSelect = assertEqual "Number of select ActionInfos." 1 (length actionInfos)
Expand Down Expand Up @@ -90,3 +88,22 @@ testListingType =

instance IsString H.Type where
fromString = H.fromParseResult . H.parse


testListingPluralization :: Assertion
testListingPluralization =
assertEqual "Listing should not doubly pluralize resource names"
"List things"
(mkActionDescription rn ai)
where
rn = "things"
ai = head $ listGetterActionInfo
baseResource { name = rn}
"/"
(Singleton ())


baseResource :: Resource IO IO Void () Void
baseResource = mkResourceId { name = "resource", schema = Schema (Just (Many ())) (Named []), list = listHandler }
where
listHandler () = mkListing id $ \_ -> return []