From 7329baa34a1e1431ff1969860a5a0bc302345d00 Mon Sep 17 00:00:00 2001 From: Roman Bodavskiy Date: Wed, 31 Jul 2024 13:21:04 +0300 Subject: [PATCH] comment for api list --- lib/namma-dsl/src/NammaDSL/DSL/Parser/API.hs | 3 ++- lib/namma-dsl/src/NammaDSL/DSL/Syntax/API.hs | 1 + .../NammaDSL/Generator/Haskell/Dashboard/Servant.hs | 13 +++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/namma-dsl/src/NammaDSL/DSL/Parser/API.hs b/lib/namma-dsl/src/NammaDSL/DSL/Parser/API.hs index c67fb0e..52a51d7 100644 --- a/lib/namma-dsl/src/NammaDSL/DSL/Parser/API.hs +++ b/lib/namma-dsl/src/NammaDSL/DSL/Parser/API.hs @@ -104,6 +104,7 @@ parseAllApis' = do obj <- preview (_Object) val let params = fromMaybe KM.empty $ preview (ix acc_params ._Object) obj endpoint = parseEndpoint params $ fromMaybe (error "Endpoint not found !") $ preview (ix acc_endpoint . _String) obj + endpointText = fromMaybe (error "Endpoint not found !") $ preview (ix acc_endpoint . _String) obj auth = getAuthType <$> preview (ix acc_auth . _String) obj req = parseRequest obj @@ -139,7 +140,7 @@ parseAllApis' = do A.Null -> ApiMigration (toText k) Nothing _ -> error "String or Null migration params only supported for now" - return $ ApiTT allApiParts apiTp apiName auth headers multipart req res helperApi apiKind moduleName requestValidation migrations + return $ ApiTT allApiParts apiTp apiName endpointText auth headers multipart req res helperApi apiKind moduleName requestValidation migrations parseSingleApi _ _ _ _ = error "Api specs missing" parseRequest :: A.Object -> Maybe ApiReq diff --git a/lib/namma-dsl/src/NammaDSL/DSL/Syntax/API.hs b/lib/namma-dsl/src/NammaDSL/DSL/Syntax/API.hs index 36bf832..1c071b4 100644 --- a/lib/namma-dsl/src/NammaDSL/DSL/Syntax/API.hs +++ b/lib/namma-dsl/src/NammaDSL/DSL/Syntax/API.hs @@ -74,6 +74,7 @@ data ApiTT = ApiTT { _urlParts :: [UrlParts], _apiType :: ApiType, _apiName :: Maybe Text, + _apiEndpoint :: Text, _authType :: Maybe AuthType, _header :: [HeaderType], _apiMultipartType :: Maybe ApiMultipart, diff --git a/lib/namma-dsl/src/NammaDSL/Generator/Haskell/Dashboard/Servant.hs b/lib/namma-dsl/src/NammaDSL/Generator/Haskell/Dashboard/Servant.hs index f15a207..6ec7034 100644 --- a/lib/namma-dsl/src/NammaDSL/Generator/Haskell/Dashboard/Servant.hs +++ b/lib/namma-dsl/src/NammaDSL/Generator/Haskell/Dashboard/Servant.hs @@ -119,11 +119,24 @@ mkCodeBody generationType apiRead = do let allApis = input ^. apis tellM . fromMaybe mempty $ interpreter input $ do + generateApiListComment generateAPIType SERVANT_API_DASHBOARD apiRead generateAPIHandler apiRead forM_ allApis $ generateServantApiType generationType apiRead forM_ allApis $ handlerFunctionDef generationType apiRead +generateApiListComment :: Writer CodeUnit +generateApiListComment = do + input <- ask + let moduleName' = input ^. moduleName + commentW $ T.unpack moduleName' <> "APIs:" + let apiPrefix' = + T.unpack $ + fromMaybe (headToLower $ input ^. moduleName) $ + input ^. apiPrefix + forM_ (input ^. apis) \api -> do + commentW $ show (api ^. apiType) <> " /" <> apiPrefix' <> T.unpack (api ^. apiEndpoint) + generateAPIHandler :: ApiRead -> Writer CodeUnit generateAPIHandler apiRead = do input <- ask