|
4 | 4 | {-# LANGUAGE DeriveGeneric #-}
|
5 | 5 | {-# LANGUAGE OverloadedStrings #-}
|
6 | 6 | {-# LANGUAGE QuasiQuotes #-}
|
| 7 | +{-# LANGUAGE TypeFamilies #-} |
7 | 8 | {-# LANGUAGE TypeOperators #-}
|
8 | 9 | {-# LANGUAGE PackageImports #-}
|
9 | 10 | module Servant.SwaggerSpec where
|
@@ -40,6 +41,7 @@ spec = describe "HasSwagger" $ do
|
40 | 41 | it "Todo API" $ checkAPI (Proxy :: Proxy TodoAPI) todoAPI
|
41 | 42 | it "Hackage API (with tags)" $ checkSwagger hackageSwaggerWithTags hackageAPI
|
42 | 43 | it "GetPost API (test subOperations)" $ checkSwagger getPostSwagger getPostAPI
|
| 44 | + it "UVerb API" $ checkSwagger uverbSwagger uverbAPI |
43 | 45 | it "Comprehensive API" $ do
|
44 | 46 | let _x = toSwagger comprehensiveAPI
|
45 | 47 | True `shouldBe` True -- type-level test
|
@@ -406,3 +408,93 @@ getPostAPI = [aesonQQ|
|
406 | 408 | }
|
407 | 409 | |]
|
408 | 410 |
|
| 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