Use a specific name for OpenAPI module

This commit is contained in:
Jacky Hu
2016-06-18 10:18:43 +08:00
parent 563c5fa778
commit 103fa0550c
3 changed files with 11 additions and 9 deletions
+1 -1
View File
@@ -128,7 +128,7 @@ library
, PostgREST.RangeQuery
, PostgREST.ApiRequest
, PostgREST.Types
, PostgREST.ApiSpec
, PostgREST.OpenAPI
hs-source-dirs: src
Test-Suite spec
+2 -4
View File
@@ -9,7 +9,6 @@ module PostgREST.App (
import Control.Applicative
import Data.Bifunctor (first)
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Lazy as BL
import Data.IORef (IORef, readIORef)
import Data.List (find, delete)
import Data.Maybe (fromMaybe, fromJust, mapMaybe)
@@ -61,7 +60,7 @@ import PostgREST.QueryBuilder ( callProc
, ResultsWithCount
)
import PostgREST.Types
import PostgREST.ApiSpec
import PostgREST.OpenAPI
import Prelude
@@ -227,8 +226,7 @@ app dbStructure conf apiRequest =
pkeys = map pkName $ filter (filterPk tSchema tTable) allPrKeys
in
(t, cols, pkeys))
encodeApi :: [(Table, [Column], [Text])] -> BL.ByteString
encodeApi ti = encode $ apiSpec ti host port
encodeApi ti = encodeOpenAPI ti host port
host = configHost conf
port = toInteger $ configPort conf
notFound = responseLBS status404 [] ""
@@ -1,11 +1,12 @@
{-# LANGUAGE OverloadedStrings #-}
module PostgREST.ApiSpec (
apiSpec
module PostgREST.OpenAPI (
encodeOpenAPI
) where
import Control.Lens
import Data.Aeson (decode, encode)
import Data.ByteString.Lazy (ByteString)
import Data.HashMap.Strict.InsOrd (InsOrdHashMap, fromList)
import Data.String (IsString (..))
import Data.Text (Text, unpack, pack, concat, intercalate)
@@ -199,8 +200,8 @@ makeRootPathItem = ("/", p)
makePathItems :: [(Table, [Column], [Text])] -> InsOrdHashMap FilePath PathItem
makePathItems ti = fromList $ makeRootPathItem : map makePathItem ti
apiSpec :: [(Table, [Column], [Text])] -> String -> Integer -> Swagger
apiSpec ti h p = (mempty :: Swagger)
postgrestSpec:: [(Table, [Column], [Text])] -> String -> Integer -> Swagger
postgrestSpec ti h p = (mempty :: Swagger)
& basePath ?~ "/"
& schemes ?~ [Http]
& info .~ ((mempty :: Info)
@@ -212,3 +213,6 @@ apiSpec ti h p = (mempty :: Swagger)
& paths .~ makePathItems ti
where
h' = Just $ Host h (Just (fromInteger p))
encodeOpenAPI :: [(Table, [Column], [Text])] -> String -> Integer -> ByteString
encodeOpenAPI ti h p = encode $ postgrestSpec ti h p