Skip to content

Commit

Permalink
Add writeSwaggerJSON helper in the example project to write pretty sw…
Browse files Browse the repository at this point in the history
…agger.json
  • Loading branch information
fizruk committed Mar 6, 2016
1 parent e6a5b4c commit baa9b96
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 1 deletion.
2 changes: 2 additions & 0 deletions example/example.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ library
Todo
build-depends: base
, aeson
, aeson-pretty
, bytestring
, lens
, servant
, servant-server
Expand Down
5 changes: 5 additions & 0 deletions example/src/Todo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ module Todo where

import Control.Lens
import Data.Aeson
import Data.Aeson.Encode.Pretty (encodePretty)
import qualified Data.ByteString.Lazy.Char8 as BL8
import Data.Proxy
import Data.Text (Text)
import Data.Time (UTCTime(..), fromGregorian)
Expand Down Expand Up @@ -66,3 +68,6 @@ todoSwagger = toSwagger todoAPI
server :: Server API
server = return todoSwagger :<|> error "not implemented"

-- | Output generated @swagger.json@ file for the @'TodoAPI'@.
writeSwaggerJSON :: IO ()
writeSwaggerJSON = BL8.writeFile "example/swagger.json" (encodePretty todoSwagger)
161 changes: 160 additions & 1 deletion example/swagger.json
Original file line number Diff line number Diff line change
@@ -1 +1,160 @@
{"swagger":"2.0","info":{"version":"1.0","title":"Todo API","license":{"url":"http://mit.com","name":"MIT"},"description":"This is an API that tests swagger integration"},"definitions":{"Todo":{"example":{"summary":"get milk","created":"2015-12-31T00:00:00.000000000000Z"},"required":["created","summary"],"type":"object","description":"This is some real Todo right here","properties":{"summary":{"type":"string"},"created":{"$ref":"#/definitions/UTCTime"}}},"UTCTime":{"format":"yyyy-mm-ddThh:MM:ssZ","type":"string"},"TodoId":{"maximum":9223372036854775807,"minimum":-9223372036854775808,"type":"integer"}},"paths":{"/todo/{id}":{"get":{"responses":{"404":{"description":"`id` not found"},"200":{"schema":{"$ref":"#/definitions/Todo"},"description":""}},"produces":["application/json"],"parameters":[{"maximum":9223372036854775807,"minimum":-9223372036854775808,"required":true,"in":"path","name":"id","type":"integer"}]},"put":{"consumes":["application/json"],"responses":{"404":{"description":"`id` not found"},"400":{"description":"Invalid `body`"},"200":{"schema":{"$ref":"#/definitions/TodoId"},"description":""}},"produces":["application/json"],"parameters":[{"maximum":9223372036854775807,"minimum":-9223372036854775808,"required":true,"in":"path","name":"id","type":"integer"},{"required":true,"schema":{"$ref":"#/definitions/Todo"},"in":"body","name":"body"}]}},"/todo":{"post":{"consumes":["application/json"],"responses":{"400":{"description":"Invalid `body`"},"201":{"schema":{"$ref":"#/definitions/TodoId"},"description":""}},"produces":["application/json"],"parameters":[{"required":true,"schema":{"$ref":"#/definitions/Todo"},"in":"body","name":"body"}]},"get":{"responses":{"200":{"schema":{"items":{"$ref":"#/definitions/Todo"},"type":"array"},"description":""}},"produces":["application/json"]}}}}
{
"swagger": "2.0",
"info": {
"version": "1.0",
"title": "Todo API",
"license": {
"url": "http://mit.com",
"name": "MIT"
},
"description": "This is an API that tests swagger integration"
},
"definitions": {
"Todo": {
"example": {
"summary": "get milk",
"created": "2015-12-31T00:00:00.000000000000Z"
},
"required": [
"created",
"summary"
],
"type": "object",
"description": "This is some real Todo right here",
"properties": {
"summary": {
"type": "string"
},
"created": {
"$ref": "#/definitions/UTCTime"
}
}
},
"UTCTime": {
"format": "yyyy-mm-ddThh:MM:ssZ",
"type": "string"
},
"TodoId": {
"maximum": 9223372036854775807,
"minimum": -9223372036854775808,
"type": "integer"
}
},
"paths": {
"/todo/{id}": {
"get": {
"responses": {
"404": {
"description": "`id` not found"
},
"200": {
"schema": {
"$ref": "#/definitions/Todo"
},
"description": ""
}
},
"produces": [
"application/json"
],
"parameters": [
{
"maximum": 9223372036854775807,
"minimum": -9223372036854775808,
"required": true,
"in": "path",
"name": "id",
"type": "integer"
}
]
},
"put": {
"consumes": [
"application/json"
],
"responses": {
"404": {
"description": "`id` not found"
},
"400": {
"description": "Invalid `body`"
},
"200": {
"schema": {
"$ref": "#/definitions/TodoId"
},
"description": ""
}
},
"produces": [
"application/json"
],
"parameters": [
{
"maximum": 9223372036854775807,
"minimum": -9223372036854775808,
"required": true,
"in": "path",
"name": "id",
"type": "integer"
},
{
"required": true,
"schema": {
"$ref": "#/definitions/Todo"
},
"in": "body",
"name": "body"
}
]
}
},
"/todo": {
"post": {
"consumes": [
"application/json"
],
"responses": {
"400": {
"description": "Invalid `body`"
},
"201": {
"schema": {
"$ref": "#/definitions/TodoId"
},
"description": ""
}
},
"produces": [
"application/json"
],
"parameters": [
{
"required": true,
"schema": {
"$ref": "#/definitions/Todo"
},
"in": "body",
"name": "body"
}
]
},
"get": {
"responses": {
"200": {
"schema": {
"items": {
"$ref": "#/definitions/Todo"
},
"type": "array"
},
"description": ""
}
},
"produces": [
"application/json"
]
}
}
}
}

0 comments on commit baa9b96

Please sign in to comment.