@@ -13,7 +13,7 @@ import Data.Text (Text)
1313
1414import Data.Swagger
1515import SpecCommon
16−import Test.Hspec
16+import Test.Hspec hiding (example)
1717
1818spec :: Spec
1919spec = do
@@ -44,13 +44,13 @@ main = hspec spec
4444-- =======================================================================
4545
4646infoExample :: Info
47−infoExample = Info
48− { _infoTitle = "Swagger Sample App"
49− , _infoDescription = Just "This is a sample server Petstore server."
50− , _infoTermsOfService = Just "http://swagger.io/terms/"
51− , _infoContact = Just contactExample
52− , _infoLicense = Just licenseExample
53− , _infoVersion = "1.0.1" }
47+infoExample = mempty
48+ & title .~ "Swagger Sample App"
49+ & description ?~ "This is a sample server Petstore server."
50+ & termsOfService ?~ "http://swagger.io/terms/"
51+ & contact ?~ contactExample
52+ & license ?~ licenseExample
53+ & version .~ "1.0.1"
5454
5555infoExampleJSON :: Value
5656infoExampleJSON = [aesonQQ|
@@ -76,10 +76,10 @@ infoExampleJSON = [aesonQQ|
7676-- =======================================================================
7777
7878contactExample :: Contact
79−contactExample = Contact
80− { _contactName = Just "API Support"
81− , _contactUrl = Just (URL "http://www.swagger.io/support")
82− , _contactEmail = Just "support@swagger.io" }
79+contactExample = mempty
80+ & name ?~ "API Support"
81+ & url ?~ URL "http://www.swagger.io/support"
82+ & email ?~ "support@swagger.io"
8383
8484contactExampleJSON :: Value
8585contactExampleJSON = [aesonQQ|
@@ -95,9 +95,7 @@ contactExampleJSON = [aesonQQ|
9595-- =======================================================================
9696
9797licenseExample :: License
98−licenseExample = License
99− { _licenseName = "Apache 2.0"
100− , _licenseUrl = Just (URL "http://www.apache.org/licenses/LICENSE-2.0.html") }
98+licenseExample = License "Apache 2.0" (Just (URL "http://www.apache.org/licenses/LICENSE-2.0.html"))
10199
102100licenseExampleJSON :: Value
103101licenseExampleJSON = [aesonQQ|
@@ -114,46 +112,39 @@ licenseExampleJSON = [aesonQQ|
114112
115113operationExample :: Operation
116114operationExample = mempty
117− { _operationTags = ["pet"]
118− , _operationSummary = Just "Updates a pet in the store with form data"
119− , _operationDescription = Just ""
120− , _operationOperationId = Just "updatePetWithForm"
121− , _operationConsumes = Just (MimeList ["application/x-www-form-urlencoded"])
122− , _operationProduces = Just (MimeList ["application/json", "application/xml"])
123− , _operationParameters = params
124− , _operationResponses = responses
125− , _operationSecurity = security
126− }
127− where
128− security = [SecurityRequirement [("petstore_auth", ["write:pets", "read:pets"])]]
129−
130− responses = mempty
131− { _responsesResponses =
132− [ (200, Inline mempty { _responseDescription = "Pet updated." })
133− , (405, Inline mempty { _responseDescription = "Invalid input" }) ] }
134−
135− params = map Inline
136− [ Param
137− { _paramName = "petId"
138− , _paramDescription = Just "ID of pet that needs to be updated"
139− , _paramRequired = Just True
140− , _paramSchema = ParamOther (stringSchema ParamPath) }
141− , Param
142− { _paramName = "name"
143− , _paramDescription = Just "Updated name of the pet"
144− , _paramRequired = Just False
145− , _paramSchema = ParamOther (stringSchema ParamFormData) }
146− , Param
147− { _paramName = "status"
148− , _paramDescription = Just "Updated status of the pet"
149− , _paramRequired = Just False
150− , _paramSchema = ParamOther (stringSchema ParamFormData) }
115+ & tags .~ ["pet"]
116+ & summary ?~ "Updates a pet in the store with form data"
117+ & description ?~ ""
118+ & operationId ?~ "updatePetWithForm"
119+ & consumes ?~ MimeList ["application/x-www-form-urlencoded"]
120+ & produces ?~ MimeList ["application/json", "application/xml"]
121+ & parameters .~ map Inline
122+ [ mempty
123+ & name .~ "petId"
124+ & description ?~ "ID of pet that needs to be updated"
125+ & required ?~ True
126+ & schema .~ ParamOther (stringSchema ParamPath)
127+ , mempty
128+ & name .~ "name"
129+ & description ?~ "Updated name of the pet"
130+ & required ?~ False
131+ & schema .~ ParamOther (stringSchema ParamFormData)
132+ , mempty
133+ & name .~ "status"
134+ & description ?~ "Updated status of the pet"
135+ & required ?~ False
136+ & schema .~ ParamOther (stringSchema ParamFormData)
151137 ]
152138
139+ & responses .~ (mempty & responses .~
140+ [ (200, Inline (mempty & description .~ "Pet updated."))
141+ , (405, Inline (mempty & description .~ "Invalid input")) ])
142+ & security .~ [SecurityRequirement [("petstore_auth", ["write:pets", "read:pets"])]]
143+ where
153144 stringSchema :: ParamLocation -> ParamOtherSchema
154− stringSchema i = mempty
155− & paramOtherSchemaIn .~ i
156− & schemaType .~ SwaggerString
145+ stringSchema loc = mempty
146+ & in_ .~ loc
147+ & type_ .~ SwaggerString
157148
158149operationExampleJSON :: Value
159150operationExampleJSON = [aesonQQ|
@@ -219,8 +210,8 @@ operationExampleJSON = [aesonQQ|
219210
220211schemaPrimitiveExample :: Schema
221212schemaPrimitiveExample = mempty
222− & schemaType .~ SwaggerString
223− & schemaFormat ?~ "email"
213+ & type_ .~ SwaggerString
214+ & format ?~ "email"
224215
225216schemaPrimitiveExampleJSON :: Value
226217schemaPrimitiveExampleJSON = [aesonQQ|
@@ -232,15 +223,15 @@ schemaPrimitiveExampleJSON = [aesonQQ|
232223
233224schemaSimpleModelExample :: Schema
234225schemaSimpleModelExample = mempty
235− & schemaType .~ SwaggerObject
236− & schemaRequired .~ [ "name" ]
237− & schemaProperties .~
238− [ ("name", Inline (mempty & schemaType .~ SwaggerString))
226+ & type_ .~ SwaggerObject
227+ & required .~ [ "name" ]
228+ & properties .~
229+ [ ("name", Inline (mempty & type_ .~ SwaggerString))
239230 , ("address", Ref (Reference "Address"))
240231 , ("age", Inline $ mempty
241− & schemaMinimum ?~ 0
242− & schemaType .~ SwaggerInteger
243− & schemaFormat ?~ "int32" ) ]
232+ & minimum_ ?~ 0
233+ & type_ .~ SwaggerInteger
234+ & format ?~ "int32" ) ]
244235
245236schemaSimpleModelExampleJSON :: Value
246237schemaSimpleModelExampleJSON = [aesonQQ|
@@ -267,8 +258,8 @@ schemaSimpleModelExampleJSON = [aesonQQ|
267258
268259schemaModelDictExample :: Schema
269260schemaModelDictExample = mempty
270− & schemaType .~ SwaggerObject
271− & schemaAdditionalProperties ?~ (mempty & schemaType .~ SwaggerString)
261+ & type_ .~ SwaggerObject
262+ & additionalProperties ?~ (mempty & type_ .~ SwaggerString)
272263
273264schemaModelDictExampleJSON :: Value
274265schemaModelDictExampleJSON = [aesonQQ|
@@ -281,19 +272,21 @@ schemaModelDictExampleJSON = [aesonQQ|
281272|]
282273
283274schemaWithExampleExample :: Schema
284−schemaWithExampleExample = (mempty & schemaType .~ SwaggerObject)
285− { _schemaProperties =
275+schemaWithExampleExample = mempty
276+ & type_ .~ SwaggerObject
277+ & properties .~
286278 [ ("id", Inline $ mempty
287− & schemaType .~ SwaggerInteger
288− & schemaFormat ?~ "int64" )
289− , ("name", Inline (mempty & schemaType .~ SwaggerString)) ]
290− , _schemaRequired = [ "name" ]
291− , _schemaExample = Just [aesonQQ|
292− {
293− "name": "Puma",
294− "id": 1
295− }
296− |] }
279+ & type_ .~ SwaggerInteger
280+ & format ?~ "int64" )
281+ , ("name", Inline $ mempty
282+ & type_ .~ SwaggerString) ]
283+ & required .~ [ "name" ]
284+ & example ?~ [aesonQQ|
285+ {
286+ "name": "Puma",
287+ "id": 1
288+ }
289+ |]
297290
298291schemaWithExampleExampleJSON :: Value
299292schemaWithExampleExampleJSON = [aesonQQ|
@@ -325,19 +318,19 @@ schemaWithExampleExampleJSON = [aesonQQ|
325318definitionsExample :: HashMap Text Schema
326319definitionsExample =
327320 [ ("Category", mempty
328− & schemaType .~ SwaggerObject
329− & schemaProperties .~
321+ & type_ .~ SwaggerObject
322+ & properties .~
330323 [ ("id", Inline $ mempty
331− & schemaType .~ SwaggerInteger
332− & schemaFormat ?~ "int64")
333− , ("name", Inline (mempty & schemaType .~ SwaggerString)) ] )
324+ & type_ .~ SwaggerInteger
325+ & format ?~ "int64")
326+ , ("name", Inline (mempty & type_ .~ SwaggerString)) ] )
334327 , ("Tag", mempty
335− & schemaType .~ SwaggerObject
336− & schemaProperties .~
328+ & type_ .~ SwaggerObject
329+ & properties .~
337330 [ ("id", Inline $ mempty
338− & schemaType .~ SwaggerInteger
339− & schemaFormat ?~ "int64")
340− , ("name", Inline (mempty & schemaType .~ SwaggerString)) ] ) ]
331+ & type_ .~ SwaggerInteger
332+ & format ?~ "int64")
333+ , ("name", Inline (mempty & type_ .~ SwaggerString)) ] ) ]
341334
342335definitionsExampleJSON :: Value
343336definitionsExampleJSON = [aesonQQ|
@@ -376,21 +369,21 @@ definitionsExampleJSON = [aesonQQ|
376369paramsDefinitionExample :: HashMap Text Param
377370paramsDefinitionExample =
378371 [ ("skipParam", mempty
379− { _paramName = "skip"
380− , _paramDescription = Just "number of items to skip"
381− , _paramRequired = Just True
382− , _paramSchema = ParamOther $ mempty
383− & paramOtherSchemaIn .~ ParamQuery
384− & schemaType .~ SwaggerInteger
385− & schemaFormat ?~ "int32" })
372+ & name .~ "skip"
373+ & description ?~ "number of items to skip"
374+ & required ?~ True
375+ & schema .~ ParamOther (mempty
376+ & in_ .~ ParamQuery
377+ & type_ .~ SwaggerInteger
378+ & format ?~ "int32" ))
386379 , ("limitParam", mempty
387− { _paramName = "limit"
388− , _paramDescription = Just "max records to return"
389− , _paramRequired = Just True
390− , _paramSchema = ParamOther $ mempty
391− & paramOtherSchemaIn .~ ParamQuery
392− & schemaType .~ SwaggerInteger
393− & schemaFormat ?~ "int32" }) ]
380+ & name .~ "limit"
381+ & description ?~ "max records to return"
382+ & required ?~ True
383+ & schema .~ ParamOther (mempty
384+ & in_ .~ ParamQuery
385+ & type_ .~ SwaggerInteger
386+ & format ?~ "int32" )) ]
394387
395388paramsDefinitionExampleJSON :: Value
396389paramsDefinitionExampleJSON = [aesonQQ|
@@ -420,8 +413,8 @@ paramsDefinitionExampleJSON = [aesonQQ|
420413
421414responsesDefinitionExample :: HashMap Text Response
422415responsesDefinitionExample =
423− [ ("NotFound", mempty { _responseDescription = "Entity not found." })
424− , ("IllegalInput", mempty { _responseDescription = "Illegal input for operation." }) ]
416+ [ ("NotFound", mempty & description .~ "Entity not found.")
417+ , ("IllegalInput", mempty & description .~ "Illegal input for operation.") ]
425418
426419responsesDefinitionExampleJSON :: Value
427420responsesDefinitionExampleJSON = [aesonQQ|
@@ -478,45 +471,39 @@ securityDefinitionsExampleJSON = [aesonQQ|
478471
479472swaggerExample :: Swagger
480473swaggerExample = mempty
481− { _basePath = Just "/"
482− , _schemes = Just [Http]
483− , _info = mempty
484− { _infoVersion = "1.0"
485− , _infoTitle = "Todo API"
486− , _infoLicense = Just License
487− { _licenseName = "MIT"
488− , _licenseUrl = Just (URL "http://mit.com") }
489− , _infoDescription = Just "This is a an API that tests servant-swagger support for a Todo API" }
490− , _paths = mempty
491− { _pathsMap =
492− [ ("/todo/{id}", mempty
493− { _pathItemGet = Just mempty
494− { _operationResponses = mempty
495− { _responsesResponses =
496− [ (200, Inline mempty
497− { _responseSchema = Just $ Inline (mempty & schemaType .~ SwaggerObject)
498− { _schemaExample = Just [aesonQQ|
499− {
500− "created": 100,
501− "description": "get milk"
502− } |]
503− , _schemaDescription = Just "This is some real Todo right here"
504− , _schemaProperties =
505− [ ("created", Inline $ mempty
506− & schemaType .~ SwaggerInteger
507− & schemaFormat ?~ "int32")
508− , ("description", Inline (mempty & schemaType .~ SwaggerString)) ] }
509− , _responseDescription = "OK" }) ] }
510− , _operationProduces = Just (MimeList [ "application/json" ])
511− , _operationParameters =
512− [ Inline mempty
513− { _paramRequired = Just True
514− , _paramName = "id"
515− , _paramDescription = Just "TodoId param"
516− , _paramSchema = ParamOther $ mempty
517− & paramOtherSchemaIn .~ ParamPath
518− & schemaType .~ SwaggerString } ]
519− , _operationTags = [ "todo" ] } }) ] } }
474+ & basePath ?~ "/"
475+ & schemes ?~ [Http]
476+ & info .~ (mempty
477+ & version .~ "1.0"
478+ & title .~ "Todo API"
479+ & license ?~ License "MIT" (Just (URL "http://mit.com"))
480+ & description ?~ "This is a an API that tests servant-swagger support for a Todo API")
481+ & paths.at "/todo/{id}" ?~ (mempty & get ?~ ((mempty :: Operation)
482+ & at 200 ?~ Inline (mempty
483+ & description .~ "OK"
484+ & schema ?~ Inline (mempty
485+ & type_ .~ SwaggerObject
486+ & example ?~ [aesonQQ|
487+ {
488+ "created": 100,
489+ "description": "get milk"
490+ } |]
491+ & description ?~ "This is some real Todo right here"
492+ & properties .~
493+ [ ("created", Inline $ mempty
494+ & type_ .~ SwaggerInteger
495+ & format ?~ "int32")
496+ , ("description", Inline (mempty & type_ .~ SwaggerString))]))
497+ & produces ?~ MimeList [ "application/json" ]
498+ & parameters .~
499+ [ Inline $ mempty
500+ & required ?~ True
501+ & name .~ "id"
502+ & description ?~ "TodoId param"
503+ & schema .~ ParamOther (mempty
504+ & in_ .~ ParamPath
505+ & type_ .~ SwaggerString ) ]
506+ & tags .~ [ "todo" ] ))
520507
521508swaggerExampleJSON :: Value
522509swaggerExampleJSON = [aesonQQ|