mirror of
https://github.com/scarf-sh/tie.git
synced 2024-11-23 02:56:59 +03:00
Remove some superflouos whitespace from generated code
This commit is contained in:
parent
51c5a0a8d4
commit
24e28b6c2d
63
src/Tie.hs
63
src/Tie.hs
@ -191,16 +191,15 @@ generate write packageName apiName extraPackages inputFile = do
|
||||
codegenSchema name' normedType
|
||||
write path $
|
||||
vsep $
|
||||
[ header,
|
||||
mempty,
|
||||
externalDependencyCode,
|
||||
mempty,
|
||||
schemaDependencyCode,
|
||||
mempty,
|
||||
vsep (intersperse mempty codeForInlineDependencies),
|
||||
mempty,
|
||||
output
|
||||
]
|
||||
intersperse mempty $
|
||||
concat
|
||||
[ [ header,
|
||||
externalDependencyCode,
|
||||
schemaDependencyCode
|
||||
],
|
||||
codeForInlineDependencies,
|
||||
[output]
|
||||
]
|
||||
|
||||
-- For each Operation, generate data types for the responses.
|
||||
for_ operations $ \operation@Operation {name} -> do
|
||||
@ -215,17 +214,16 @@ generate write packageName apiName extraPackages inputFile = do
|
||||
traverse (uncurry codegenSchema) inlineDefinitions
|
||||
responsesCode <- codegenResponses resolver operation
|
||||
write path $
|
||||
vsep
|
||||
[ header,
|
||||
mempty,
|
||||
importsCode,
|
||||
mempty,
|
||||
codegenExtraResponseModuleDependencies apiName,
|
||||
mempty,
|
||||
vsep codeForInlineDefinitions,
|
||||
mempty,
|
||||
responsesCode
|
||||
]
|
||||
vsep $
|
||||
intersperse mempty $
|
||||
concat
|
||||
[ [ header,
|
||||
importsCode,
|
||||
codegenExtraResponseModuleDependencies apiName
|
||||
],
|
||||
codeForInlineDefinitions,
|
||||
[responsesCode]
|
||||
]
|
||||
|
||||
-- Generate auxiliary definitions in Response.hs
|
||||
let path = responseHaskellFileName apiName
|
||||
@ -284,19 +282,16 @@ generate write packageName apiName extraPackages inputFile = do
|
||||
operations
|
||||
|
||||
write path $
|
||||
vsep
|
||||
[ header,
|
||||
mempty,
|
||||
codegenExtraApiModuleDependencies apiName,
|
||||
mempty,
|
||||
externalDependencyCode,
|
||||
mempty,
|
||||
schemaDependencyCode,
|
||||
mempty,
|
||||
responseDependencyCode,
|
||||
mempty,
|
||||
operationsCode
|
||||
]
|
||||
vsep $
|
||||
intersperse
|
||||
mempty
|
||||
[ header,
|
||||
codegenExtraApiModuleDependencies apiName,
|
||||
externalDependencyCode,
|
||||
schemaDependencyCode,
|
||||
responseDependencyCode,
|
||||
operationsCode
|
||||
]
|
||||
|
||||
-- Last but not least, generate the Cabal file
|
||||
let allReferencedModules :: [Text]
|
||||
|
@ -221,7 +221,7 @@ codegenOneOfType getDiscriminator typName variants = do
|
||||
)
|
||||
)
|
||||
|
||||
pure (PP.vsep [decl, mempty, toJson, mempty, fromJson])
|
||||
pure (PP.vsep $ intersperse mempty [decl, toJson, fromJson])
|
||||
|
||||
codegenObjectType :: Monad m => Name -> ObjectType (Named Type) -> m (Doc ann)
|
||||
codegenObjectType typName ObjectType {..}
|
||||
@ -324,7 +324,7 @@ codegenObjectType typName ObjectType {..} = do
|
||||
)
|
||||
)
|
||||
)
|
||||
in pure (PP.vsep [decl, mempty, toJson, mempty, fromJson])
|
||||
in pure (PP.vsep $ intersperse mempty [decl, toJson, fromJson])
|
||||
|
||||
codegenRequiredOptionalFieldType :: Bool -> Doc ann -> Doc ann
|
||||
codegenRequiredOptionalFieldType True doc = doc
|
||||
@ -474,4 +474,8 @@ codegenEnumeration typName alternatives _includeNull =
|
||||
)
|
||||
)
|
||||
)
|
||||
in PP.vsep [dataDecl, mempty, toJSON, mempty, fromJSON, mempty, toHttpApiData, mempty, fromHttpApiData]
|
||||
in PP.vsep
|
||||
( intersperse
|
||||
mempty
|
||||
[dataDecl, toJSON, fromJSON, toHttpApiData, fromHttpApiData]
|
||||
)
|
||||
|
@ -344,8 +344,6 @@ import qualified Web.HttpApiData
|
||||
|
||||
import Test.Response
|
||||
|
||||
|
||||
|
||||
data TestResponse
|
||||
= TestResponse200 Network.Wai.StreamingBody
|
||||
|
||||
@ -394,8 +392,6 @@ import qualified Web.HttpApiData
|
||||
|
||||
import Test.Response
|
||||
|
||||
|
||||
|
||||
data Test2Response
|
||||
= Test2Response200 Data.Aeson.Value
|
||||
deriving (Show)
|
||||
|
@ -330,8 +330,6 @@ import Test.Schemas.Test
|
||||
|
||||
import Test.Response
|
||||
|
||||
|
||||
|
||||
data TestResponse
|
||||
= TestResponse200 Test
|
||||
deriving (Show)
|
||||
@ -378,8 +376,6 @@ import qualified Web.HttpApiData
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
data Test = Test
|
||||
{
|
||||
dateProp :: (Data.Maybe.Maybe (Data.Time.Day)),
|
||||
|
@ -333,8 +333,6 @@ import Test.Schemas.Package
|
||||
|
||||
import Test.Response
|
||||
|
||||
|
||||
|
||||
data DummyResponse
|
||||
= DummyResponse200 Package
|
||||
deriving (Show)
|
||||
@ -382,8 +380,6 @@ import qualified Web.HttpApiData
|
||||
import Test.Schemas.PackageBase
|
||||
import Test.Schemas.PackageType
|
||||
|
||||
|
||||
|
||||
data DockerPackage = DockerPackage
|
||||
{
|
||||
backendRegistry :: (Data.Maybe.Maybe (Data.Text.Text)),
|
||||
@ -470,8 +466,6 @@ import qualified Web.HttpApiData
|
||||
import Test.Schemas.PackageBase
|
||||
import Test.Schemas.PackageType
|
||||
|
||||
|
||||
|
||||
data FilePackage = FilePackage
|
||||
{
|
||||
id :: Data.Text.Text,
|
||||
@ -558,8 +552,6 @@ import qualified Web.HttpApiData
|
||||
import Test.Schemas.DockerPackage
|
||||
import Test.Schemas.FilePackage
|
||||
|
||||
|
||||
|
||||
data Package
|
||||
= PackageFilePackage FilePackage
|
||||
| PackageDockerPackage DockerPackage
|
||||
@ -613,8 +605,6 @@ import qualified Web.HttpApiData
|
||||
|
||||
import Test.Schemas.PackageType
|
||||
|
||||
|
||||
|
||||
data PackageBase = PackageBase
|
||||
{
|
||||
id :: Data.Text.Text,
|
||||
@ -692,8 +682,6 @@ import qualified Web.HttpApiData
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
data PackageType
|
||||
= PackageTypeDocker
|
||||
| PackageTypeFile
|
||||
|
@ -397,8 +397,6 @@ import Test.Schemas.Package
|
||||
|
||||
import Test.Response
|
||||
|
||||
|
||||
|
||||
data ListPackagesResponse
|
||||
= ListPackagesResponse200 Package
|
||||
deriving (Show)
|
||||
@ -609,8 +607,6 @@ import Test.Schemas.Order
|
||||
|
||||
import Test.Response
|
||||
|
||||
|
||||
|
||||
data ListPackages4Response
|
||||
= ListPackages4Response201
|
||||
deriving (Show)
|
||||
@ -657,8 +653,6 @@ import Test.Schemas.InsightsTimeRange
|
||||
|
||||
import Test.Response
|
||||
|
||||
|
||||
|
||||
data ListPackages5Response
|
||||
= ListPackages5Response201
|
||||
deriving (Show)
|
||||
@ -705,8 +699,6 @@ import qualified Web.HttpApiData
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
data InsightsTimeRange
|
||||
= InsightsTimeRangeLastWeek
|
||||
| InsightsTimeRangeLastMonth
|
||||
@ -782,8 +774,6 @@ import qualified Web.HttpApiData
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
data Order
|
||||
= OrderAsc
|
||||
| OrderDesc
|
||||
@ -853,8 +843,6 @@ import qualified Web.HttpApiData
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
data Package
|
||||
= PackageDOCKER
|
||||
| PackagePYTHON
|
||||
|
@ -334,8 +334,6 @@ import Test.Schemas.Test
|
||||
|
||||
import Test.Response
|
||||
|
||||
|
||||
|
||||
data TestResponse
|
||||
= TestResponse200 Test
|
||||
deriving (Show)
|
||||
@ -382,8 +380,6 @@ import qualified Scarf.Hashids
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
newtype Test = Test
|
||||
{
|
||||
test1 :: (Data.Maybe.Maybe (Scarf.Hashids.Hashid Int32))
|
||||
|
@ -361,8 +361,6 @@ import Test.Schemas.Test
|
||||
|
||||
import Test.Response
|
||||
|
||||
|
||||
|
||||
data TestResponse
|
||||
= TestResponse200 Test
|
||||
deriving (Show)
|
||||
@ -409,8 +407,6 @@ import qualified Web.HttpApiData
|
||||
|
||||
import Test.Response
|
||||
|
||||
|
||||
|
||||
data Test1Response
|
||||
= Test1Response201 (Data.Maybe.Maybe (Data.Text.Text))
|
||||
deriving (Show)
|
||||
@ -457,8 +453,6 @@ import qualified Web.HttpApiData
|
||||
|
||||
import Test.Response
|
||||
|
||||
|
||||
|
||||
data Test2Response
|
||||
= Test2Response201 Data.Text.Text
|
||||
deriving (Show)
|
||||
@ -505,8 +499,6 @@ import qualified Web.HttpApiData
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
data Test = Test
|
||||
{
|
||||
dateProp :: (Data.Maybe.Maybe (Data.Time.Day)),
|
||||
|
@ -360,8 +360,6 @@ import Test.Schemas.Packages
|
||||
|
||||
import Test.Response
|
||||
|
||||
|
||||
|
||||
data ListPackagesResponse
|
||||
= ListPackagesResponse200 Packages
|
||||
deriving (Show)
|
||||
@ -408,8 +406,6 @@ import Test.Schemas.Package
|
||||
|
||||
import Test.Response
|
||||
|
||||
|
||||
|
||||
data ListPackages2Response
|
||||
= ListPackages2Response200 [ Package ]
|
||||
deriving (Show)
|
||||
@ -456,8 +452,6 @@ import Test.Schemas.Inline
|
||||
|
||||
import Test.Response
|
||||
|
||||
|
||||
|
||||
data ListPackages3Response
|
||||
= ListPackages3Response200 [ Inline ]
|
||||
deriving (Show)
|
||||
@ -563,8 +557,6 @@ import qualified Web.HttpApiData
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
newtype Package = Package
|
||||
{
|
||||
name :: (Data.Maybe.Maybe (Data.Text.Text))
|
||||
@ -622,8 +614,6 @@ import qualified Web.HttpApiData
|
||||
|
||||
import Test.Schemas.Package
|
||||
|
||||
|
||||
|
||||
type Packages = [ Package ]
|
||||
---------------------
|
||||
test.cabal
|
||||
|
@ -330,8 +330,6 @@ import Test.Schemas.Test
|
||||
|
||||
import Test.Response
|
||||
|
||||
|
||||
|
||||
data TestResponse
|
||||
= TestResponse200 Test
|
||||
deriving (Show)
|
||||
@ -378,8 +376,6 @@ import qualified Web.HttpApiData
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
data Test = Test
|
||||
{
|
||||
a :: (Data.Maybe.Maybe (GHC.Int.Int32)),
|
||||
|
@ -360,8 +360,6 @@ import Test.Schemas.PetOrPackage
|
||||
|
||||
import Test.Response
|
||||
|
||||
|
||||
|
||||
data ListPackagesResponse
|
||||
= ListPackagesResponse200 PetOrPackage
|
||||
deriving (Show)
|
||||
@ -408,8 +406,6 @@ import Test.Schemas.Inline
|
||||
|
||||
import Test.Response
|
||||
|
||||
|
||||
|
||||
data ListPackages2Response
|
||||
= ListPackages2Response200 Inline
|
||||
deriving (Show)
|
||||
@ -456,8 +452,6 @@ import Test.Schemas.Inline2
|
||||
|
||||
import Test.Response
|
||||
|
||||
|
||||
|
||||
data ListPackages3Response
|
||||
= ListPackages3Response200 Inline2
|
||||
deriving (Show)
|
||||
@ -677,8 +671,6 @@ import qualified Web.HttpApiData
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
newtype Package = Package
|
||||
{
|
||||
type' :: (Data.Maybe.Maybe (Data.Text.Text))
|
||||
@ -736,8 +728,6 @@ import qualified Web.HttpApiData
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
newtype Pet = Pet
|
||||
{
|
||||
type' :: (Data.Maybe.Maybe (Data.Text.Text))
|
||||
@ -796,8 +786,6 @@ import qualified Web.HttpApiData
|
||||
import Test.Schemas.Package
|
||||
import Test.Schemas.Pet
|
||||
|
||||
|
||||
|
||||
data PetOrPackage
|
||||
= PetOrPackagePet Pet
|
||||
| PetOrPackagePackage Package
|
||||
|
@ -361,8 +361,6 @@ import Test.Schemas.Error
|
||||
|
||||
import Test.Response
|
||||
|
||||
|
||||
|
||||
data CreatePetsResponse
|
||||
= CreatePetsResponse201
|
||||
| CreatePetsDefaultResponse Network.HTTP.Types.Status Error
|
||||
@ -413,8 +411,6 @@ import Test.Schemas.Pets
|
||||
|
||||
import Test.Response
|
||||
|
||||
|
||||
|
||||
data ListPetsResponse
|
||||
= ListPetsResponse200 Pets (Data.Maybe.Maybe (Data.Text.Text))
|
||||
| ListPetsDefaultResponse Network.HTTP.Types.Status Error
|
||||
@ -465,8 +461,6 @@ import Test.Schemas.Pet
|
||||
|
||||
import Test.Response
|
||||
|
||||
|
||||
|
||||
data ShowPetByIdResponse
|
||||
= ShowPetByIdResponse200 Pet
|
||||
| ShowPetByIdDefaultResponse Network.HTTP.Types.Status Error
|
||||
@ -516,8 +510,6 @@ import qualified Web.HttpApiData
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
data Error = Error
|
||||
{
|
||||
code :: GHC.Int.Int32,
|
||||
@ -579,8 +571,6 @@ import qualified Web.HttpApiData
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
data Pet = Pet
|
||||
{
|
||||
id :: GHC.Int.Int64,
|
||||
@ -646,8 +636,6 @@ import qualified Web.HttpApiData
|
||||
|
||||
import Test.Schemas.Pet
|
||||
|
||||
|
||||
|
||||
type Pets = [ Pet ]
|
||||
---------------------
|
||||
test.cabal
|
||||
|
@ -384,6 +384,7 @@ instance Data.Aeson.FromJSON CreateUserRequestBody where
|
||||
parseJSON = Data.Aeson.withObject "CreateUserRequestBody" $ \o ->
|
||||
CreateUserRequestBody
|
||||
<$> o Data.Aeson..:? "nise"
|
||||
|
||||
newtype CreateUserResponseBody200 = CreateUserResponseBody200
|
||||
{
|
||||
name :: (Data.Maybe.Maybe (Data.Text.Text))
|
||||
@ -451,8 +452,6 @@ import Test.Schemas.Vehicle
|
||||
|
||||
import Test.Response
|
||||
|
||||
|
||||
|
||||
data GetUserResponse
|
||||
= GetUserResponse200 Vehicle
|
||||
| GetUserResponse404
|
||||
@ -502,8 +501,6 @@ import qualified Web.HttpApiData
|
||||
|
||||
import Test.Schemas.Vehicle
|
||||
|
||||
|
||||
|
||||
data Car = Car
|
||||
{
|
||||
has4WheelDrive :: (Data.Maybe.Maybe (GHC.Types.Bool)),
|
||||
@ -821,8 +818,6 @@ import qualified Web.HttpApiData
|
||||
import Test.Schemas.Car
|
||||
import Test.Schemas.Vehicle
|
||||
|
||||
|
||||
|
||||
data Plane = Plane
|
||||
{
|
||||
car :: (Data.Maybe.Maybe (Car)),
|
||||
@ -904,8 +899,6 @@ import qualified Web.HttpApiData
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
data Vehicle = Vehicle
|
||||
{
|
||||
id :: GHC.Int.Int,
|
||||
|
Loading…
Reference in New Issue
Block a user