Skip to content

Commit b9d6ee3

Browse files
committed
test.
1 parent 5070860 commit b9d6ee3

File tree

2 files changed

+92
-2
lines changed

2 files changed

+92
-2
lines changed

src/Servant/Swagger/Internal.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
#endif
1616
module Servant.Swagger.Internal where
1717

18-
-- TODO: write tests!
19-
2018
import Prelude ()
2119
import Prelude.Compat
2220

test/Servant/SwaggerSpec.hs

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
{-# LANGUAGE DeriveGeneric #-}
55
{-# LANGUAGE OverloadedStrings #-}
66
{-# LANGUAGE QuasiQuotes #-}
7+
{-# LANGUAGE TypeFamilies #-}
78
{-# LANGUAGE TypeOperators #-}
89
{-# LANGUAGE PackageImports #-}
910
module Servant.SwaggerSpec where
@@ -40,6 +41,7 @@ spec = describe "HasSwagger" $ do
4041
it "Todo API" $ checkAPI (Proxy :: Proxy TodoAPI) todoAPI
4142
it "Hackage API (with tags)" $ checkSwagger hackageSwaggerWithTags hackageAPI
4243
it "GetPost API (test subOperations)" $ checkSwagger getPostSwagger getPostAPI
44+
it "UVerb API" $ checkSwagger uverbSwagger uverbAPI
4345
it "Comprehensive API" $ do
4446
let _x = toSwagger comprehensiveAPI
4547
True `shouldBe` True -- type-level test
@@ -406,3 +408,93 @@ getPostAPI = [aesonQQ|
406408
}
407409
|]
408410

411+
-- =======================================================================
412+
-- UVerb API
413+
-- =======================================================================
414+
415+
data FisxUser = FisxUser {name :: String}
416+
deriving (Eq, Show, Generic)
417+
418+
instance ToSchema FisxUser
419+
420+
instance HasStatus FisxUser where
421+
type StatusOf FisxUser = 203
422+
423+
data ArianUser = ArianUser
424+
deriving (Eq, Show, Generic)
425+
426+
instance ToSchema ArianUser
427+
428+
type UVerbAPI = "fisx" :> UVerb 'GET '[JSON] '[FisxUser, WithStatus 303 String]
429+
:<|> "arian" :> UVerb 'POST '[JSON] '[WithStatus 201 ArianUser]
430+
431+
uverbSwagger :: Swagger
432+
uverbSwagger = toSwagger (Proxy :: Proxy UVerbAPI)
433+
434+
uverbAPI :: Value
435+
uverbAPI = [aesonQQ|
436+
{
437+
"swagger": "2.0",
438+
"info": {
439+
"version": "",
440+
"title": ""
441+
},
442+
"paths": {
443+
"/fisx": {
444+
"get": {
445+
"produces": [
446+
"application/json;charset=utf-8"
447+
],
448+
"responses": {
449+
"303": {
450+
"schema": {
451+
"type": "string"
452+
},
453+
"description": ""
454+
},
455+
"203": {
456+
"schema": {
457+
"$ref": "#/definitions/FisxUser"
458+
},
459+
"description": ""
460+
}
461+
}
462+
}
463+
},
464+
"/arian": {
465+
"post": {
466+
"produces": [
467+
"application/json;charset=utf-8"
468+
],
469+
"responses": {
470+
"201": {
471+
"schema": {
472+
"$ref": "#/definitions/ArianUser"
473+
},
474+
"description": ""
475+
}
476+
}
477+
}
478+
}
479+
},
480+
"definitions": {
481+
"FisxUser": {
482+
"required": [
483+
"name"
484+
],
485+
"properties": {
486+
"name": {
487+
"type": "string"
488+
}
489+
},
490+
"type": "object"
491+
},
492+
"ArianUser": {
493+
"type": "string",
494+
"enum": [
495+
"ArianUser"
496+
]
497+
}
498+
}
499+
}
500+
|]

0 commit comments

Comments
 (0)