@@ -13,7 +13,7 @@ import Data.Text (Text)
14import Data.Swagger
14import Data.Swagger
15import SpecCommon
15import SpecCommon
16−import Test.Hspec
16+import Test.Hspec hiding (example)
18spec :: Spec
18spec :: Spec
@@ -44,13 +44,13 @@ main = hspec spec
44-- =======================================================================
44-- =======================================================================
46infoExample :: Info
46infoExample :: Info
47−infoExample = Info
47+infoExample = mempty
48− { _infoTitle = "Swagger Sample App"
48+ & title .~ "Swagger Sample App"
49− , _infoDescription = Just "This is a sample server Petstore server."
49+ & description ?~ "This is a sample server Petstore server."
50− , _infoTermsOfService = Just "http://swagger.io/terms/"
50+ & termsOfService ?~ "http://swagger.io/terms/"
51− , _infoContact = Just contactExample
51+ & contact ?~ contactExample
52− , _infoLicense = Just licenseExample
52+ & license ?~ licenseExample
53− , _infoVersion = "1.0.1" }
53+ & version .~ "1.0.1"
55infoExampleJSON :: Value
55infoExampleJSON :: Value
56infoExampleJSON = [aesonQQ|
56infoExampleJSON = [aesonQQ|
@@ -76,10 +76,10 @@ infoExampleJSON = [aesonQQ|
76-- =======================================================================
76-- =======================================================================
78contactExample :: Contact
78contactExample :: Contact
79−contactExample = Contact
79+contactExample = mempty
80− { _contactName = Just "API Support"
80+ & name ?~ "API Support"
81− , _contactUrl = Just (URL "http://www.swagger.io/support")
81+ & url ?~ URL "http://www.swagger.io/support"
82− , _contactEmail = Just "support@swagger.io" }
82+ & email ?~ "support@swagger.io"
84contactExampleJSON :: Value
84contactExampleJSON :: Value
85contactExampleJSON = [aesonQQ|
85contactExampleJSON = [aesonQQ|
@@ -95,9 +95,7 @@ contactExampleJSON = [aesonQQ|
95-- =======================================================================
95-- =======================================================================
97licenseExample :: License
97licenseExample :: 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"))
102licenseExampleJSON :: Value
100licenseExampleJSON :: Value
103licenseExampleJSON = [aesonQQ|
101licenseExampleJSON = [aesonQQ|
@@ -114,46 +112,39 @@ licenseExampleJSON = [aesonQQ|
115operationExample :: Operation
113operationExample :: Operation
116operationExample = mempty
114operationExample = mempty
117− { _operationTags = ["pet"]
115+ & tags .~ ["pet"]
118− , _operationSummary = Just "Updates a pet in the store with form data"
116+ & summary ?~ "Updates a pet in the store with form data"
119− , _operationDescription = Just ""
117+ & description ?~ ""
120− , _operationOperationId = Just "updatePetWithForm"
118+ & operationId ?~ "updatePetWithForm"
121− , _operationConsumes = Just (MimeList ["application/x-www-form-urlencoded"])
119+ & consumes ?~ MimeList ["application/x-www-form-urlencoded"]
122− , _operationProduces = Just (MimeList ["application/json", "application/xml"])
120+ & produces ?~ MimeList ["application/json", "application/xml"]
123− , _operationParameters = params
124− , _operationResponses = responses
125− , _operationSecurity = security
128− security = [SecurityRequirement [("petstore_auth", ["write:pets", "read:pets"])]]
131− { _responsesResponses =
132− [ (200, Inline mempty { _responseDescription = "Pet updated." })
133− , (405, Inline mempty { _responseDescription = "Invalid input" }) ] }
135− params = map Inline
121+ & parameters .~ map Inline
136− [ Param
122+ [ mempty
137− { _paramName = "petId"
123+ & name .~ "petId"
138− , _paramDescription = Just "ID of pet that needs to be updated"
124+ & description ?~ "ID of pet that needs to be updated"
139− , _paramRequired = Just True
125+ & required ?~ True
140− , _paramSchema = ParamOther (stringSchema ParamPath) }
126+ & schema .~ ParamOther (stringSchema ParamPath)
141− , Param
127+ , mempty
142− { _paramName = "name"
128+ & name .~ "name"
143− , _paramDescription = Just "Updated name of the pet"
129+ & description ?~ "Updated name of the pet"
144− , _paramRequired = Just False
130+ & required ?~ False
145− , _paramSchema = ParamOther (stringSchema ParamFormData) }
131+ & schema .~ ParamOther (stringSchema ParamFormData)
146− , Param
132+ , mempty
147− { _paramName = "status"
133+ & name .~ "status"
148− , _paramDescription = Just "Updated status of the pet"
134+ & description ?~ "Updated status of the pet"
149− , _paramRequired = Just False
135+ & required ?~ False
150− , _paramSchema = ParamOther (stringSchema ParamFormData) }
136+ & schema .~ ParamOther (stringSchema ParamFormData)
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"])]]
153 stringSchema :: ParamLocation -> ParamOtherSchema
144 stringSchema :: ParamLocation -> ParamOtherSchema
154− stringSchema i = mempty
145+ stringSchema loc = mempty
155− & paramOtherSchemaIn .~ i
146+ & in_ .~ loc
156− & schemaType .~ SwaggerString
147+ & type_ .~ SwaggerString
158operationExampleJSON :: Value
149operationExampleJSON :: Value
159operationExampleJSON = [aesonQQ|
150operationExampleJSON = [aesonQQ|
@@ -219,8 +210,8 @@ operationExampleJSON = [aesonQQ|
220schemaPrimitiveExample :: Schema
211schemaPrimitiveExample :: Schema
221schemaPrimitiveExample = mempty
212schemaPrimitiveExample = mempty
222− & schemaType .~ SwaggerString
213+ & type_ .~ SwaggerString
223− & schemaFormat ?~ "email"
214+ & format ?~ "email"
225schemaPrimitiveExampleJSON :: Value
216schemaPrimitiveExampleJSON :: Value
226schemaPrimitiveExampleJSON = [aesonQQ|
217schemaPrimitiveExampleJSON = [aesonQQ|
@@ -232,15 +223,15 @@ schemaPrimitiveExampleJSON = [aesonQQ|
233schemaSimpleModelExample :: Schema
224schemaSimpleModelExample :: Schema
234schemaSimpleModelExample = mempty
225schemaSimpleModelExample = mempty
235− & schemaType .~ SwaggerObject
226+ & type_ .~ SwaggerObject
236− & schemaRequired .~ [ "name" ]
227+ & required .~ [ "name" ]
237− & schemaProperties .~
228+ & properties .~
238− [ ("name", Inline (mempty & schemaType .~ SwaggerString))
229+ [ ("name", Inline (mempty & type_ .~ SwaggerString))
239 , ("address", Ref (Reference "Address"))
230 , ("address", Ref (Reference "Address"))
240 , ("age", Inline $ mempty
231 , ("age", Inline $ mempty
241− & schemaMinimum ?~ 0
232+ & minimum_ ?~ 0
242− & schemaType .~ SwaggerInteger
233+ & type_ .~ SwaggerInteger
243− & schemaFormat ?~ "int32" ) ]
234+ & format ?~ "int32" ) ]
245schemaSimpleModelExampleJSON :: Value
236schemaSimpleModelExampleJSON :: Value
246schemaSimpleModelExampleJSON = [aesonQQ|
237schemaSimpleModelExampleJSON = [aesonQQ|
@@ -267,8 +258,8 @@ schemaSimpleModelExampleJSON = [aesonQQ|
268schemaModelDictExample :: Schema
259schemaModelDictExample :: Schema
269schemaModelDictExample = mempty
260schemaModelDictExample = mempty
270− & schemaType .~ SwaggerObject
261+ & type_ .~ SwaggerObject
271− & schemaAdditionalProperties ?~ (mempty & schemaType .~ SwaggerString)
262+ & additionalProperties ?~ (mempty & type_ .~ SwaggerString)
273schemaModelDictExampleJSON :: Value
264schemaModelDictExampleJSON :: Value
274schemaModelDictExampleJSON = [aesonQQ|
265schemaModelDictExampleJSON = [aesonQQ|
@@ -281,19 +272,21 @@ schemaModelDictExampleJSON = [aesonQQ|
283schemaWithExampleExample :: Schema
274schemaWithExampleExample :: Schema
284−schemaWithExampleExample = (mempty & schemaType .~ SwaggerObject)
275+schemaWithExampleExample = mempty
285− { _schemaProperties =
276+ & type_ .~ SwaggerObject
286 [ ("id", Inline $ mempty
278 [ ("id", Inline $ mempty
287− & schemaType .~ SwaggerInteger
279+ & type_ .~ SwaggerInteger
288− & schemaFormat ?~ "int64" )
280+ & format ?~ "int64" )
289− , ("name", Inline (mempty & schemaType .~ SwaggerString)) ]
281+ , ("name", Inline $ mempty
290− , _schemaRequired = [ "name" ]
282+ & type_ .~ SwaggerString) ]
291− , _schemaExample = Just [aesonQQ|
283+ & required .~ [ "name" ]
284+ & example ?~ [aesonQQ|
293− "name": "Puma",
286+ "name": "Puma",
298schemaWithExampleExampleJSON :: Value
291schemaWithExampleExampleJSON :: Value
299schemaWithExampleExampleJSON = [aesonQQ|
292schemaWithExampleExampleJSON = [aesonQQ|
@@ -325,19 +318,19 @@ schemaWithExampleExampleJSON = [aesonQQ|
325definitionsExample :: HashMap Text Schema
318definitionsExample :: HashMap Text Schema
326definitionsExample =
319definitionsExample =
327 [ ("Category", mempty
320 [ ("Category", mempty
328− & schemaType .~ SwaggerObject
321+ & type_ .~ SwaggerObject
329− & schemaProperties .~
322+ & properties .~
330 [ ("id", Inline $ mempty
323 [ ("id", Inline $ mempty
331− & schemaType .~ SwaggerInteger
324+ & type_ .~ SwaggerInteger
332− & schemaFormat ?~ "int64")
325+ & format ?~ "int64")
333− , ("name", Inline (mempty & schemaType .~ SwaggerString)) ] )
326+ , ("name", Inline (mempty & type_ .~ SwaggerString)) ] )
334 , ("Tag", mempty
327 , ("Tag", mempty
335− & schemaType .~ SwaggerObject
328+ & type_ .~ SwaggerObject
336− & schemaProperties .~
329+ & properties .~
337 [ ("id", Inline $ mempty
330 [ ("id", Inline $ mempty
338− & schemaType .~ SwaggerInteger
331+ & type_ .~ SwaggerInteger
339− & schemaFormat ?~ "int64")
332+ & format ?~ "int64")
340− , ("name", Inline (mempty & schemaType .~ SwaggerString)) ] ) ]
333+ , ("name", Inline (mempty & type_ .~ SwaggerString)) ] ) ]
342definitionsExampleJSON :: Value
335definitionsExampleJSON :: Value
343definitionsExampleJSON = [aesonQQ|
336definitionsExampleJSON = [aesonQQ|
@@ -376,21 +369,21 @@ definitionsExampleJSON = [aesonQQ|
376paramsDefinitionExample :: HashMap Text Param
369paramsDefinitionExample :: HashMap Text Param
377paramsDefinitionExample =
370paramsDefinitionExample =
378 [ ("skipParam", mempty
371 [ ("skipParam", mempty
379− { _paramName = "skip"
372+ & name .~ "skip"
380− , _paramDescription = Just "number of items to skip"
373+ & description ?~ "number of items to skip"
381− , _paramRequired = Just True
374+ & required ?~ True
382− , _paramSchema = ParamOther $ mempty
375+ & schema .~ ParamOther (mempty
383− & paramOtherSchemaIn .~ ParamQuery
376+ & in_ .~ ParamQuery
384− & schemaType .~ SwaggerInteger
377+ & type_ .~ SwaggerInteger
385− & schemaFormat ?~ "int32" })
378+ & format ?~ "int32" ))
386 , ("limitParam", mempty
379 , ("limitParam", mempty
387− { _paramName = "limit"
380+ & name .~ "limit"
388− , _paramDescription = Just "max records to return"
381+ & description ?~ "max records to return"
389− , _paramRequired = Just True
382+ & required ?~ True
390− , _paramSchema = ParamOther $ mempty
383+ & schema .~ ParamOther (mempty
391− & paramOtherSchemaIn .~ ParamQuery
384+ & in_ .~ ParamQuery
392− & schemaType .~ SwaggerInteger
385+ & type_ .~ SwaggerInteger
393− & schemaFormat ?~ "int32" }) ]
386+ & format ?~ "int32" )) ]
395paramsDefinitionExampleJSON :: Value
388paramsDefinitionExampleJSON :: Value
396paramsDefinitionExampleJSON = [aesonQQ|
389paramsDefinitionExampleJSON = [aesonQQ|
@@ -420,8 +413,8 @@ paramsDefinitionExampleJSON = [aesonQQ|
421responsesDefinitionExample :: HashMap Text Response
414responsesDefinitionExample :: HashMap Text Response
422responsesDefinitionExample =
415responsesDefinitionExample =
423− [ ("NotFound", mempty { _responseDescription = "Entity not found." })
416+ [ ("NotFound", mempty & description .~ "Entity not found.")
424− , ("IllegalInput", mempty { _responseDescription = "Illegal input for operation." }) ]
417+ , ("IllegalInput", mempty & description .~ "Illegal input for operation.") ]
426responsesDefinitionExampleJSON :: Value
419responsesDefinitionExampleJSON :: Value
427responsesDefinitionExampleJSON = [aesonQQ|
420responsesDefinitionExampleJSON = [aesonQQ|
@@ -478,45 +471,39 @@ securityDefinitionsExampleJSON = [aesonQQ|
479swaggerExample :: Swagger
472swaggerExample :: Swagger
480swaggerExample = mempty
473swaggerExample = mempty
481− { _basePath = Just "/"
474+ & basePath ?~ "/"
482− , _schemes = Just [Http]
475+ & schemes ?~ [Http]
483− , _info = mempty
476+ & info .~ (mempty
484− { _infoVersion = "1.0"
477+ & version .~ "1.0"
485− , _infoTitle = "Todo API"
478+ & title .~ "Todo API"
486− , _infoLicense = Just License
487− { _licenseName = "MIT"
488− , _licenseUrl = Just (URL "http://mit.com") }
479+ & license ?~ License "MIT" (Just (URL "http://mit.com"))
489− , _infoDescription = Just "This is a an API that tests servant-swagger support for a Todo API" }
480+ & description ?~ "This is a an API that tests servant-swagger support for a Todo API")
492− [ ("/todo/{id}", mempty
481+ & paths.at "/todo/{id}" ?~ (mempty & get ?~ ((mempty :: Operation)
493− { _pathItemGet = Just mempty
494− { _operationResponses = mempty
495− { _responsesResponses =
496− [ (200, Inline mempty
482+ & at 200 ?~ Inline (mempty
497− { _responseSchema = Just $ Inline (mempty & schemaType .~ SwaggerObject)
483+ & description .~ "OK"
498− { _schemaExample = Just [aesonQQ|
484+ & schema ?~ Inline (mempty
485+ & type_ .~ SwaggerObject
486+ & example ?~ [aesonQQ|
500− "created": 100,
488+ "created": 100,
501− "description": "get milk"
489+ "description": "get milk"
503− , _schemaDescription = Just "This is some real Todo right here"
491+ & description ?~ "This is some real Todo right here"
504− , _schemaProperties =
492+ & properties .~
505− [ ("created", Inline $ mempty
493+ [ ("created", Inline $ mempty
506− & schemaType .~ SwaggerInteger
494+ & type_ .~ SwaggerInteger
507− & schemaFormat ?~ "int32")
495+ & format ?~ "int32")
508− , ("description", Inline (mempty & schemaType .~ SwaggerString)) ] }
496+ , ("description", Inline (mempty & type_ .~ SwaggerString))]))
509− , _responseDescription = "OK" }) ] }
510− , _operationProduces = Just (MimeList [ "application/json" ])
497+ & produces ?~ MimeList [ "application/json" ]
511− , _operationParameters =
498+ & parameters .~
512− [ Inline mempty
499+ [ Inline $ mempty
513− { _paramRequired = Just True
500+ & required ?~ True
514− , _paramName = "id"
501+ & name .~ "id"
515− , _paramDescription = Just "TodoId param"
502+ & description ?~ "TodoId param"
516− , _paramSchema = ParamOther $ mempty
503+ & schema .~ ParamOther (mempty
517− & paramOtherSchemaIn .~ ParamPath
504+ & in_ .~ ParamPath
518− & schemaType .~ SwaggerString } ]
505+ & type_ .~ SwaggerString ) ]
519− , _operationTags = [ "todo" ] } }) ] } }
506+ & tags .~ [ "todo" ] ))
521swaggerExampleJSON :: Value
508swaggerExampleJSON :: Value
522swaggerExampleJSON = [aesonQQ|
509swaggerExampleJSON = [aesonQQ|