Merge pull request #639 from hudayou/swagger2
Provide a swagger2 spec for the dynamic API
This commit is contained in:
@@ -8,7 +8,11 @@ import SpecHelper
|
||||
|
||||
import Network.HTTP.Types
|
||||
import Network.Wai (Application)
|
||||
import Network.Wai.Test (SResponse(simpleHeaders))
|
||||
import Network.Wai.Test (SResponse(simpleStatus, simpleHeaders, simpleBody))
|
||||
|
||||
import Data.Maybe (fromJust)
|
||||
import Data.Aeson (decode)
|
||||
import qualified Data.JsonSchema.Draft4 as D4
|
||||
|
||||
spec :: SpecWith Application
|
||||
spec = do
|
||||
@@ -61,6 +65,33 @@ spec = do
|
||||
] |]
|
||||
{matchStatus = 200}
|
||||
|
||||
it "returns a valid openapi spec" $ do
|
||||
r <- request methodGet "/" [("Accept", "application/openapi+json")] ""
|
||||
liftIO $
|
||||
let respStatus = simpleStatus r in
|
||||
respStatus `shouldSatisfy`
|
||||
\s -> s == Status { statusCode = 200, statusMessage="OK" }
|
||||
liftIO $
|
||||
let respHeaders = simpleHeaders r in
|
||||
respHeaders `shouldSatisfy`
|
||||
\hs -> ("Content-Type", "application/openapi+json; charset=utf-8") `elem` hs
|
||||
liftIO $
|
||||
let respBody = simpleBody r
|
||||
schema :: D4.Schema
|
||||
schema = D4.emptySchema { D4._schemaRef = Just "openapi.json" }
|
||||
schemaContext :: D4.SchemaWithURI D4.Schema
|
||||
schemaContext = D4.SchemaWithURI
|
||||
{ D4._swSchema = schema
|
||||
, D4._swURI = Just "test/fixtures/openapi.json"
|
||||
}
|
||||
in
|
||||
D4.fetchFilesystemAndValidate schemaContext ((fromJust . decode) respBody) `shouldReturn` Right ()
|
||||
|
||||
it "should respond to openapi request on none root path with 415" $
|
||||
request methodGet "/none_root_path"
|
||||
(acceptHdrs "application/openapi+json") ""
|
||||
`shouldRespondWith` 415
|
||||
|
||||
describe "Table info" $ do
|
||||
it "The structure of complex views is correctly detected" $
|
||||
request methodOptions "/filtered_tasks" [] "" `shouldRespondWith`
|
||||
|
||||
Reference in New Issue
Block a user