git.iko.soy/typeable/swagger2
on master help sign in
Add Swagger object test
commit611c546ea0272d298b166c08252b31ab641d78df authorNickolay Kudasov <nickolay.kudasov@gmail.com> dateSun 8 Nov 2015, 22:32 (11 years ago) parent966767e
1 file changed+112
test/Data/SwaggerSpec.hs+112
test/Data/SwaggerSpec.hs+112
@@ -52,6 +52,7 @@ spec = do
5252 describe "Parameters Definition Object" $ parametersDefinitionExample <~> parametersDefinitionExampleJSON
5353 describe "Responses Definition Object" $ responsesDefinitionExample <~> responsesDefinitionExampleJSON
5454 describe "Security Definitions Object" $ securityDefinitionsExample <~> securityDefinitionsExampleJSON
55+ describe "Swagger Object" $ swaggerExample <~> swaggerExampleJSON
5556
5657main :: IO ()
5758main = hspec spec
@@ -496,3 +497,114 @@ securityDefinitionsExampleJSON = [aesonQQ|
496497 }
497498}
498499|]
500+
501+-- =======================================================================
502+-- Swagger object
503+-- =======================================================================
504+
505+swaggerExample :: Swagger
506+swaggerExample = mempty
507+ { swaggerBasePath = Just "/"
508+ , swaggerSchemes = Just [Http]
509+ , swaggerInfo = mempty
510+ { swaggerInfoVersion = "1.0"
511+ , swaggerInfoTitle = "Todo API"
512+ , swaggerInfoLicense = Just SwaggerLicense
513+ { swaggerLicenseName = "MIT"
514+ , swaggerLicenseUrl = Just (URL "http://mit.com") }
515+ , swaggerInfoDescription = Just "This is a an API that tests servant-swagger support for a Todo API" }
516+ , swaggerPaths = mempty
517+ { swaggerPathsMap =
518+ [ ("/todo/{id}", mempty
519+ { swaggerPathItemGet = Just mempty
520+ { swaggerOperationResponses = mempty
521+ { swaggerResponsesResponses =
522+ [ (200, mempty
523+ { swaggerResponseSchema = Just mempty
524+ { swaggerSchemaExample = Just [aesonQQ|
525+ {
526+ "created": 100,
527+ "description": "get milk"
528+ } |]
529+ , swaggerSchemaType = SwaggerSchemaObject
530+ , swaggerSchemaDescription = Just "This is some real Todo right here"
531+ , swaggerSchemaProperties =
532+ [ ("created", mempty
533+ { swaggerSchemaType = SwaggerSchemaInteger
534+ , swaggerSchemaFormat = Just "int32" })
535+ , ("description", mempty
536+ { swaggerSchemaType = SwaggerSchemaString }) ] }
537+ , swaggerResponseDescription = "OK" }) ] }
538+ , swaggerOperationProduces = Just (SwaggerMimeList [ "application/json" ])
539+ , swaggerOperationParameters =
540+ [ mempty
541+ { swaggerParameterRequired = True
542+ , swaggerParameterName = "id"
543+ , swaggerParameterDescription = Just "TodoId param"
544+ , swaggerParameterSchema = SwaggerParameterOther mempty
545+ { swaggerParameterOtherSchemaIn = SwaggerParameterPath
546+ , swaggerParameterOtherSchemaType = SwaggerParamString } } ]
547+ , swaggerOperationTags = [ "todo" ] } }) ] } }
548+
549+swaggerExampleJSON :: Value
550+swaggerExampleJSON = [aesonQQ|
551+{
552+ "swagger": "2.0",
553+ "basePath": "/",
554+ "schemes": [
555+ "http"
556+ ],
557+ "info": {
558+ "version": "1.0",
559+ "title": "Todo API",
560+ "license": {
561+ "url": "http://mit.com",
562+ "name": "MIT"
563+ },
564+ "description": "This is a an API that tests servant-swagger support for a Todo API"
565+ },
566+ "paths": {
567+ "/todo/{id}": {
568+ "get": {
569+ "responses": {
570+ "200": {
571+ "schema": {
572+ "example": {
573+ "created": 100,
574+ "description": "get milk"
575+ },
576+ "type": "object",
577+ "description": "This is some real Todo right here",
578+ "properties": {
579+ "created": {
580+ "format": "int32",
581+ "type": "integer"
582+ },
583+ "description": {
584+ "type": "string"
585+ }
586+ }
587+ },
588+ "description": "OK"
589+ }
590+ },
591+ "produces": [
592+ "application/json"
593+ ],
594+ "parameters": [
595+ {
596+ "required": true,
597+ "in": "path",
598+ "name": "id",
599+ "type": "string",
600+ "description": "TodoId param"
601+ }
602+ ],
603+ "tags": [
604+ "todo"
605+ ]
606+ }
607+ }
608+ }
609+}
610+|]