Quick and diry CLI

This commit is contained in:
Alex Biehl 2022-02-18 08:22:19 +01:00
parent 9312b2b671
commit 7ac36beb5d
10 changed files with 291 additions and 179 deletions

82
bin/Main.hs Normal file
View File

@ -0,0 +1,82 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
module Main (main) where
import Options.Applicative
( Parser,
auto,
execParser,
flag,
fullDesc,
header,
help,
helper,
info,
long,
metavar,
option,
progDesc,
short,
showDefault,
str,
strArgument,
strOption,
switch,
value,
)
import System.Environment (getArgs)
import Tie (fileWriter, generate)
import Prelude hiding (Option)
data Input = Input
{ outputDirectory :: FilePath,
moduleName :: Text,
packageName :: Text,
inputFile :: FilePath
}
options :: Parser Input
options =
Input
<$> option
str
( long "output"
<> short 'o'
<> metavar "DIR"
<> showDefault
<> value "out"
)
<*> option
str
( long "module-name"
<> metavar "MODULE"
<> showDefault
<> value "OpenAPI"
)
<*> option
str
( long "package-name"
<> metavar "PACKAGE"
<> showDefault
<> value "open-api"
)
<*> strArgument
( metavar "FILE"
)
main :: IO ()
main = do
Input {..} <-
execParser $
info
(options <**> helper)
( fullDesc
<> progDesc "Generate a Haskell server from an OpenAPI3 specification"
<> header "tie - openapi3 server code generator"
)
generate
(fileWriter outputDirectory)
packageName
moduleName
inputFile

View File

@ -107,12 +107,16 @@ normalize =
pure (inlineArrayElementTypeName enclosingType)
)
generate :: MonadIO m => Writer m -> FilePath -> m ()
generate write inputFile = do
-- TODO make configurable
let apiName = "OpenAPI"
packageName = "open-api"
generate ::
MonadIO m =>
Writer m ->
-- | Package name
Text ->
-- | Module name
Text ->
FilePath ->
m ()
generate write packageName apiName inputFile = do
openApi <- readOpenApiSpec inputFile
-- Helper to resolve components in the spec.

View File

@ -26,6 +26,7 @@ codegenCabalFile packageName exposedModules =
"," <+> "http-api-data",
"," <+> "http-types",
"," <+> "text",
"," <+> "time",
"," <+> "wai"
]
),

View File

@ -1,3 +1,5 @@
{-# LANGUAGE OverloadedStrings #-}
module Test.Tie.Golden (test_Golden_tests) where
import Data.ByteString.Builder (toLazyByteString)
@ -18,7 +20,11 @@ test_Golden_tests = do
(replaceExtension input ".yaml.out")
( do
(_, output) <- withTestWriter $ \writer ->
generate writer input
generate
writer
"test" -- package name
"Test" -- module name
input
pure (toLazyByteString output)
)
| input' <- inputs,

View File

@ -1,11 +1,11 @@
OpenAPI/Api.hs
Test/Api.hs
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
module OpenAPI.Api where
module Test.Api where
import qualified Control.Applicative
import qualified Control.Monad
@ -24,11 +24,11 @@ import qualified Network.HTTP.Types
import qualified Network.Wai
import qualified Web.HttpApiData
import OpenAPI.Response
import Test.Response
import OpenAPI.Schemas.Test
import Test.Schemas.Test
import OpenAPI.Response.Test
import Test.Response.Test
data Api m = Api {
-- | test
@ -56,14 +56,14 @@ application run api notFound request respond =
invalidRequest _ =
respond (Network.Wai.responseBuilder (toEnum 401) [] mempty)
---------------------
OpenAPI/Response.hs
Test/Response.hs
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
module OpenAPI.Response where
module Test.Response where
import qualified Control.Applicative
import qualified Control.Monad
@ -85,14 +85,14 @@ import qualified Web.HttpApiData
class ToResponse a where
toResponse :: a -> Network.Wai.Response
---------------------
OpenAPI/Response/Test.hs
Test/Response/Test.hs
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
module OpenAPI.Response.Test where
module Test.Response.Test where
import qualified Control.Applicative
import qualified Control.Monad
@ -111,9 +111,9 @@ import qualified Network.HTTP.Types
import qualified Network.Wai
import qualified Web.HttpApiData
import OpenAPI.Schemas.Test
import Test.Schemas.Test
import OpenAPI.Response
import Test.Response
data TestResponse
= TestResponse200 Test
@ -122,14 +122,14 @@ instance ToResponse TestResponse where
toResponse (TestResponse200 x) =
Network.Wai.responseBuilder (toEnum 200) [(Network.HTTP.Types.hContentType, "application/json")] (Data.Aeson.fromEncoding (Data.Aeson.toEncoding x))
---------------------
OpenAPI/Schemas/Test.hs
Test/Schemas/Test.hs
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
module OpenAPI.Schemas.Test where
module Test.Schemas.Test where
import qualified Control.Applicative
import qualified Control.Monad
@ -171,10 +171,10 @@ instance Data.Aeson.FromJSON Test where
<$> o Data.Aeson..:? "dateProp"
<*> o Data.Aeson..:? "dateTimeProp"
---------------------
open-api.cabal
test.cabal
cabal-version: 3.0
name: open-api
name: test
version: 0.1.0.0
library
build-depends:
@ -185,9 +185,10 @@ library
, http-api-data
, http-types
, text
, time
, wai
exposed-modules:
OpenAPI.Api
OpenAPI.Response
OpenAPI.Response.Test
OpenAPI.Schemas.Test
Test.Api
Test.Response
Test.Response.Test
Test.Schemas.Test

View File

@ -1,11 +1,11 @@
OpenAPI/Api.hs
Test/Api.hs
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
module OpenAPI.Api where
module Test.Api where
import qualified Control.Applicative
import qualified Control.Monad
@ -24,13 +24,13 @@ import qualified Network.HTTP.Types
import qualified Network.Wai
import qualified Web.HttpApiData
import OpenAPI.Response
import Test.Response
import OpenAPI.Schemas.Package
import Test.Schemas.Package
import OpenAPI.Response.ListPackages
import OpenAPI.Response.ListPackages
import Test.Response.ListPackages
import Test.Response.ListPackages
data Api m = Api {
-- | List all packages
@ -70,14 +70,14 @@ application run api notFound request respond =
invalidRequest _ =
respond (Network.Wai.responseBuilder (toEnum 401) [] mempty)
---------------------
OpenAPI/Response.hs
Test/Response.hs
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
module OpenAPI.Response where
module Test.Response where
import qualified Control.Applicative
import qualified Control.Monad
@ -99,14 +99,14 @@ import qualified Web.HttpApiData
class ToResponse a where
toResponse :: a -> Network.Wai.Response
---------------------
OpenAPI/Response/ListPackages.hs
Test/Response/ListPackages.hs
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
module OpenAPI.Response.ListPackages where
module Test.Response.ListPackages where
import qualified Control.Applicative
import qualified Control.Monad
@ -127,7 +127,7 @@ import qualified Web.HttpApiData
import OpenAPI.Response
import Test.Response
data ListPackagesResponse
= ListPackagesResponse200 error: Enum
@ -136,14 +136,14 @@ instance ToResponse ListPackagesResponse where
toResponse (ListPackagesResponse200 x) =
Network.Wai.responseBuilder (toEnum 200) [(Network.HTTP.Types.hContentType, "application/json")] (Data.Aeson.fromEncoding (Data.Aeson.toEncoding x))
---------------------
OpenAPI/Response/ListPackages.hs
Test/Response/ListPackages.hs
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
module OpenAPI.Response.ListPackages where
module Test.Response.ListPackages where
import qualified Control.Applicative
import qualified Control.Monad
@ -162,9 +162,9 @@ import qualified Network.HTTP.Types
import qualified Network.Wai
import qualified Web.HttpApiData
import OpenAPI.Schemas.Package
import Test.Schemas.Package
import OpenAPI.Response
import Test.Response
data ListPackagesResponse
= ListPackagesResponse200 Package
@ -173,14 +173,14 @@ instance ToResponse ListPackagesResponse where
toResponse (ListPackagesResponse200 x) =
Network.Wai.responseBuilder (toEnum 200) [(Network.HTTP.Types.hContentType, "application/json")] (Data.Aeson.fromEncoding (Data.Aeson.toEncoding x))
---------------------
OpenAPI/Schemas/Package.hs
Test/Schemas/Package.hs
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
module OpenAPI.Schemas.Package where
module Test.Schemas.Package where
import qualified Control.Applicative
import qualified Control.Monad
@ -223,10 +223,10 @@ instance Data.Aeson.FromJSON Package where
"NPM" -> pure PackageNPM
_ -> fail "invalid enum value"
---------------------
open-api.cabal
test.cabal
cabal-version: 3.0
name: open-api
name: test
version: 0.1.0.0
library
build-depends:
@ -237,9 +237,10 @@ library
, http-api-data
, http-types
, text
, time
, wai
exposed-modules:
OpenAPI.Api
OpenAPI.Response
OpenAPI.Response.ListPackages
OpenAPI.Schemas.Package
Test.Api
Test.Response
Test.Response.ListPackages
Test.Schemas.Package

View File

@ -1,11 +1,11 @@
OpenAPI/Api.hs
Test/Api.hs
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
module OpenAPI.Api where
module Test.Api where
import qualified Control.Applicative
import qualified Control.Monad
@ -24,15 +24,15 @@ import qualified Network.HTTP.Types
import qualified Network.Wai
import qualified Web.HttpApiData
import OpenAPI.Response
import Test.Response
import OpenAPI.Schemas.Packages
import OpenAPI.Schemas.Inline
import OpenAPI.Schemas.Package
import Test.Schemas.Packages
import Test.Schemas.Inline
import Test.Schemas.Package
import OpenAPI.Response.ListPackages
import OpenAPI.Response.ListPackages3
import OpenAPI.Response.ListPackages2
import Test.Response.ListPackages
import Test.Response.ListPackages3
import Test.Response.ListPackages2
data Api m = Api {
-- | List all packages
@ -84,14 +84,14 @@ application run api notFound request respond =
invalidRequest _ =
respond (Network.Wai.responseBuilder (toEnum 401) [] mempty)
---------------------
OpenAPI/Response.hs
Test/Response.hs
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
module OpenAPI.Response where
module Test.Response where
import qualified Control.Applicative
import qualified Control.Monad
@ -113,14 +113,14 @@ import qualified Web.HttpApiData
class ToResponse a where
toResponse :: a -> Network.Wai.Response
---------------------
OpenAPI/Response/ListPackages.hs
Test/Response/ListPackages.hs
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
module OpenAPI.Response.ListPackages where
module Test.Response.ListPackages where
import qualified Control.Applicative
import qualified Control.Monad
@ -139,9 +139,9 @@ import qualified Network.HTTP.Types
import qualified Network.Wai
import qualified Web.HttpApiData
import OpenAPI.Schemas.Packages
import Test.Schemas.Packages
import OpenAPI.Response
import Test.Response
data ListPackagesResponse
= ListPackagesResponse200 Packages
@ -150,14 +150,14 @@ instance ToResponse ListPackagesResponse where
toResponse (ListPackagesResponse200 x) =
Network.Wai.responseBuilder (toEnum 200) [(Network.HTTP.Types.hContentType, "application/json")] (Data.Aeson.fromEncoding (Data.Aeson.toEncoding x))
---------------------
OpenAPI/Response/ListPackages2.hs
Test/Response/ListPackages2.hs
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
module OpenAPI.Response.ListPackages2 where
module Test.Response.ListPackages2 where
import qualified Control.Applicative
import qualified Control.Monad
@ -176,9 +176,9 @@ import qualified Network.HTTP.Types
import qualified Network.Wai
import qualified Web.HttpApiData
import OpenAPI.Schemas.Package
import Test.Schemas.Package
import OpenAPI.Response
import Test.Response
data ListPackages2Response
= ListPackages2Response200 [ Package ]
@ -187,14 +187,14 @@ instance ToResponse ListPackages2Response where
toResponse (ListPackages2Response200 x) =
Network.Wai.responseBuilder (toEnum 200) [(Network.HTTP.Types.hContentType, "application/json")] (Data.Aeson.fromEncoding (Data.Aeson.toEncoding x))
---------------------
OpenAPI/Response/ListPackages3.hs
Test/Response/ListPackages3.hs
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
module OpenAPI.Response.ListPackages3 where
module Test.Response.ListPackages3 where
import qualified Control.Applicative
import qualified Control.Monad
@ -213,9 +213,9 @@ import qualified Network.HTTP.Types
import qualified Network.Wai
import qualified Web.HttpApiData
import OpenAPI.Schemas.Inline
import Test.Schemas.Inline
import OpenAPI.Response
import Test.Response
data ListPackages3Response
= ListPackages3Response200 [ Inline ]
@ -224,14 +224,14 @@ instance ToResponse ListPackages3Response where
toResponse (ListPackages3Response200 x) =
Network.Wai.responseBuilder (toEnum 200) [(Network.HTTP.Types.hContentType, "application/json")] (Data.Aeson.fromEncoding (Data.Aeson.toEncoding x))
---------------------
OpenAPI/Schemas/Inline.hs
Test/Schemas/Inline.hs
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
module OpenAPI.Schemas.Inline where
module Test.Schemas.Inline where
import qualified Control.Applicative
import qualified Control.Monad
@ -270,14 +270,14 @@ instance Data.Aeson.FromJSON InlineElem where
type Inline = [ InlineElem ]
---------------------
OpenAPI/Schemas/Package.hs
Test/Schemas/Package.hs
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
module OpenAPI.Schemas.Package where
module Test.Schemas.Package where
import qualified Control.Applicative
import qualified Control.Monad
@ -316,14 +316,14 @@ instance Data.Aeson.FromJSON Package where
Package
<$> o Data.Aeson..:? "name"
---------------------
OpenAPI/Schemas/Packages.hs
Test/Schemas/Packages.hs
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
module OpenAPI.Schemas.Packages where
module Test.Schemas.Packages where
import qualified Control.Applicative
import qualified Control.Monad
@ -342,16 +342,16 @@ import qualified Network.HTTP.Types
import qualified Network.Wai
import qualified Web.HttpApiData
import OpenAPI.Schemas.Package
import Test.Schemas.Package
type Packages = [ Package ]
---------------------
open-api.cabal
test.cabal
cabal-version: 3.0
name: open-api
name: test
version: 0.1.0.0
library
build-depends:
@ -362,13 +362,14 @@ library
, http-api-data
, http-types
, text
, time
, wai
exposed-modules:
OpenAPI.Api
OpenAPI.Response
OpenAPI.Response.ListPackages
OpenAPI.Response.ListPackages2
OpenAPI.Response.ListPackages3
OpenAPI.Schemas.Inline
OpenAPI.Schemas.Package
OpenAPI.Schemas.Packages
Test.Api
Test.Response
Test.Response.ListPackages
Test.Response.ListPackages2
Test.Response.ListPackages3
Test.Schemas.Inline
Test.Schemas.Package
Test.Schemas.Packages

View File

@ -1,11 +1,11 @@
OpenAPI/Api.hs
Test/Api.hs
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
module OpenAPI.Api where
module Test.Api where
import qualified Control.Applicative
import qualified Control.Monad
@ -24,15 +24,15 @@ import qualified Network.HTTP.Types
import qualified Network.Wai
import qualified Web.HttpApiData
import OpenAPI.Response
import Test.Response
import OpenAPI.Schemas.Packages
import OpenAPI.Schemas.Inline2
import OpenAPI.Schemas.Inline
import Test.Schemas.Packages
import Test.Schemas.Inline2
import Test.Schemas.Inline
import OpenAPI.Response.ListPackages
import OpenAPI.Response.ListPackages2
import OpenAPI.Response.ListPackages2
import Test.Response.ListPackages
import Test.Response.ListPackages2
import Test.Response.ListPackages2
data Api m = Api {
-- | List all packages
@ -84,14 +84,14 @@ application run api notFound request respond =
invalidRequest _ =
respond (Network.Wai.responseBuilder (toEnum 401) [] mempty)
---------------------
OpenAPI/Response.hs
Test/Response.hs
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
module OpenAPI.Response where
module Test.Response where
import qualified Control.Applicative
import qualified Control.Monad
@ -113,14 +113,14 @@ import qualified Web.HttpApiData
class ToResponse a where
toResponse :: a -> Network.Wai.Response
---------------------
OpenAPI/Response/ListPackages.hs
Test/Response/ListPackages.hs
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
module OpenAPI.Response.ListPackages where
module Test.Response.ListPackages where
import qualified Control.Applicative
import qualified Control.Monad
@ -139,9 +139,9 @@ import qualified Network.HTTP.Types
import qualified Network.Wai
import qualified Web.HttpApiData
import OpenAPI.Schemas.Packages
import Test.Schemas.Packages
import OpenAPI.Response
import Test.Response
data ListPackagesResponse
= ListPackagesResponse200 Packages
@ -150,14 +150,14 @@ instance ToResponse ListPackagesResponse where
toResponse (ListPackagesResponse200 x) =
Network.Wai.responseBuilder (toEnum 200) [(Network.HTTP.Types.hContentType, "application/json")] (Data.Aeson.fromEncoding (Data.Aeson.toEncoding x))
---------------------
OpenAPI/Response/ListPackages2.hs
Test/Response/ListPackages2.hs
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
module OpenAPI.Response.ListPackages2 where
module Test.Response.ListPackages2 where
import qualified Control.Applicative
import qualified Control.Monad
@ -176,9 +176,9 @@ import qualified Network.HTTP.Types
import qualified Network.Wai
import qualified Web.HttpApiData
import OpenAPI.Schemas.Inline
import Test.Schemas.Inline
import OpenAPI.Response
import Test.Response
data ListPackages2Response
= ListPackages2Response200 Inline
@ -187,14 +187,14 @@ instance ToResponse ListPackages2Response where
toResponse (ListPackages2Response200 x) =
Network.Wai.responseBuilder (toEnum 200) [(Network.HTTP.Types.hContentType, "application/json")] (Data.Aeson.fromEncoding (Data.Aeson.toEncoding x))
---------------------
OpenAPI/Response/ListPackages2.hs
Test/Response/ListPackages2.hs
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
module OpenAPI.Response.ListPackages2 where
module Test.Response.ListPackages2 where
import qualified Control.Applicative
import qualified Control.Monad
@ -213,9 +213,9 @@ import qualified Network.HTTP.Types
import qualified Network.Wai
import qualified Web.HttpApiData
import OpenAPI.Schemas.Inline2
import Test.Schemas.Inline2
import OpenAPI.Response
import Test.Response
data ListPackages2Response
= ListPackages2Response200 Inline2
@ -224,14 +224,14 @@ instance ToResponse ListPackages2Response where
toResponse (ListPackages2Response200 x) =
Network.Wai.responseBuilder (toEnum 200) [(Network.HTTP.Types.hContentType, "application/json")] (Data.Aeson.fromEncoding (Data.Aeson.toEncoding x))
---------------------
OpenAPI/Schemas/Inline.hs
Test/Schemas/Inline.hs
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
module OpenAPI.Schemas.Inline where
module Test.Schemas.Inline where
import qualified Control.Applicative
import qualified Control.Monad
@ -250,7 +250,7 @@ import qualified Network.HTTP.Types
import qualified Network.Wai
import qualified Web.HttpApiData
import OpenAPI.Schemas.Package
import Test.Schemas.Package
data InlineValue
= InlineValueInlineValueOneOf1 GHC.Types.Int
@ -284,14 +284,14 @@ instance Data.Aeson.FromJSON Inline where
Inline
<$> o Data.Aeson..:? "value"
---------------------
OpenAPI/Schemas/Inline2.hs
Test/Schemas/Inline2.hs
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
module OpenAPI.Schemas.Inline2 where
module Test.Schemas.Inline2 where
import qualified Control.Applicative
import qualified Control.Monad
@ -310,7 +310,7 @@ import qualified Network.HTTP.Types
import qualified Network.Wai
import qualified Web.HttpApiData
import OpenAPI.Schemas.Package
import Test.Schemas.Package
data Inline2Value
= Inline2ValueInline2ValueOneOf1 GHC.Types.Int
@ -357,14 +357,14 @@ instance Data.Aeson.FromJSON Inline2 where
Inline2
<$> o Data.Aeson..:? "value"
---------------------
OpenAPI/Schemas/Package.hs
Test/Schemas/Package.hs
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
module OpenAPI.Schemas.Package where
module Test.Schemas.Package where
import qualified Control.Applicative
import qualified Control.Monad
@ -403,14 +403,14 @@ instance Data.Aeson.FromJSON Package where
Package
<$> o Data.Aeson..:? "name"
---------------------
OpenAPI/Schemas/Packages.hs
Test/Schemas/Packages.hs
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
module OpenAPI.Schemas.Packages where
module Test.Schemas.Packages where
import qualified Control.Applicative
import qualified Control.Monad
@ -429,7 +429,7 @@ import qualified Network.HTTP.Types
import qualified Network.Wai
import qualified Web.HttpApiData
import OpenAPI.Schemas.Package
import Test.Schemas.Package
@ -446,10 +446,10 @@ instance Data.Aeson.FromJSON Packages where
(PackagesPackage <$> Data.Aeson.parseJSON x) Control.Applicative.<|>
(PackagesPackage <$> Data.Aeson.parseJSON x)
---------------------
open-api.cabal
test.cabal
cabal-version: 3.0
name: open-api
name: test
version: 0.1.0.0
library
build-depends:
@ -460,13 +460,14 @@ library
, http-api-data
, http-types
, text
, time
, wai
exposed-modules:
OpenAPI.Api
OpenAPI.Response
OpenAPI.Response.ListPackages
OpenAPI.Response.ListPackages2
OpenAPI.Schemas.Inline
OpenAPI.Schemas.Inline2
OpenAPI.Schemas.Package
OpenAPI.Schemas.Packages
Test.Api
Test.Response
Test.Response.ListPackages
Test.Response.ListPackages2
Test.Schemas.Inline
Test.Schemas.Inline2
Test.Schemas.Package
Test.Schemas.Packages

View File

@ -1,11 +1,11 @@
OpenAPI/Api.hs
Test/Api.hs
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
module OpenAPI.Api where
module Test.Api where
import qualified Control.Applicative
import qualified Control.Monad
@ -24,14 +24,14 @@ import qualified Network.HTTP.Types
import qualified Network.Wai
import qualified Web.HttpApiData
import OpenAPI.Response
import Test.Response
import OpenAPI.Schemas.Vehicle
import OpenAPI.Schemas.NISE
import OpenAPI.Schemas.Vehicle
import Test.Schemas.Vehicle
import Test.Schemas.NISE
import Test.Schemas.Vehicle
import OpenAPI.Response.GetUser
import OpenAPI.Response.CreateUser
import Test.Response.GetUser
import Test.Response.CreateUser
data Api m = Api {
getUser ::
@ -118,14 +118,14 @@ application run api notFound request respond =
invalidRequest _ =
respond (Network.Wai.responseBuilder (toEnum 401) [] mempty)
---------------------
OpenAPI/Response.hs
Test/Response.hs
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
module OpenAPI.Response where
module Test.Response where
import qualified Control.Applicative
import qualified Control.Monad
@ -147,14 +147,14 @@ import qualified Web.HttpApiData
class ToResponse a where
toResponse :: a -> Network.Wai.Response
---------------------
OpenAPI/Response/CreateUser.hs
Test/Response/CreateUser.hs
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
module OpenAPI.Response.CreateUser where
module Test.Response.CreateUser where
import qualified Control.Applicative
import qualified Control.Monad
@ -173,10 +173,10 @@ import qualified Network.HTTP.Types
import qualified Network.Wai
import qualified Web.HttpApiData
import OpenAPI.Schemas.NISE
import OpenAPI.Schemas.Vehicle
import Test.Schemas.NISE
import Test.Schemas.Vehicle
import OpenAPI.Response
import Test.Response
data CreateUserResponse
= CreateUserResponse200 Vehicle
@ -185,14 +185,14 @@ instance ToResponse CreateUserResponse where
toResponse (CreateUserResponse200 x) =
Network.Wai.responseBuilder (toEnum 200) [(Network.HTTP.Types.hContentType, "application/json")] (Data.Aeson.fromEncoding (Data.Aeson.toEncoding x))
---------------------
OpenAPI/Response/GetUser.hs
Test/Response/GetUser.hs
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
module OpenAPI.Response.GetUser where
module Test.Response.GetUser where
import qualified Control.Applicative
import qualified Control.Monad
@ -211,9 +211,9 @@ import qualified Network.HTTP.Types
import qualified Network.Wai
import qualified Web.HttpApiData
import OpenAPI.Schemas.Vehicle
import Test.Schemas.Vehicle
import OpenAPI.Response
import Test.Response
data GetUserResponse
= GetUserResponse200 Vehicle
@ -222,14 +222,14 @@ instance ToResponse GetUserResponse where
toResponse (GetUserResponse200 x) =
Network.Wai.responseBuilder (toEnum 200) [(Network.HTTP.Types.hContentType, "application/json")] (Data.Aeson.fromEncoding (Data.Aeson.toEncoding x))
---------------------
OpenAPI/Schemas/Car.hs
Test/Schemas/Car.hs
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
module OpenAPI.Schemas.Car where
module Test.Schemas.Car where
import qualified Control.Applicative
import qualified Control.Monad
@ -248,7 +248,7 @@ import qualified Network.HTTP.Types
import qualified Network.Wai
import qualified Web.HttpApiData
import OpenAPI.Schemas.Vehicle
import Test.Schemas.Vehicle
@ -280,14 +280,14 @@ instance Data.Aeson.FromJSON Car where
<*> o Data.Aeson..:? "name"
<*> o Data.Aeson..: "type"
---------------------
OpenAPI/Schemas/NISE.hs
Test/Schemas/NISE.hs
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
module OpenAPI.Schemas.NISE where
module Test.Schemas.NISE where
import qualified Control.Applicative
import qualified Control.Monad
@ -306,7 +306,7 @@ import qualified Network.HTTP.Types
import qualified Network.Wai
import qualified Web.HttpApiData
import OpenAPI.Schemas.PackageId
import Test.Schemas.PackageId
newtype NISEValue = NISEValue
{
@ -352,14 +352,14 @@ instance Data.Aeson.FromJSON NISE where
<*> o Data.Aeson..: "ports"
<*> o Data.Aeson..:? "value"
---------------------
OpenAPI/Schemas/PackageId.hs
Test/Schemas/PackageId.hs
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
module OpenAPI.Schemas.PackageId where
module Test.Schemas.PackageId where
import qualified Control.Applicative
import qualified Control.Monad
@ -378,8 +378,8 @@ import qualified Network.HTTP.Types
import qualified Network.Wai
import qualified Web.HttpApiData
import OpenAPI.Schemas.Car
import OpenAPI.Schemas.Plane
import Test.Schemas.Car
import Test.Schemas.Plane
data PackageIdOneOf4 = PackageIdOneOf4
{
@ -458,14 +458,14 @@ instance Data.Aeson.FromJSON PackageId where
(PackageIdPackageIdOneOf3 <$> Data.Aeson.parseJSON x) Control.Applicative.<|>
(PackageIdPackageIdOneOf4 <$> Data.Aeson.parseJSON x)
---------------------
OpenAPI/Schemas/Plane.hs
Test/Schemas/Plane.hs
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
module OpenAPI.Schemas.Plane where
module Test.Schemas.Plane where
import qualified Control.Applicative
import qualified Control.Monad
@ -484,8 +484,8 @@ import qualified Network.HTTP.Types
import qualified Network.Wai
import qualified Web.HttpApiData
import OpenAPI.Schemas.Car
import OpenAPI.Schemas.Vehicle
import Test.Schemas.Car
import Test.Schemas.Vehicle
@ -523,14 +523,14 @@ instance Data.Aeson.FromJSON Plane where
<*> o Data.Aeson..:? "nb_passengers"
<*> o Data.Aeson..:? "type"
---------------------
OpenAPI/Schemas/Vehicle.hs
Test/Schemas/Vehicle.hs
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
module OpenAPI.Schemas.Vehicle where
module Test.Schemas.Vehicle where
import qualified Control.Applicative
import qualified Control.Monad
@ -578,10 +578,10 @@ instance Data.Aeson.FromJSON Vehicle where
<*> o Data.Aeson..:? "name"
<*> o Data.Aeson..: "type"
---------------------
open-api.cabal
test.cabal
cabal-version: 3.0
name: open-api
name: test
version: 0.1.0.0
library
build-depends:
@ -592,14 +592,15 @@ library
, http-api-data
, http-types
, text
, time
, wai
exposed-modules:
OpenAPI.Api
OpenAPI.Response
OpenAPI.Response.CreateUser
OpenAPI.Response.GetUser
OpenAPI.Schemas.Car
OpenAPI.Schemas.NISE
OpenAPI.Schemas.PackageId
OpenAPI.Schemas.Plane
OpenAPI.Schemas.Vehicle
Test.Api
Test.Response
Test.Response.CreateUser
Test.Response.GetUser
Test.Schemas.Car
Test.Schemas.NISE
Test.Schemas.PackageId
Test.Schemas.Plane
Test.Schemas.Vehicle

View File

@ -71,6 +71,20 @@ library
hs-source-dirs: src
default-language: Haskell2010
executable tie
build-depends:
base, tie, relude, optparse-applicative
mixins:
base hiding (Prelude),
relude (Relude as Prelude),
relude
main-is: Main.hs
hs-source-dirs: bin
default-language: Haskell2010
test-suite tie-tests
type: exitcode-stdio-1.0
main-is: Main.hs