on develop help sign in
Removing the prime suffix for request types where possible
commitebb6e17e740c65fa7f64237b8e3e184ae9a48e7c authorBrendan Hay <brendan.g.hay@gmail.com> dateTue 20 Oct 2015, 10:35 (11 years ago) parent90791f6
4 files changed+17−8
gen/src/Gen/AST/Flatten.hs+3−3 gen/src/Gen/AST/Render.hs+5−3 gen/src/Gen/Types.hs+8−1 gen/src/Gen/Types/Id.hs+1−1
gen/src/Gen/AST/Flatten.hs+3−3
@@ -31,7 +31,6 @@ import qualified Data.HashSet as Set
3131import Data.Maybe
3232import Data.Semigroup ((<>))
3333import qualified Data.Text as Text
34−import Debug.Trace
3534import Gen.Formatting
3635import Gen.Types
3736import Prelude hiding (sum)
@@ -153,9 +152,10 @@ method qs suf m@Method {..} = do
153152 ps <- Map.traverseWithKey (localParam (abbreviate _mId)) _mParameters
154153 cn <- use sCanonicalName
155154
156− let (_, typ, _) = mname cn suf _mId
155+ let (_, typ', _) = mname cn suf _mId
157156
158− b <- body typ
157+ typ <- reserveType typ'
158+ b <- body typ
159159
160160 let params = ps <> qs
161161 fields = Map.delete "alt" $ b (upload (Map.map _pParam params))
gen/src/Gen/AST/Render.hs+5−3
@@ -132,11 +132,13 @@ renderAPI s = do
132132
133133renderMethod :: Service a -> NS -> Suffix -> Method Solved -> AST Action
134134renderMethod s root suf m@Method {..} = do
135+ typ <- reserveType typ'
136+
135137 x@Solved {..} <- getSolved typ
136138 Just d <- renderSchema x
137139
138− i <- pp Print $ requestDecl _unique _prefix alias url (props _schema) m
139− dl <- pp Print $ downloadDecl _unique _prefix alias url (props _schema) m
140+ i <- pp Print $ requestDecl _unique _prefix alias url (props _schema) m
141+ dl <- pp Print $ downloadDecl _unique _prefix alias url (props _schema) m
140142
141143 let is = i : [dl | _mSupportsMediaDownload]
142144
@@ -144,7 +146,7 @@ renderMethod s root suf m@Method {..} = do
144146 <$> pp Print (verbAlias alias m)
145147 <*> pure (insts is d)
146148 where
147− (alias, typ, ns) = mname (_sCanonicalName s) suf _mId
149+ (alias, typ', ns) = mname (_sCanonicalName s) suf _mId
148150
149151 url = name (serviceName s)
150152
gen/src/Gen/Types.hs+8−1
@@ -334,7 +334,6 @@ initial s = Memo s mempty mempty res core mempty mempty mempty
334334 res = Set.fromList
335335 . mapMaybe (view iId)
336336 $ Map.elems (s ^. dSchemas)
337−
338337 -- Types available in Network.Google.Prelude.
339338 core = Map.fromList
340339 [ ("Body", SLit requiredInfo RqBody)
@@ -349,6 +348,14 @@ instance HasService Memo (Fix Schema) where
349348
350349type AST = ExceptT Error (State Memo)
351350
351+reserveType :: Global -> AST Global
352+reserveType g = do
353+ p <- uses reserve (Set.member g)
354+ pure $!
355+ if p
356+ then reference g "'"
357+ else g
358+
352359reserveBranches :: AST ()
353360reserveBranches = do
354361 ss <- use schemas
gen/src/Gen/Types/Id.hs+1−1
@@ -87,7 +87,7 @@ aname = name . Text.unpack . (<> "API") . upperHead . Text.replace "." ""
8787mname :: Text -> Suffix -> Global -> (Name, Global, Text)
8888mname abrv (Suffix suf) (Global g) =
8989 ( name . Text.unpack $ mconcat n <> suf -- Action service type alias.
90− , Global (n <> ["'"]) -- Action data type.
90+ , Global n -- Action data type.
9191 , Text.intercalate "." ns -- Action namespace.
9292 )
9393 where