@@ -4,12 +4,15 @@
44{-# LANGUAGE QuasiQuotes #-}
55module Data.SwaggerSpec where
66
7+import Control.Lens
8+
79import Data.Aeson
810import Data.Aeson.QQ
911import Data.HashMap.Strict (HashMap)
1012import Data.Text (Text)
1113
1214import Data.Swagger
15+import Data.Swagger.Lens
1316import SpecCommon
1417import Test.Hspec
1518
@@ -148,10 +151,10 @@ operationExample = mempty
148151 , _paramSchema = ParamOther (stringSchema ParamFormData) }
149152 ]
150153
154+ stringSchema :: ParamLocation -> ParamOtherSchema
151155 stringSchema i = mempty
152− { _paramOtherSchemaIn = i
153− , _paramOtherSchemaType = ParamString
154− }
156+ & paramOtherSchemaIn .~ i
157+ & schemaType .~ ParamString
155158
156159operationExampleJSON :: Value
157160operationExampleJSON = [aesonQQ|
@@ -217,9 +220,8 @@ operationExampleJSON = [aesonQQ|
217220
218221schemaPrimitiveExample :: Schema
219222schemaPrimitiveExample = mempty
220− { _schemaType = SchemaString
221− , _schemaFormat = Just "email"
222− }
223+ & schemaType .~ SchemaString
224+ & schemaFormat ?~ "email"
223225
224226schemaPrimitiveExampleJSON :: Value
225227schemaPrimitiveExampleJSON = [aesonQQ|
@@ -231,17 +233,15 @@ schemaPrimitiveExampleJSON = [aesonQQ|
231233
232234schemaSimpleModelExample :: Schema
233235schemaSimpleModelExample = mempty
234− { _schemaType = SchemaObject
235− , _schemaRequired = [ "name" ]
236− , _schemaProperties =
237− [ ("name", Inline mempty
238− { _schemaType = SchemaString } )
236+ & schemaType .~ SchemaObject
237+ & schemaRequired .~ [ "name" ]
238+ & schemaProperties .~
239+ [ ("name", Inline (mempty & schemaType .~ SchemaString))
239240 , ("address", Ref (Reference "#/definitions/Address"))
240− , ("age", Inline mempty
241− { _schemaType = SchemaInteger
242− , _schemaFormat = Just "int32"
243− , _schemaSchemaCommon = mempty
244− { _schemaCommonMinimum = Just 0 } } ) ] }
241+ , ("age", Inline $ mempty
242+ & schemaMinimum ?~ 0
243+ & schemaType .~ SchemaInteger
244+ & schemaFormat ?~ "int32" ) ]
245245
246246schemaSimpleModelExampleJSON :: Value
247247schemaSimpleModelExampleJSON = [aesonQQ|
@@ -268,9 +268,8 @@ schemaSimpleModelExampleJSON = [aesonQQ|
268268
269269schemaModelDictExample :: Schema
270270schemaModelDictExample = mempty
271− { _schemaType = SchemaObject
272− , _schemaAdditionalProperties = Just mempty
273− { _schemaType = SchemaString } }
271+ & schemaType .~ SchemaObject
272+ & schemaAdditionalProperties ?~ (mempty & schemaType .~ SchemaString)
274273
275274schemaModelDictExampleJSON :: Value
276275schemaModelDictExampleJSON = [aesonQQ|
@@ -283,14 +282,12 @@ schemaModelDictExampleJSON = [aesonQQ|
283282|]
284283
285284schemaWithExampleExample :: Schema
286−schemaWithExampleExample = mempty
287− { _schemaType = SchemaObject
288− , _schemaProperties =
289− [ ("id", Inline mempty
290− { _schemaType = SchemaInteger
291− , _schemaFormat = Just "int64" })
292− , ("name", Inline mempty
293− { _schemaType = SchemaString }) ]
285+schemaWithExampleExample = (mempty & schemaType .~ SchemaObject)
286+ { _schemaProperties =
287+ [ ("id", Inline $ mempty
288+ & schemaType .~ SchemaInteger
289+ & schemaFormat ?~ "int64" )
290+ , ("name", Inline (mempty & schemaType .~ SchemaString)) ]
294291 , _schemaRequired = [ "name" ]
295292 , _schemaExample = Just [aesonQQ|
296293 {
@@ -329,21 +326,19 @@ schemaWithExampleExampleJSON = [aesonQQ|
329326definitionsExample :: HashMap Text Schema
330327definitionsExample =
331328 [ ("Category", mempty
332− { _schemaType = SchemaObject
333− , _schemaProperties =
334− [ ("id", Inline mempty
335− { _schemaType = SchemaInteger
336− , _schemaFormat = Just "int64" })
337− , ("name", Inline mempty
338− { _schemaType = SchemaString }) ] })
329+ & schemaType .~ SchemaObject
330+ & schemaProperties .~
331+ [ ("id", Inline $ mempty
332+ & schemaType .~ SchemaInteger
333+ & schemaFormat ?~ "int64")
334+ , ("name", Inline (mempty & schemaType .~ SchemaString)) ] )
339335 , ("Tag", mempty
340− { _schemaType = SchemaObject
341− , _schemaProperties =
342− [ ("id", Inline mempty
343− { _schemaType = SchemaInteger
344− , _schemaFormat = Just "int64" })
345− , ("name", Inline mempty
346− { _schemaType = SchemaString }) ] }) ]
336+ & schemaType .~ SchemaObject
337+ & schemaProperties .~
338+ [ ("id", Inline $ mempty
339+ & schemaType .~ SchemaInteger
340+ & schemaFormat ?~ "int64")
341+ , ("name", Inline (mempty & schemaType .~ SchemaString)) ] ) ]
347342
348343definitionsExampleJSON :: Value
349344definitionsExampleJSON = [aesonQQ|
@@ -385,18 +380,18 @@ paramsDefinitionExample =
385380 { _paramName = "skip"
386381 , _paramDescription = Just "number of items to skip"
387382 , _paramRequired = Just True
388− , _paramSchema = ParamOther mempty
389− { _paramOtherSchemaIn = ParamQuery
390− , _paramOtherSchemaType = ParamInteger
391− , _paramOtherSchemaFormat = Just "int32" } })
383+ , _paramSchema = ParamOther $ mempty
384+ & paramOtherSchemaIn .~ ParamQuery
385+ & schemaType .~ ParamInteger
386+ & schemaFormat ?~ "int32" })
392387 , ("limitParam", mempty
393388 { _paramName = "limit"
394389 , _paramDescription = Just "max records to return"
395390 , _paramRequired = Just True
396− , _paramSchema = ParamOther mempty
397− { _paramOtherSchemaIn = ParamQuery
398− , _paramOtherSchemaType = ParamInteger
399− , _paramOtherSchemaFormat = Just "int32" } }) ]
391+ , _paramSchema = ParamOther $ mempty
392+ & paramOtherSchemaIn .~ ParamQuery
393+ & schemaType .~ ParamInteger
394+ & schemaFormat ?~ "int32" }) ]
400395
401396paramsDefinitionExampleJSON :: Value
402397paramsDefinitionExampleJSON = [aesonQQ|
@@ -500,20 +495,18 @@ swaggerExample = mempty
500495 { _operationResponses = mempty
501496 { _responsesResponses =
502497 [ (200, Inline mempty
503− { _responseSchema = Just $ Inline mempty
498+ { _responseSchema = Just $ Inline (mempty & schemaType .~ SchemaObject)
504499 { _schemaExample = Just [aesonQQ|
505500 {
506501 "created": 100,
507502 "description": "get milk"
508503 } |]
509− , _schemaType = SchemaObject
510504 , _schemaDescription = Just "This is some real Todo right here"
511505 , _schemaProperties =
512− [ ("created", Inline mempty
513− { _schemaType = SchemaInteger
514− , _schemaFormat = Just "int32" })
515− , ("description", Inline mempty
516− { _schemaType = SchemaString }) ] }
506+ [ ("created", Inline $ mempty
507+ & schemaType .~ SchemaInteger
508+ & schemaFormat ?~ "int32")
509+ , ("description", Inline (mempty & schemaType .~ SchemaString)) ] }
517510 , _responseDescription = "OK" }) ] }
518511 , _operationProduces = Just (MimeList [ "application/json" ])
519512 , _operationParameters =
@@ -521,9 +514,9 @@ swaggerExample = mempty
521514 { _paramRequired = Just True
522515 , _paramName = "id"
523516 , _paramDescription = Just "TodoId param"
524− , _paramSchema = ParamOther mempty
525− { _paramOtherSchemaIn = ParamPath
526− , _paramOtherSchemaType = ParamString } } ]
517+ , _paramSchema = ParamOther $ mempty
518+ & paramOtherSchemaIn .~ ParamPath
519+ & schemaType .~ ParamString } ]
527520 , _operationTags = [ "todo" ] } }) ] } }
528521
529522swaggerExampleJSON :: Value