Skip to content

Commit

Permalink
comment for api list
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-bodavskiy committed Nov 19, 2024
1 parent f32e6c4 commit 7329baa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/namma-dsl/src/NammaDSL/DSL/Parser/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/namma-dsl/src/NammaDSL/DSL/Syntax/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ data ApiTT = ApiTT
{ _urlParts :: [UrlParts],
_apiType :: ApiType,
_apiName :: Maybe Text,
_apiEndpoint :: Text,
_authType :: Maybe AuthType,
_header :: [HeaderType],
_apiMultipartType :: Maybe ApiMultipart,
Expand Down
13 changes: 13 additions & 0 deletions lib/namma-dsl/src/NammaDSL/Generator/Haskell/Dashboard/Servant.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7329baa

Please sign in to comment.