@@ -4,12 +4,15 @@
4{-# LANGUAGE QuasiQuotes #-}
4{-# LANGUAGE QuasiQuotes #-}
5module Data.SwaggerSpec where
5module Data.SwaggerSpec where
7import Data.Aeson
9import Data.Aeson
8import Data.Aeson.QQ
10import Data.Aeson.QQ
9import Data.HashMap.Strict (HashMap)
11import Data.HashMap.Strict (HashMap)
10import Data.Text (Text)
12import Data.Text (Text)
12import Data.Swagger
14import Data.Swagger
15+import Data.Swagger.Lens
13import SpecCommon
16import SpecCommon
14import Test.Hspec
17import Test.Hspec
@@ -148,10 +151,10 @@ operationExample = mempty
148 , _paramSchema = ParamOther (stringSchema ParamFormData) }
151 , _paramSchema = ParamOther (stringSchema ParamFormData) }
154+ stringSchema :: ParamLocation -> ParamOtherSchema
151 stringSchema i = mempty
155 stringSchema i = mempty
152− { _paramOtherSchemaIn = i
156+ & paramOtherSchemaIn .~ i
153− , _paramOtherSchemaType = ParamString
157+ & schemaType .~ ParamString
156operationExampleJSON :: Value
159operationExampleJSON :: Value
157operationExampleJSON = [aesonQQ|
160operationExampleJSON = [aesonQQ|
@@ -217,9 +220,8 @@ operationExampleJSON = [aesonQQ|
218schemaPrimitiveExample :: Schema
221schemaPrimitiveExample :: Schema
219schemaPrimitiveExample = mempty
222schemaPrimitiveExample = mempty
220− { _schemaType = SchemaString
223+ & schemaType .~ SchemaString
221− , _schemaFormat = Just "email"
224+ & schemaFormat ?~ "email"
224schemaPrimitiveExampleJSON :: Value
226schemaPrimitiveExampleJSON :: Value
225schemaPrimitiveExampleJSON = [aesonQQ|
227schemaPrimitiveExampleJSON = [aesonQQ|
@@ -231,17 +233,15 @@ schemaPrimitiveExampleJSON = [aesonQQ|
232schemaSimpleModelExample :: Schema
234schemaSimpleModelExample :: Schema
233schemaSimpleModelExample = mempty
235schemaSimpleModelExample = mempty
234− { _schemaType = SchemaObject
236+ & schemaType .~ SchemaObject
235− , _schemaRequired = [ "name" ]
237+ & schemaRequired .~ [ "name" ]
236− , _schemaProperties =
238+ & schemaProperties .~
237− [ ("name", Inline mempty
239+ [ ("name", Inline (mempty & schemaType .~ SchemaString))
238− { _schemaType = SchemaString } )
239 , ("address", Ref (Reference "#/definitions/Address"))
240 , ("address", Ref (Reference "#/definitions/Address"))
240− , ("age", Inline mempty
241+ , ("age", Inline $ mempty
242+ & schemaMinimum ?~ 0
241− { _schemaType = SchemaInteger
243+ & schemaType .~ SchemaInteger
242− , _schemaFormat = Just "int32"
244+ & schemaFormat ?~ "int32" ) ]
243− , _schemaSchemaCommon = mempty
244− { _schemaCommonMinimum = Just 0 } } ) ] }
246schemaSimpleModelExampleJSON :: Value
246schemaSimpleModelExampleJSON :: Value
247schemaSimpleModelExampleJSON = [aesonQQ|
247schemaSimpleModelExampleJSON = [aesonQQ|
@@ -268,9 +268,8 @@ schemaSimpleModelExampleJSON = [aesonQQ|
269schemaModelDictExample :: Schema
269schemaModelDictExample :: Schema
270schemaModelDictExample = mempty
270schemaModelDictExample = mempty
271− { _schemaType = SchemaObject
271+ & schemaType .~ SchemaObject
272− , _schemaAdditionalProperties = Just mempty
272+ & schemaAdditionalProperties ?~ (mempty & schemaType .~ SchemaString)
273− { _schemaType = SchemaString } }
275schemaModelDictExampleJSON :: Value
274schemaModelDictExampleJSON :: Value
276schemaModelDictExampleJSON = [aesonQQ|
275schemaModelDictExampleJSON = [aesonQQ|
@@ -283,14 +282,12 @@ schemaModelDictExampleJSON = [aesonQQ|
285schemaWithExampleExample :: Schema
284schemaWithExampleExample :: Schema
286−schemaWithExampleExample = mempty
285+schemaWithExampleExample = (mempty & schemaType .~ SchemaObject)
287− { _schemaType = SchemaObject
288− , _schemaProperties =
286+ { _schemaProperties =
289− [ ("id", Inline mempty
287+ [ ("id", Inline $ mempty
290− { _schemaType = SchemaInteger
288+ & schemaType .~ SchemaInteger
291− , _schemaFormat = Just "int64" })
289+ & schemaFormat ?~ "int64" )
292− , ("name", Inline mempty
290+ , ("name", Inline (mempty & schemaType .~ SchemaString)) ]
293− { _schemaType = SchemaString }) ]
294 , _schemaRequired = [ "name" ]
291 , _schemaRequired = [ "name" ]
295 , _schemaExample = Just [aesonQQ|
292 , _schemaExample = Just [aesonQQ|
@@ -329,21 +326,19 @@ schemaWithExampleExampleJSON = [aesonQQ|
329definitionsExample :: HashMap Text Schema
326definitionsExample :: HashMap Text Schema
330definitionsExample =
327definitionsExample =
331 [ ("Category", mempty
328 [ ("Category", mempty
332− { _schemaType = SchemaObject
329+ & schemaType .~ SchemaObject
333− , _schemaProperties =
330+ & schemaProperties .~
334− [ ("id", Inline mempty
331+ [ ("id", Inline $ mempty
335− { _schemaType = SchemaInteger
332+ & schemaType .~ SchemaInteger
336− , _schemaFormat = Just "int64" })
333+ & schemaFormat ?~ "int64")
337− , ("name", Inline mempty
334+ , ("name", Inline (mempty & schemaType .~ SchemaString)) ] )
338− { _schemaType = SchemaString }) ] })
339 , ("Tag", mempty
335 , ("Tag", mempty
340− { _schemaType = SchemaObject
336+ & schemaType .~ SchemaObject
341− , _schemaProperties =
337+ & schemaProperties .~
342− [ ("id", Inline mempty
338+ [ ("id", Inline $ mempty
343− { _schemaType = SchemaInteger
339+ & schemaType .~ SchemaInteger
344− , _schemaFormat = Just "int64" })
340+ & schemaFormat ?~ "int64")
345− , ("name", Inline mempty
341+ , ("name", Inline (mempty & schemaType .~ SchemaString)) ] ) ]
346− { _schemaType = SchemaString }) ] }) ]
348definitionsExampleJSON :: Value
343definitionsExampleJSON :: Value
349definitionsExampleJSON = [aesonQQ|
344definitionsExampleJSON = [aesonQQ|
@@ -385,18 +380,18 @@ paramsDefinitionExample =
385 { _paramName = "skip"
380 { _paramName = "skip"
386 , _paramDescription = Just "number of items to skip"
381 , _paramDescription = Just "number of items to skip"
387 , _paramRequired = Just True
382 , _paramRequired = Just True
388− , _paramSchema = ParamOther mempty
383+ , _paramSchema = ParamOther $ mempty
389− { _paramOtherSchemaIn = ParamQuery
384+ & paramOtherSchemaIn .~ ParamQuery
390− , _paramOtherSchemaType = ParamInteger
385+ & schemaType .~ ParamInteger
391− , _paramOtherSchemaFormat = Just "int32" } })
386+ & schemaFormat ?~ "int32" })
392 , ("limitParam", mempty
387 , ("limitParam", mempty
393 { _paramName = "limit"
388 { _paramName = "limit"
394 , _paramDescription = Just "max records to return"
389 , _paramDescription = Just "max records to return"
395 , _paramRequired = Just True
390 , _paramRequired = Just True
396− , _paramSchema = ParamOther mempty
391+ , _paramSchema = ParamOther $ mempty
397− { _paramOtherSchemaIn = ParamQuery
392+ & paramOtherSchemaIn .~ ParamQuery
398− , _paramOtherSchemaType = ParamInteger
393+ & schemaType .~ ParamInteger
399− , _paramOtherSchemaFormat = Just "int32" } }) ]
394+ & schemaFormat ?~ "int32" }) ]
401paramsDefinitionExampleJSON :: Value
396paramsDefinitionExampleJSON :: Value
402paramsDefinitionExampleJSON = [aesonQQ|
397paramsDefinitionExampleJSON = [aesonQQ|
@@ -500,20 +495,18 @@ swaggerExample = mempty
500 { _operationResponses = mempty
495 { _operationResponses = mempty
501 { _responsesResponses =
496 { _responsesResponses =
502 [ (200, Inline mempty
497 [ (200, Inline mempty
503− { _responseSchema = Just $ Inline mempty
498+ { _responseSchema = Just $ Inline (mempty & schemaType .~ SchemaObject)
504 { _schemaExample = Just [aesonQQ|
499 { _schemaExample = Just [aesonQQ|
506 "created": 100,
501 "created": 100,
507 "description": "get milk"
502 "description": "get milk"
509− , _schemaType = SchemaObject
510 , _schemaDescription = Just "This is some real Todo right here"
504 , _schemaDescription = Just "This is some real Todo right here"
511 , _schemaProperties =
505 , _schemaProperties =
512− [ ("created", Inline mempty
506+ [ ("created", Inline $ mempty
513− { _schemaType = SchemaInteger
507+ & schemaType .~ SchemaInteger
514− , _schemaFormat = Just "int32" })
508+ & schemaFormat ?~ "int32")
515− , ("description", Inline mempty
509+ , ("description", Inline (mempty & schemaType .~ SchemaString)) ] }
516− { _schemaType = SchemaString }) ] }
517 , _responseDescription = "OK" }) ] }
510 , _responseDescription = "OK" }) ] }
518 , _operationProduces = Just (MimeList [ "application/json" ])
511 , _operationProduces = Just (MimeList [ "application/json" ])
519 , _operationParameters =
512 , _operationParameters =
@@ -521,9 +514,9 @@ swaggerExample = mempty
521 { _paramRequired = Just True
514 { _paramRequired = Just True
522 , _paramName = "id"
515 , _paramName = "id"
523 , _paramDescription = Just "TodoId param"
516 , _paramDescription = Just "TodoId param"
524− , _paramSchema = ParamOther mempty
517+ , _paramSchema = ParamOther $ mempty
525− { _paramOtherSchemaIn = ParamPath
518+ & paramOtherSchemaIn .~ ParamPath
526− , _paramOtherSchemaType = ParamString } } ]
519+ & schemaType .~ ParamString } ]
527 , _operationTags = [ "todo" ] } }) ] } }
520 , _operationTags = [ "todo" ] } }) ] } }
529swaggerExampleJSON :: Value
522swaggerExampleJSON :: Value