@@ -1,5 +1,6 @@
1{-# LANGUAGE OverloadedLists #-}
1{-# LANGUAGE OverloadedLists #-}
2{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE OverloadedStrings #-}
3+{-# LANGUAGE ScopedTypeVariables #-}
3{-# LANGUAGE QuasiQuotes #-}
4{-# LANGUAGE QuasiQuotes #-}
4module Data.SwaggerSpec where
5module Data.SwaggerSpec where
@@ -54,7 +55,11 @@ spec = do
54 describe "Parameters Definition Object" $ parametersDefinitionExample <~> parametersDefinitionExampleJSON
55 describe "Parameters Definition Object" $ parametersDefinitionExample <~> parametersDefinitionExampleJSON
55 describe "Responses Definition Object" $ responsesDefinitionExample <~> responsesDefinitionExampleJSON
56 describe "Responses Definition Object" $ responsesDefinitionExample <~> responsesDefinitionExampleJSON
56 describe "Security Definitions Object" $ securityDefinitionsExample <~> securityDefinitionsExampleJSON
57 describe "Security Definitions Object" $ securityDefinitionsExample <~> securityDefinitionsExampleJSON
58+ describe "Swagger Object" $ do
57− describe "Swagger Object" $ swaggerExample <~> swaggerExampleJSON
59+ context "Todo Example" $ swaggerExample <~> swaggerExampleJSON
60+ context "PetStore Example" $
61+ it "decodes successfully" $ do
62+ fromJSON petstoreExampleJSON `shouldSatisfy` (\x -> case x of Success (_ :: Swagger) -> True; _ -> False)
59main :: IO ()
64main :: IO ()
60main = hspec spec
65main = hspec spec
@@ -526,7 +531,7 @@ swaggerExample = mempty
526 { swaggerOperationResponses = mempty
531 { swaggerOperationResponses = mempty
527 { swaggerResponsesResponses =
532 { swaggerResponsesResponses =
528 [ (200, SwaggerInline mempty
533 [ (200, SwaggerInline mempty
529− { swaggerResponseSchema = Just mempty
534+ { swaggerResponseSchema = Just $ SwaggerInline mempty
530 { swaggerSchemaExample = Just [aesonQQ|
535 { swaggerSchemaExample = Just [aesonQQ|
532 "created": 100,
537 "created": 100,
@@ -614,3 +619,1041 @@ swaggerExampleJSON = [aesonQQ|
623+petstoreExampleJSON :: Value
624+petstoreExampleJSON = [aesonQQ|
628+ "description":"This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.",
630+ "title":"Swagger Petstore",
631+ "termsOfService":"http://swagger.io/terms/",
633+ "email":"apiteam@swagger.io"
636+ "name":"Apache 2.0",
637+ "url":"http://www.apache.org/licenses/LICENSE-2.0.html"
640+ "host":"petstore.swagger.io",
645+ "description":"Everything about your Pets",
647+ "description":"Find out more",
648+ "url":"http://swagger.io"
653+ "description":"Access to Petstore orders"
657+ "description":"Operations about user",
659+ "description":"Find out more about our store",
660+ "url":"http://swagger.io"
673+ "summary":"Add a new pet to the store",
675+ "operationId":"addPet",
688+ "description":"Pet object that needs to be added to the store",
691+ "$ref":"#/definitions/Pet"
697+ "description":"Invalid input"
713+ "summary":"Update an existing pet",
715+ "operationId":"updatePet",
728+ "description":"Pet object that needs to be added to the store",
731+ "$ref":"#/definitions/Pet"
737+ "description":"Invalid ID supplied"
740+ "description":"Pet not found"
743+ "description":"Validation exception"
756+ "/pet/findByStatus":{
761+ "summary":"Finds Pets by status",
762+ "description":"Multiple status values can be provided with comma seperated strings",
763+ "operationId":"findPetsByStatus",
772+ "description":"Status values that need to be considered for filter",
782+ "default":"available"
784+ "collectionFormat":"csv"
789+ "description":"successful operation",
793+ "$ref":"#/definitions/Pet"
798+ "description":"Invalid status value"
816+ "summary":"Finds Pets by tags",
817+ "description":"Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.",
818+ "operationId":"findPetsByTags",
827+ "description":"Tags to filter by",
833+ "collectionFormat":"csv"
838+ "description":"successful operation",
842+ "$ref":"#/definitions/Pet"
847+ "description":"Invalid tag value"
865+ "summary":"Find pet by ID",
866+ "description":"Returns a single pet",
867+ "operationId":"getPetById",
876+ "description":"ID of pet to return",
884+ "description":"successful operation",
886+ "$ref":"#/definitions/Pet"
890+ "description":"Invalid ID supplied"
893+ "description":"Pet not found"
907+ "summary":"Updates a pet in the store with form data",
909+ "operationId":"updatePetWithForm",
911+ "application/x-www-form-urlencoded"
921+ "description":"ID of pet that needs to be updated",
929+ "description":"Updated name of the pet",
936+ "description":"Updated status of the pet",
943+ "description":"Invalid input"
959+ "summary":"Deletes a pet",
961+ "operationId":"deletePet",
976+ "description":"Pet id to delete",
984+ "description":"Invalid pet value"
997+ "/pet/{petId}/uploadImage":{
1002+ "summary":"uploads an image",
1004+ "operationId":"uploadFile",
1006+ "multipart/form-data"
1015+ "description":"ID of pet to update",
1021+ "name":"additionalMetadata",
1023+ "description":"Additional data to pass to server",
1030+ "description":"file to upload",
1037+ "description":"successful operation",
1039+ "$ref":"#/definitions/ApiResponse"
1053+ "/store/inventory":{
1058+ "summary":"Returns pet inventories by status",
1059+ "description":"Returns a map of status codes to quantities",
1060+ "operationId":"getInventory",
1068+ "description":"successful operation",
1071+ "additionalProperties":{
1091+ "summary":"Place an order for a pet",
1093+ "operationId":"placeOrder",
1102+ "description":"order placed for purchasing the pet",
1105+ "$ref":"#/definitions/Order"
1111+ "description":"successful operation",
1113+ "$ref":"#/definitions/Order"
1117+ "description":"Invalid Order"
1122+ "/store/order/{orderId}":{
1127+ "summary":"Find purchase order by ID",
1128+ "description":"For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions",
1129+ "operationId":"getOrderById",
1138+ "description":"ID of pet that needs to be fetched",
1148+ "description":"successful operation",
1150+ "$ref":"#/definitions/Order"
1154+ "description":"Invalid ID supplied"
1157+ "description":"Order not found"
1165+ "summary":"Delete purchase order by ID",
1166+ "description":"For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors",
1167+ "operationId":"deleteOrder",
1176+ "description":"ID of the order that needs to be deleted",
1184+ "description":"Invalid ID supplied"
1187+ "description":"Order not found"
1197+ "summary":"Create user",
1198+ "description":"This can only be done by the logged in user.",
1199+ "operationId":"createUser",
1208+ "description":"Created user object",
1211+ "$ref":"#/definitions/User"
1217+ "description":"successful operation"
1222+ "/user/createWithArray":{
1227+ "summary":"Creates list of users with given input array",
1229+ "operationId":"createUsersWithArrayInput",
1238+ "description":"List of user object",
1243+ "$ref":"#/definitions/User"
1250+ "description":"successful operation"
1255+ "/user/createWithList":{
1260+ "summary":"Creates list of users with given input array",
1262+ "operationId":"createUsersWithListInput",
1271+ "description":"List of user object",
1276+ "$ref":"#/definitions/User"
1283+ "description":"successful operation"
1293+ "summary":"Logs user into the system",
1295+ "operationId":"loginUser",
1304+ "description":"The user name for login",
1311+ "description":"The password for login in clear text",
1318+ "description":"successful operation",
1326+ "description":"calls per hour allowed by the user"
1328+ "X-Expires-After":{
1330+ "format":"date-time",
1331+ "description":"date in UTC when toekn expires"
1336+ "description":"Invalid username/password supplied"
1346+ "summary":"Logs out current logged in user session",
1348+ "operationId":"logoutUser",
1357+ "description":"successful operation"
1362+ "/user/{username}":{
1367+ "summary":"Get user by user name",
1369+ "operationId":"getUserByName",
1378+ "description":"The name that needs to be fetched. Use user1 for testing. ",
1385+ "description":"successful operation",
1387+ "$ref":"#/definitions/User"
1391+ "description":"Invalid username supplied"
1394+ "description":"User not found"
1402+ "summary":"Updated user",
1403+ "description":"This can only be done by the logged in user.",
1404+ "operationId":"updateUser",
1413+ "description":"name that need to be deleted",
1420+ "description":"Updated user object",
1423+ "$ref":"#/definitions/User"
1429+ "description":"Invalid user supplied"
1432+ "description":"User not found"
1440+ "summary":"Delete user",
1441+ "description":"This can only be done by the logged in user.",
1442+ "operationId":"deleteUser",
1451+ "description":"The name that needs to be deleted",
1458+ "description":"Invalid username supplied"
1461+ "description":"User not found"
1467+ "securityDefinitions":{
1470+ "authorizationUrl":"http://petstore.swagger.io/api/oauth/dialog",
1473+ "write:pets":"modify pets in your account",
1474+ "read:pets":"read your pets"
1501+ "format":"date-time"
1505+ "description":"Order Status",
1564+ "description":"User Status"
1598+ "$ref":"#/definitions/Category"
1621+ "$ref":"#/definitions/Tag"
1626+ "description":"pet status in the store",
1655+ "description":"Find out more about Swagger",
1656+ "url":"http://swagger.io"