on develop help sign in
Adding a default scope name
5242370Brendan Hay
gen/src/Gen/AST/Render.hs+3−8
@@ -113,7 +113,7 @@ renderAPI s = do
113 where
113 where
114 alias = aname (_sCanonicalName s)
114 alias = aname (_sCanonicalName s)
115
115
116− url = name (Text.unpack (urlName s))
116+ url = name (serviceName s)
117
117
118 svc = Fun' url (Just (rawHelpText h))
118 svc = Fun' url (Just (rawHelpText h))
119 <$> pp None (urlSig url)
119 <$> pp None (urlSig url)
@@ -127,12 +127,7 @@ renderAPI s = do
127 <$> pp None (scopeSig n)
127 <$> pp None (scopeSig n)
128 <*> pp None (scopeDecl n k)
128 <*> pp None (scopeDecl n k)
129 where
129 where
130− n = name
130+ n = name (scopeName s k)
131− . Text.unpack
132− . (<> "Scope")
133− . toCamel
134− . last
135− $ Text.split (== '/') k
136
131
137renderMethod :: Service a -> NS -> Suffix -> Method Solved -> AST Action
132renderMethod :: Service a -> NS -> Suffix -> Method Solved -> AST Action
138renderMethod s root suf m@Method {..} = do
133renderMethod s root suf m@Method {..} = do
@@ -150,7 +145,7 @@ renderMethod s root suf m@Method {..} = do
150 where
145 where
151 (alias, typ, ns) = mname (_sCanonicalName s) suf _mId
146 (alias, typ, ns) = mname (_sCanonicalName s) suf _mId
152
147
153− url = name (Text.unpack (urlName s))
148+ url = name (serviceName s)
154
149
155 insts is = \case
150 insts is = \case
156 Prod n h r c ls _ -> Prod n h r c ls is
151 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 ((<>))
38import Data.Text (Text)
38import Data.Text (Text)
39import qualified Data.Text as Text
39import qualified Data.Text as Text
40import Data.Text.Manipulate
40import Data.Text.Manipulate
41+import Debug.Trace
41import Gen.Orphans ()
42import Gen.Orphans ()
42import Gen.Text
43import Gen.Text
43import Gen.TH
44import Gen.TH
@@ -433,5 +434,16 @@ instance FromJSON a => FromJSON (Service a) where
433instance HasDescription (Service a) a where
434instance HasDescription (Service a) a where
434 description = sDescription
435 description = sDescription
435
436
436−urlName :: Service a -> Text
437+serviceName :: Service a -> String
437−urlName = (<> "Service") . toCamel . _sCanonicalName
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+