on develop help sign in
Differentiating between request and response bodies
commitc327699da780b2bf4db57e2235f0d4eac168637d authorBrendan Hay <brendan.g.hay@gmail.com> dateTue 13 Oct 2015, 11:25 (11 years ago) parent0e1d9a6
4 files changed+16−9
gen/src/Gen/AST/Solve.hs+2−1 gen/src/Gen/Syntax.hs+10−6 gen/src/Gen/Types.hs+2−1 gen/src/Gen/Types/Schema.hs+2−1
gen/src/Gen/AST/Solve.hs+2−1
@@ -133,7 +133,8 @@ getDerive g = loc "getDerive" g $ memo derived g go
133133 Bool -> enum
134134 Time -> DRead : base
135135 Date -> DRead : base
136− Body -> []
136+ RqBody -> [DIsString, DMonoid]
137+ RsBody -> []
137138 Alt _ -> DRead : base
138139 JSONValue -> DRead : base
139140 -- FIXME: Add numeric cases
gen/src/Gen/Syntax.hs+10−6
@@ -116,13 +116,13 @@ verbAlias n m
116116 , _mSupportsMediaUpload m =
117117 [TyApp (TyApp (TyApp (TyCon "MultipartRelated") json)
118118 (tycon (ref b)))
119− (TyCon "Stream")]
119+ (TyCon "Body")]
120120
121121 | Just b <- _mRequest m =
122122 [TyApp (TyApp (TyCon "ReqBody") json) (tycon (ref b))]
123123
124124 | _mSupportsMediaUpload m =
125− [TyApp (TyApp (TyCon "ReqBody") octet) (TyCon "RequestBody")]
125+ [TyApp (TyApp (TyCon "ReqBody") octet) (TyCon "Body")]
126126
127127 | otherwise = []
128128
@@ -156,7 +156,9 @@ downloadDecl n p api url fs m =
156156 pat | _mSupportsMediaDownload m = PInfixApp PWildCard (UnQual (sym ":<|>")) (pvar "go")
157157 | otherwise = pvar "go"
158158
159− prec = PApp (UnQual "MediaDownload") [PRec (UnQual (dname n)) [PFieldWildcard]]
159+ prec = PApp (UnQual "MediaDownload")
160+ [ PRec (UnQual (dname n)) [PFieldWildcard | not (null fs)]
161+ ]
160162
161163requestDecl :: Global
162164 -> Prefix
@@ -177,7 +179,7 @@ requestDecl n p api url fs m =
177179 pat | _mSupportsMediaDownload m = PInfixApp (pvar "go") (UnQual (sym ":<|>")) PWildCard
178180 | otherwise = pvar "go"
179181
180− prec = PRec (UnQual (dname n)) [PFieldWildcard]
182+ prec = PRec (UnQual (dname n)) [PFieldWildcard | not (null fs)]
181183
182184googleRequestDecl :: Global
183185 -> Type
@@ -451,7 +453,8 @@ externalLit = \case
451453 Int64 -> TyCon "Int64"
452454
453455 Alt t -> TyCon (unqual (Text.unpack t))
454− Body -> TyCon "Stream"
456+ RqBody -> TyCon "Body"
457+ RsBody -> TyCon "Stream"
455458 JSONValue -> TyCon "JSONValue"
456459
457460internalLit :: Lit -> Type
@@ -471,7 +474,8 @@ internalLit = \case
471474 Int64 -> TyCon "Int64"
472475
473476 Alt t -> TyCon (unqual (Text.unpack t))
474− Body -> TyCon "Stream"
477+ RqBody -> TyCon "Body"
478+ RsBody -> TyCon "Stream"
475479 JSONValue -> TyCon "JSONValue"
476480
477481mapping :: TType -> Exp -> Exp
gen/src/Gen/Types.hs+2−1
@@ -333,7 +333,8 @@ initial s = Memo s mempty mempty res core mempty mempty mempty
333333
334334 -- Types available in Network.Google.Prelude.
335335 core = Map.fromList
336− [ ("Body", SLit requiredInfo Body)
336+ [ ("Body", SLit requiredInfo RqBody)
337+ , ("Stream", SLit requiredInfo RsBody)
337338 , ("JSONValue", SLit requiredInfo JSONValue)
338339 ]
339340
gen/src/Gen/Types/Schema.hs+2−1
@@ -199,7 +199,8 @@ data Lit
199199 | Date
200200 | DateTime
201201 -- Core types.
202− | Body
202+ | RqBody
203+ | RsBody
203204 | JSONValue
204205 | Alt Text
205206 deriving (Eq, Show)