on develop help sign in
Adding a default scope name
commit5242370685fbd8731c9ed4d4fa7a3873f75b3247 authorBrendan Hay <brendan.g.hay@gmail.com> dateTue 13 Oct 2015, 14:01 (11 years ago) parent208c39e
2 files changed+17−10
gen/src/Gen/AST/Render.hs+3−8 gen/src/Gen/Types/Schema.hs+14−2
gen/src/Gen/AST/Render.hs+3−8
@@ -113,7 +113,7 @@ renderAPI s = do
113113 where
114114 alias = aname (_sCanonicalName s)
115115
116− url = name (Text.unpack (urlName s))
116+ url = name (serviceName s)
117117
118118 svc = Fun' url (Just (rawHelpText h))
119119 <$> pp None (urlSig url)
@@ -127,12 +127,7 @@ renderAPI s = do
127127 <$> pp None (scopeSig n)
128128 <*> pp None (scopeDecl n k)
129129 where
130− n = name
131− . Text.unpack
132− . (<> "Scope")
133− . toCamel
134− . last
135− $ Text.split (== '/') k
130+ n = name (scopeName s k)
136131
137132renderMethod :: Service a -> NS -> Suffix -> Method Solved -> AST Action
138133renderMethod s root suf m@Method {..} = do
@@ -150,7 +145,7 @@ renderMethod s root suf m@Method {..} = do
150145 where
151146 (alias, typ, ns) = mname (_sCanonicalName s) suf _mId
152147
153− url = name (Text.unpack (urlName s))
148+ url = name (serviceName s)
154149
155150 insts is = \case
156151 Prod n h r c ls _ -> Prod n h r c ls is
gen/src/Gen/Types/Schema.hs+14−2
@@ -38,6 +38,7 @@ import Data.Semigroup ((<>))
3838import Data.Text (Text)
3939import qualified Data.Text as Text
4040import Data.Text.Manipulate
41+import Debug.Trace
4142import Gen.Orphans ()
4243import Gen.Text
4344import Gen.TH
@@ -433,5 +434,16 @@ instance FromJSON a => FromJSON (Service a) where
433434instance HasDescription (Service a) a where
434435 description = sDescription
435436
436−urlName :: Service a -> Text
437−urlName = (<> "Service") . toCamel . _sCanonicalName
437+serviceName :: Service a -> String
438+serviceName = Text.unpack . (<> "Service") . toCamel . _sCanonicalName
439+
440+scopeName :: Service a -> Text -> String
441+scopeName s k =
442+ let y = _sCanonicalName s <> "AllScope"
443+ in Text.unpack . toCamel $
444+ case Text.split (== '/') k of
445+ [] -> y
446+ xs -> case last xs of
447+ "" -> y
448+ x -> x <> "Scope"
449+