1{-# LANGUAGE DeriveGeneric #-}
2{-# LANGUAGE DeriveAnyClass #-}
3{-# LANGUAGE OverloadedLists #-}
4{-# LANGUAGE OverloadedStrings #-}
10import Data.Text (Text)
14import Data.Swagger.Declare
15import Data.Swagger.Lens
19data UserSummary = UserSummary
20 { summaryUsername :: Username
21 , summaryUserid :: Int
22 } deriving (Generic, ToSchema)
26data UserDetailed = UserDetailed
27 { username :: Username
30 } deriving (Generic, ToSchema)
32newtype Package = Package { packageName :: Text }
33 deriving (Generic, ToSchema)
35hackageSwagger :: Swagger
36hackageSwagger = spec & definitions .~ defs
38 (defs, spec) = runDeclare declareHackageSwagger mempty
40declareHackageSwagger :: Declare Definitions Swagger
41declareHackageSwagger = do
42 let usernameParamSchema = toParamSchema (Proxy :: Proxy Username)
43 userSummarySchemaRef <- declareSchemaRef (Proxy :: Proxy UserSummary)
44 userDetailedSchemaRef <- declareSchemaRef (Proxy :: Proxy UserDetailed)
45 packagesSchemaRef <- declareSchemaRef (Proxy :: Proxy [Package])
48 [ ("/users", mempty & pathItemGet ?~ (mempty
49 & operationProduces ?~ MimeList ["application/json"]
50 & operationResponses .~ (mempty
51 & responsesResponses . at 200 ?~ Inline (mempty & responseSchema ?~ userSummarySchemaRef))))
52 , ("/user/{username}", mempty & pathItemGet ?~ (mempty
53 & operationProduces ?~ MimeList ["application/json"]
54 & operationParameters .~ [ Inline $ mempty
55 & paramName .~ "username"
56 & paramRequired ?~ True
57 & paramSchema .~ ParamOther (mempty
58 & paramOtherSchemaIn .~ ParamPath
59 & paramOtherSchemaParamSchema .~ usernameParamSchema) ]
60 & operationResponses .~ (mempty
61 & responsesResponses . at 200 ?~ Inline (mempty & responseSchema ?~ userDetailedSchemaRef))))
62 , ("/packages", mempty & pathItemGet ?~ (mempty
63 & operationProduces ?~ MimeList ["application/json"]
64 & operationResponses .~ (mempty
65 & responsesResponses . at 200 ?~ Inline (mempty & responseSchema ?~ packagesSchemaRef))))
69main = putStrLn . read . show . encode $ hackageSwagger
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list