git.iko.soy/rowtype-yoga/purescript-yoga-http-api
on feat/custom-type-errors help sign in
docs: Add example test using OpenAPI schema validation
3bb7945Mark
test/Test/BearerAuthTest.purs+8−1
@@ -2,6 +2,7 @@ module Test.BearerAuthTest where
2
2
3import Prelude
3import Prelude
4
4
5+import Data.Array as Array
5import Data.Maybe (Maybe(..))
6import Data.Maybe (Maybe(..))
6import Data.String as String
7import Data.String as String
7import Effect (Effect)
8import Effect (Effect)
@@ -9,6 +10,7 @@ import Yoga.HTTP.API.Path (Path, Lit)
9import Yoga.HTTP.API.Route (GET, Route, Request, buildOpenAPISpec)
10import Yoga.HTTP.API.Route (GET, Route, Request, buildOpenAPISpec)
10import Yoga.HTTP.API.Route.Auth (BearerToken, BasicAuth, ApiKeyHeader, DigestAuth)
11import Yoga.HTTP.API.Route.Auth (BearerToken, BasicAuth, ApiKeyHeader, DigestAuth)
11import Yoga.JSON (writeJSON)
12import Yoga.JSON (writeJSON)
13+import Test.OpenAPIValidation (validate)
12import ViTest (ViTest, describe, test)
14import ViTest (ViTest, describe, test)
13import ViTest.Expect (expectToBe)
15import ViTest.Expect (expectToBe)
14
16
@@ -56,12 +58,17 @@ testBearerTokenAuth = describe "BearerToken Authentication" do
56 let hasBearerAuth = String.contains (String.Pattern "bearerAuth") json
58 let hasBearerAuth = String.contains (String.Pattern "bearerAuth") json
57 expectToBe true hasBearerAuth
59 expectToBe true hasBearerAuth
58
60
59− test "BearerToken security scheme has correct structure" do
61+ _ <- test "BearerToken security scheme has correct structure" do
60 let spec = buildOpenAPISpec @BearerAuthAPI { title: "Auth API", version: "1.0.0", description: Nothing, contact: Nothing, license: Nothing }
62 let spec = buildOpenAPISpec @BearerAuthAPI { title: "Auth API", version: "1.0.0", description: Nothing, contact: Nothing, license: Nothing }
61 let json = writeJSON spec
63 let json = writeJSON spec
62 expectToBe true (String.contains (String.Pattern "\"type\":\"http\"") json)
64 expectToBe true (String.contains (String.Pattern "\"type\":\"http\"") json)
63 expectToBe true (String.contains (String.Pattern "\"scheme\":\"bearer\"") json)
65 expectToBe true (String.contains (String.Pattern "\"scheme\":\"bearer\"") json)
64
66
67+ test "BearerToken API generates valid OpenAPI 3.0 schema" do
68+ let spec = buildOpenAPISpec @BearerAuthAPI { title: "Auth API", version: "1.0.0", description: Nothing, contact: Nothing, license: Nothing }
69+ let result = validate spec
70+ expectToBe true (Array.null result.errors)
71+
65testBasicAuth :: Effect ViTest
72testBasicAuth :: Effect ViTest
66testBasicAuth = describe "BasicAuth Authentication" do
73testBasicAuth = describe "BasicAuth Authentication" do
67 _ <- test "BasicAuth does not appear as a regular header parameter" do
74 _ <- test "BasicAuth does not appear as a regular header parameter" do