git.iko.soy/typeable/openapi3
on master help sign in
Add Definitions object test
cc208a5Nickolay Kudasov
test/Data/SwaggerSpec.hs+56
@@ -5,9 +5,11 @@ module Data.SwaggerSpec where
5
5
6import Data.Aeson
6import Data.Aeson
7import Data.Aeson.QQ
7import Data.Aeson.QQ
8+import Data.HashMap.Strict (HashMap)
8import qualified Data.HashMap.Strict as HashMap
9import qualified Data.HashMap.Strict as HashMap
9import Data.Maybe
10import Data.Maybe
10import qualified Data.Vector as Vector
11import qualified Data.Vector as Vector
12+import Data.Text (Text)
11
13
12import Data.Swagger
14import Data.Swagger
13
15
@@ -46,6 +48,7 @@ spec = do
46 context "Simple Model" $ schemaSimpleModelExample <~> schemaSimpleModelExampleJSON
48 context "Simple Model" $ schemaSimpleModelExample <~> schemaSimpleModelExampleJSON
47 context "Model with Map/Dictionary Properties" $ schemaModelDictExample <~> schemaModelDictExampleJSON
49 context "Model with Map/Dictionary Properties" $ schemaModelDictExample <~> schemaModelDictExampleJSON
48 context "Model with Example" $ schemaWithExampleExample <~> schemaWithExampleExampleJSON
50 context "Model with Example" $ schemaWithExampleExample <~> schemaWithExampleExampleJSON
51+ describe "Schema Object" $ definitionsExample <~> definitionsExampleJSON
49
52
50main :: IO ()
53main :: IO ()
51main = hspec spec
54main = hspec spec
@@ -334,3 +337,56 @@ schemaWithExampleExampleJSON = [aesonQQ|
334 }
337 }
335}
338}
336|]
339|]
340+
341+-- =======================================================================
342+-- Definitions object
343+-- =======================================================================
344+
345+definitionsExample :: HashMap Text SwaggerSchema
346+definitionsExample =
347+ [ ("Category", mempty
348+ { swaggerSchemaType = SwaggerSchemaObject
349+ , swaggerSchemaProperties =
350+ [ ("id", mempty
351+ { swaggerSchemaType = SwaggerSchemaInteger
352+ , swaggerSchemaFormat = Just "int64" })
353+ , ("name", mempty
354+ { swaggerSchemaType = SwaggerSchemaString }) ] })
355+ , ("Tag", mempty
356+ { swaggerSchemaType = SwaggerSchemaObject
357+ , swaggerSchemaProperties =
358+ [ ("id", mempty
359+ { swaggerSchemaType = SwaggerSchemaInteger
360+ , swaggerSchemaFormat = Just "int64" })
361+ , ("name", mempty
362+ { swaggerSchemaType = SwaggerSchemaString }) ] }) ]
363+
364+definitionsExampleJSON :: Value
365+definitionsExampleJSON = [aesonQQ|
366+{
367+ "Category": {
368+ "type": "object",
369+ "properties": {
370+ "id": {
371+ "type": "integer",
372+ "format": "int64"
373+ },
374+ "name": {
375+ "type": "string"
376+ }
377+ }
378+ },
379+ "Tag": {
380+ "type": "object",
381+ "properties": {
382+ "id": {
383+ "type": "integer",
384+ "format": "int64"
385+ },
386+ "name": {
387+ "type": "string"
388+ }
389+ }
390+ }
391+}
392+|]