1
1
mirror of https://github.com/aelve/guide.git synced 2024-11-21 16:03:42 +03:00

Generate swagger.json for branches (#380)

* Generate swagger.json for branches

* Fix

* Fix again

* Fix once more

* [skip ci] Regenerate swagger.json

* Don't log debug info to stdout

* Push even if the branch is ahead

* Fix

* Empty

* [skip ci] Regenerate swagger.json

* Don't use "skip ci"
This commit is contained in:
Artyom Kazak 2019-08-19 17:58:24 +03:00 committed by GitHub
parent a100905cbf
commit ce62066598
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 1369 additions and 51 deletions

View File

@ -47,10 +47,31 @@ jobs:
- curl -sSL https://get.haskellstack.org/ | sh
# travis_retry works around https://github.com/commercialhaskell/stack/issues/4888
- travis_retry stack setup
# Decrypt the GitHub deploy key (travis_key.enc)
- openssl aes-256-cbc -k "$travis_key_password" -d -md sha256 -a -in travis_key.enc -out travis_key
- echo "Host github.com" > ~/.ssh/config
- echo " IdentityFile $(pwd)/travis_key" >> ~/.ssh/config
- chmod 400 travis_key
- git remote set-url origin git@github.com:aelve/guide.git
script:
# Build
- stack --no-terminal build --test --no-run-tests --dependencies-only
- stack --no-terminal build --test --no-run-tests
# Regenerate Swagger and push to the same branch, even if the branch
# is already ahead (which may happen if the previous build in the
# pipeline also pushed to it)
- |
if [ "$TRAVIS_EVENT_TYPE" = "push" ]; then
git checkout "$TRAVIS_BRANCH" && git pull
stack exec -- guide api-docs > back/swagger.json
git add back/swagger.json
# Will only push if the commit was created successfully. Note
# that we don't use "[skip ci]" in the commit message here
# because then Mergify goes "oh, but Travis hasn't passed, so I
# shouldn't merge this".
(git commit -m "Regenerate swagger.json" && git push) || true
git checkout "$TRAVIS_COMMIT"
fi
# Upload the Docker image
- |
if [ "$TRAVIS_EVENT_TYPE" = "push" ]; then
@ -113,3 +134,9 @@ jobs:
notifications:
slack:
secure: BgQpUYFmvXrf7HVBP/fefS/8UVwES800+fT+ufgJX8b2HMx2FvaWVsdv3ErKAryLE0B3fwmvforWugTdgLO3kq66YUgSt51SNQOBLkMVGubIoQsgvr3Ernu+Wpw1DyoMkXQH9q9O9rfCIc4IwkQCEHqu5SVRqdOd5px/CHFl/ktTI22JkT8ap/Be53qjlB2U2sWUf4GxYXq0V/gGF6fDwsUwTVKFb14RfSDrOgK5Vlce2GRf3gNr1C/j7A7EHIR/Z+rNd2hvv69cFw6TRc3s39QmP8XPe3SLZPIHTZ8vRveX1SZioMeEy747r5rHd9vylEjxWtVHhvP9fOt693+woXa8ZAl5uVRgB6S4mTWLZ+LAbqhaCmDGJYr9GrrBMoqWvJiMuBX3ZvHptsAc6O2l/fxZQU3otTE++SmHkhbyoDQkcPCjXPDUi/ZlnoLc5zfMAfApcsZZ8b9t47z12H0O4uDZd2YiNPiQJ1iUA6R879LH3pcxPB3RaoWsfXzv/klkKrU/V2K4SXD9j4/bmAFArlig+dar+Dm44L/a3/G7vbU1lQIa1bG0EqB36qgUS3UCkuy2ppti/JTHpkYx7HVF2BipoCjOVvfBl9G8RkvcQIhyuCfOGm7WL1TjrKVMccIEGJKhm7OO6wOZYCBfAI5zILxi8XEJAIvBm9NywhQlwxI=
# travis_key.enc decryption password, see:
# http://markbucciarelli.com/posts/2019-01-26_how-to-push-to-github-from-travis-ci.html
env:
matrix:
secure: RqWbR4JjNKL5+KS6um6R2xKRGMxYO4qxRdI/RFi5oHsjRwKAQPGATb00Zmd84V/jaVb+NOccG1qp0/SNVwAaFf6Yr1MO9aV3GKC0fDFwSffKLdtVO2yx/JHrRYZ2ymrjEkBGug1FMrHFGZsSLaZYsYKx974tBs04xwAmPv6Yby8bZTGJyknbuyIMeSe6XZIkinyKaw/Zay6QC2CtSLoX50gqY2/HX0fVBgWKDNStigH0UEEynSetRYm/PFRcoBwu3XmHW89Y9B0E/zgvnvFuAgMVmZSUZnD9wBRlnFvfC1pUaFZP8Tz2VZhcJ4xTRTq+r3t2IRTNQBIhlQseobQMxoTrv1Y/ZiEmO14CLSwy3yeX5vCiGmCaA3957FqnjTP07svbru/A0qWMyEtuBtpheCVbQSVvMUBnrl0txTMFiBb4dsJ7zWrp3f7RQ8SFB11FwpGv89d+FifOpXN42DWRXjU0fLCPs8S5iKODWkTSQ41vpGXXUoZdaUOUg1y6tZSoc8gs61KlhcDTrBI2ZCJMNY6c6JVE/BOnJrp6zqyKhY2znyJUodEvjPsy9iccmrt0bEZTVshzbW4Q9okQ26usNtwIJoHNDUdifpmMcobb/ATYEr+C7n9ztxRy9AnZLzp6SsCDlfSDDp32fr7762PMk+2jR9w7fMrR/PBMtDXNsYQ=

View File

@ -3,9 +3,11 @@ module Guide.Api
module Guide.Api.Methods,
module Guide.Api.Server,
module Guide.Api.Types,
module Guide.Api.Docs,
)
where
import Guide.Api.Methods
import Guide.Api.Server
import Guide.Api.Types
import Guide.Api.Docs

View File

@ -0,0 +1,32 @@
{-# LANGUAGE OverloadedStrings #-}
-- | Rendered documentation for the API.
module Guide.Api.Docs
(
apiSwaggerDoc,
apiSwaggerRendered,
)
where
import Imports
import Servant.Swagger (toSwagger)
import Data.Swagger
import qualified Data.Aeson.Encode.Pretty as AesonPretty
import Guide.Api.Types
----------------------------------------------------------------------------
-- Swagger
----------------------------------------------------------------------------
-- | Swagger docs for the 'Api'.
apiSwaggerDoc :: Swagger
apiSwaggerDoc =
toSwagger (Proxy @Api)
& info.title .~ "Aelve Guide API"
& info.version .~ "alpha"
-- | Pretty-printed @swagger.json@ for the 'Api'.
apiSwaggerRendered :: Text
apiSwaggerRendered = utf8ToText $ AesonPretty.encodePretty apiSwaggerDoc

View File

@ -13,19 +13,18 @@ where
import Imports
import Data.Swagger.Lens hiding (format)
import Network.Wai (Middleware, Request)
import Network.Wai.Middleware.Cors (CorsResourcePolicy (..), corsOrigins,
simpleCorsResourcePolicy)
import Servant
import Servant.API.Generic
import Servant.Server.Generic
import Servant.Swagger
import Servant.Swagger.UI
import Guide.Api.Guider
import Guide.Api.Methods
import Guide.Api.Types
import Guide.Api.Docs
import Guide.Logger
import Guide.Config
import Guide.State
@ -76,11 +75,13 @@ logException logger mbReq ex =
-- Servant servers
----------------------------------------------------------------------------
-- Collect API and Swagger server to united 'FullApi'. First takes precedence in case of overlap.
-- | Collect API and Swagger server to united 'FullApi'. First takes
-- precedence in case of overlap.
fullServer :: DB -> Logger -> Config -> Server FullApi
fullServer db di config = apiServer db di config :<|> docServer
-- Collect api out of guiders and convert them to handlers. Type 'type Server api = ServerT api Handler' needed it.
-- | Collect api out of guiders and convert them to handlers. Type 'type
-- Server api = ServerT api Handler' needed it.
apiServer :: DB -> Logger -> Config -> Server Api
apiServer db di config = do
requestDetails <- ask
@ -89,11 +90,7 @@ apiServer db di config = do
-- | A 'Server' for Swagger docs.
docServer :: Server (SwaggerSchemaUI "api" "swagger.json")
docServer = swaggerSchemaUIServer doc
where
doc = toSwagger (Proxy @Api)
& info.title .~ "Aelve Guide API"
& info.version .~ "alpha"
docServer = swaggerSchemaUIServer apiSwaggerDoc
----------------------------------------------------------------------------
-- API handlers put together ('Site')

View File

@ -24,42 +24,10 @@ import qualified Options.Applicative as Opt
-- | All available commands
data Command
= RunServer -- ^ run server
| DryRun -- ^ load database and exit
| LoadPublic FilePath -- ^ load PublicDB, create base on it and exit
----------------------------------------------------------------------------
-- Parsers
----------------------------------------------------------------------------
{-
To see help run command:
$ guide --help
Usage: guide [-v|--version] [COMMAND]
Available options:
-h,--help Show this help text
-v,--version Show Guide version
Available commands:
run Run server
dry-run Load database and exit
load-public Load PublicDB, create base on it and exit
NOTE:
Command 'guide' is the same as 'guide run'
----------------------------------------------------------------------------
$ guide load-public --help
Usage: guide load-public (-p|--path FILEPATH)
Load PublicDB, create base on it and exit
Available options:
-h,--help Show this help text
-p,--path FILEPATH Public DB file name
-}
= RunServer -- ^ Run server
| DryRun -- ^ Load database and exit
| LoadPublic FilePath -- ^ Load PublicDB, create base on it and exit
| ApiDocs -- ^ Show docs for the backend API
-- | Parse the command line of the application.
--
@ -72,10 +40,14 @@ parseCommandLine = Opt.execParser
-- | All possible commands.
commandsParser :: Parser Command
commandsParser = Opt.subparser
$ Opt.command "run" (infoP (pure RunServer) "Start server")
<> Opt.command "dry-run" (infoP (pure DryRun) "Load database and exit")
$ Opt.command "run"
(infoP (pure RunServer) "Start server")
<> Opt.command "dry-run"
(infoP (pure DryRun) "Load database and exit")
<> Opt.command "load-public"
(infoP loadPublicParser "Load PublicDB, create base on it and exit")
<> Opt.command "api-docs"
(infoP (pure ApiDocs) "Show swagger.json for the backend API")
where
infoP parser desc = Opt.info (Opt.helper <*> parser) $ Opt.progDesc desc

View File

@ -16,11 +16,10 @@ where
import Imports hiding ((.=))
-- JSON
import Data.Aeson as Aeson
import Data.Aeson.Encode.Pretty as Aeson hiding (Config)
-- Default
import Data.Default
import Say (sayErr)
import Guide.Utils
@ -125,7 +124,7 @@ readConfig = do
let filename = "config.json"
exists <- doesFileExist filename
unless exists $ do
putStrLn "config.json doesn't exist, creating it"
sayErr "config.json doesn't exist, creating it"
BSL.writeFile filename (Aeson.encodePretty (def :: Config))
contents <- toLazyByteString <$> BS.readFile filename
case Aeson.eitherDecode' contents of

View File

@ -15,6 +15,7 @@ module Guide.Main
runServer,
dryRun,
loadPublic,
apiDocs,
)
where
@ -47,7 +48,7 @@ import System.Signal
-- HVect
import Data.HVect hiding (length)
import Guide.Api (runApiServer)
import Guide.Api (runApiServer, apiSwaggerRendered)
import Guide.App
import Guide.Cli
import Guide.Config
@ -124,6 +125,7 @@ runCommand config = \case
RunServer -> runServer config
DryRun -> dryRun config
LoadPublic path -> loadPublic config path
ApiDocs -> apiDocs config
----------------------------------------------------------------------------
-- Commands
@ -167,6 +169,11 @@ loadPublic config path = withLogger config $ \logger ->
logDebugIO logger "PublicDB imported to GlobalState"
exitSuccess
-- | Dump API docs to the output.
apiDocs :: Config -> IO ()
apiDocs config = withLogger config $ \_logger ->
T.putStrLn apiSwaggerRendered
----------------------------------------------------------------------------
-- Helpers
----------------------------------------------------------------------------

1211
back/swagger.json Normal file

File diff suppressed because it is too large Load Diff

71
travis_key.enc Normal file
View File

@ -0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