Remove some superflouos whitespace from generated code

This commit is contained in:
Alex Biehl 2022-06-12 15:04:08 +02:00 committed by Alexander Biehl
parent 51c5a0a8d4
commit 24e28b6c2d
13 changed files with 37 additions and 127 deletions

View File

@ -191,15 +191,14 @@ generate write packageName apiName extraPackages inputFile = do
codegenSchema name' normedType codegenSchema name' normedType
write path $ write path $
vsep $ vsep $
[ header, intersperse mempty $
mempty, concat
[ [ header,
externalDependencyCode, externalDependencyCode,
mempty, schemaDependencyCode
schemaDependencyCode, ],
mempty, codeForInlineDependencies,
vsep (intersperse mempty codeForInlineDependencies), [output]
mempty,
output
] ]
-- For each Operation, generate data types for the responses. -- For each Operation, generate data types for the responses.
@ -215,16 +214,15 @@ generate write packageName apiName extraPackages inputFile = do
traverse (uncurry codegenSchema) inlineDefinitions traverse (uncurry codegenSchema) inlineDefinitions
responsesCode <- codegenResponses resolver operation responsesCode <- codegenResponses resolver operation
write path $ write path $
vsep vsep $
[ header, intersperse mempty $
mempty, concat
[ [ header,
importsCode, importsCode,
mempty, codegenExtraResponseModuleDependencies apiName
codegenExtraResponseModuleDependencies apiName, ],
mempty, codeForInlineDefinitions,
vsep codeForInlineDefinitions, [responsesCode]
mempty,
responsesCode
] ]
-- Generate auxiliary definitions in Response.hs -- Generate auxiliary definitions in Response.hs
@ -284,17 +282,14 @@ generate write packageName apiName extraPackages inputFile = do
operations operations
write path $ write path $
vsep vsep $
intersperse
mempty
[ header, [ header,
mempty,
codegenExtraApiModuleDependencies apiName, codegenExtraApiModuleDependencies apiName,
mempty,
externalDependencyCode, externalDependencyCode,
mempty,
schemaDependencyCode, schemaDependencyCode,
mempty,
responseDependencyCode, responseDependencyCode,
mempty,
operationsCode operationsCode
] ]

View File

@ -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 :: Monad m => Name -> ObjectType (Named Type) -> m (Doc ann)
codegenObjectType typName ObjectType {..} 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 :: Bool -> Doc ann -> Doc ann
codegenRequiredOptionalFieldType True doc = doc 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]
)

View File

@ -344,8 +344,6 @@ import qualified Web.HttpApiData
import Test.Response import Test.Response
data TestResponse data TestResponse
= TestResponse200 Network.Wai.StreamingBody = TestResponse200 Network.Wai.StreamingBody
@ -394,8 +392,6 @@ import qualified Web.HttpApiData
import Test.Response import Test.Response
data Test2Response data Test2Response
= Test2Response200 Data.Aeson.Value = Test2Response200 Data.Aeson.Value
deriving (Show) deriving (Show)

View File

@ -330,8 +330,6 @@ import Test.Schemas.Test
import Test.Response import Test.Response
data TestResponse data TestResponse
= TestResponse200 Test = TestResponse200 Test
deriving (Show) deriving (Show)
@ -378,8 +376,6 @@ import qualified Web.HttpApiData
data Test = Test data Test = Test
{ {
dateProp :: (Data.Maybe.Maybe (Data.Time.Day)), dateProp :: (Data.Maybe.Maybe (Data.Time.Day)),

View File

@ -333,8 +333,6 @@ import Test.Schemas.Package
import Test.Response import Test.Response
data DummyResponse data DummyResponse
= DummyResponse200 Package = DummyResponse200 Package
deriving (Show) deriving (Show)
@ -382,8 +380,6 @@ import qualified Web.HttpApiData
import Test.Schemas.PackageBase import Test.Schemas.PackageBase
import Test.Schemas.PackageType import Test.Schemas.PackageType
data DockerPackage = DockerPackage data DockerPackage = DockerPackage
{ {
backendRegistry :: (Data.Maybe.Maybe (Data.Text.Text)), backendRegistry :: (Data.Maybe.Maybe (Data.Text.Text)),
@ -470,8 +466,6 @@ import qualified Web.HttpApiData
import Test.Schemas.PackageBase import Test.Schemas.PackageBase
import Test.Schemas.PackageType import Test.Schemas.PackageType
data FilePackage = FilePackage data FilePackage = FilePackage
{ {
id :: Data.Text.Text, id :: Data.Text.Text,
@ -558,8 +552,6 @@ import qualified Web.HttpApiData
import Test.Schemas.DockerPackage import Test.Schemas.DockerPackage
import Test.Schemas.FilePackage import Test.Schemas.FilePackage
data Package data Package
= PackageFilePackage FilePackage = PackageFilePackage FilePackage
| PackageDockerPackage DockerPackage | PackageDockerPackage DockerPackage
@ -613,8 +605,6 @@ import qualified Web.HttpApiData
import Test.Schemas.PackageType import Test.Schemas.PackageType
data PackageBase = PackageBase data PackageBase = PackageBase
{ {
id :: Data.Text.Text, id :: Data.Text.Text,
@ -692,8 +682,6 @@ import qualified Web.HttpApiData
data PackageType data PackageType
= PackageTypeDocker = PackageTypeDocker
| PackageTypeFile | PackageTypeFile

View File

@ -397,8 +397,6 @@ import Test.Schemas.Package
import Test.Response import Test.Response
data ListPackagesResponse data ListPackagesResponse
= ListPackagesResponse200 Package = ListPackagesResponse200 Package
deriving (Show) deriving (Show)
@ -609,8 +607,6 @@ import Test.Schemas.Order
import Test.Response import Test.Response
data ListPackages4Response data ListPackages4Response
= ListPackages4Response201 = ListPackages4Response201
deriving (Show) deriving (Show)
@ -657,8 +653,6 @@ import Test.Schemas.InsightsTimeRange
import Test.Response import Test.Response
data ListPackages5Response data ListPackages5Response
= ListPackages5Response201 = ListPackages5Response201
deriving (Show) deriving (Show)
@ -705,8 +699,6 @@ import qualified Web.HttpApiData
data InsightsTimeRange data InsightsTimeRange
= InsightsTimeRangeLastWeek = InsightsTimeRangeLastWeek
| InsightsTimeRangeLastMonth | InsightsTimeRangeLastMonth
@ -782,8 +774,6 @@ import qualified Web.HttpApiData
data Order data Order
= OrderAsc = OrderAsc
| OrderDesc | OrderDesc
@ -853,8 +843,6 @@ import qualified Web.HttpApiData
data Package data Package
= PackageDOCKER = PackageDOCKER
| PackagePYTHON | PackagePYTHON

View File

@ -334,8 +334,6 @@ import Test.Schemas.Test
import Test.Response import Test.Response
data TestResponse data TestResponse
= TestResponse200 Test = TestResponse200 Test
deriving (Show) deriving (Show)
@ -382,8 +380,6 @@ import qualified Scarf.Hashids
newtype Test = Test newtype Test = Test
{ {
test1 :: (Data.Maybe.Maybe (Scarf.Hashids.Hashid Int32)) test1 :: (Data.Maybe.Maybe (Scarf.Hashids.Hashid Int32))

View File

@ -361,8 +361,6 @@ import Test.Schemas.Test
import Test.Response import Test.Response
data TestResponse data TestResponse
= TestResponse200 Test = TestResponse200 Test
deriving (Show) deriving (Show)
@ -409,8 +407,6 @@ import qualified Web.HttpApiData
import Test.Response import Test.Response
data Test1Response data Test1Response
= Test1Response201 (Data.Maybe.Maybe (Data.Text.Text)) = Test1Response201 (Data.Maybe.Maybe (Data.Text.Text))
deriving (Show) deriving (Show)
@ -457,8 +453,6 @@ import qualified Web.HttpApiData
import Test.Response import Test.Response
data Test2Response data Test2Response
= Test2Response201 Data.Text.Text = Test2Response201 Data.Text.Text
deriving (Show) deriving (Show)
@ -505,8 +499,6 @@ import qualified Web.HttpApiData
data Test = Test data Test = Test
{ {
dateProp :: (Data.Maybe.Maybe (Data.Time.Day)), dateProp :: (Data.Maybe.Maybe (Data.Time.Day)),

View File

@ -360,8 +360,6 @@ import Test.Schemas.Packages
import Test.Response import Test.Response
data ListPackagesResponse data ListPackagesResponse
= ListPackagesResponse200 Packages = ListPackagesResponse200 Packages
deriving (Show) deriving (Show)
@ -408,8 +406,6 @@ import Test.Schemas.Package
import Test.Response import Test.Response
data ListPackages2Response data ListPackages2Response
= ListPackages2Response200 [ Package ] = ListPackages2Response200 [ Package ]
deriving (Show) deriving (Show)
@ -456,8 +452,6 @@ import Test.Schemas.Inline
import Test.Response import Test.Response
data ListPackages3Response data ListPackages3Response
= ListPackages3Response200 [ Inline ] = ListPackages3Response200 [ Inline ]
deriving (Show) deriving (Show)
@ -563,8 +557,6 @@ import qualified Web.HttpApiData
newtype Package = Package newtype Package = Package
{ {
name :: (Data.Maybe.Maybe (Data.Text.Text)) name :: (Data.Maybe.Maybe (Data.Text.Text))
@ -622,8 +614,6 @@ import qualified Web.HttpApiData
import Test.Schemas.Package import Test.Schemas.Package
type Packages = [ Package ] type Packages = [ Package ]
--------------------- ---------------------
test.cabal test.cabal

View File

@ -330,8 +330,6 @@ import Test.Schemas.Test
import Test.Response import Test.Response
data TestResponse data TestResponse
= TestResponse200 Test = TestResponse200 Test
deriving (Show) deriving (Show)
@ -378,8 +376,6 @@ import qualified Web.HttpApiData
data Test = Test data Test = Test
{ {
a :: (Data.Maybe.Maybe (GHC.Int.Int32)), a :: (Data.Maybe.Maybe (GHC.Int.Int32)),

View File

@ -360,8 +360,6 @@ import Test.Schemas.PetOrPackage
import Test.Response import Test.Response
data ListPackagesResponse data ListPackagesResponse
= ListPackagesResponse200 PetOrPackage = ListPackagesResponse200 PetOrPackage
deriving (Show) deriving (Show)
@ -408,8 +406,6 @@ import Test.Schemas.Inline
import Test.Response import Test.Response
data ListPackages2Response data ListPackages2Response
= ListPackages2Response200 Inline = ListPackages2Response200 Inline
deriving (Show) deriving (Show)
@ -456,8 +452,6 @@ import Test.Schemas.Inline2
import Test.Response import Test.Response
data ListPackages3Response data ListPackages3Response
= ListPackages3Response200 Inline2 = ListPackages3Response200 Inline2
deriving (Show) deriving (Show)
@ -677,8 +671,6 @@ import qualified Web.HttpApiData
newtype Package = Package newtype Package = Package
{ {
type' :: (Data.Maybe.Maybe (Data.Text.Text)) type' :: (Data.Maybe.Maybe (Data.Text.Text))
@ -736,8 +728,6 @@ import qualified Web.HttpApiData
newtype Pet = Pet newtype Pet = Pet
{ {
type' :: (Data.Maybe.Maybe (Data.Text.Text)) type' :: (Data.Maybe.Maybe (Data.Text.Text))
@ -796,8 +786,6 @@ import qualified Web.HttpApiData
import Test.Schemas.Package import Test.Schemas.Package
import Test.Schemas.Pet import Test.Schemas.Pet
data PetOrPackage data PetOrPackage
= PetOrPackagePet Pet = PetOrPackagePet Pet
| PetOrPackagePackage Package | PetOrPackagePackage Package

View File

@ -361,8 +361,6 @@ import Test.Schemas.Error
import Test.Response import Test.Response
data CreatePetsResponse data CreatePetsResponse
= CreatePetsResponse201 = CreatePetsResponse201
| CreatePetsDefaultResponse Network.HTTP.Types.Status Error | CreatePetsDefaultResponse Network.HTTP.Types.Status Error
@ -413,8 +411,6 @@ import Test.Schemas.Pets
import Test.Response import Test.Response
data ListPetsResponse data ListPetsResponse
= ListPetsResponse200 Pets (Data.Maybe.Maybe (Data.Text.Text)) = ListPetsResponse200 Pets (Data.Maybe.Maybe (Data.Text.Text))
| ListPetsDefaultResponse Network.HTTP.Types.Status Error | ListPetsDefaultResponse Network.HTTP.Types.Status Error
@ -465,8 +461,6 @@ import Test.Schemas.Pet
import Test.Response import Test.Response
data ShowPetByIdResponse data ShowPetByIdResponse
= ShowPetByIdResponse200 Pet = ShowPetByIdResponse200 Pet
| ShowPetByIdDefaultResponse Network.HTTP.Types.Status Error | ShowPetByIdDefaultResponse Network.HTTP.Types.Status Error
@ -516,8 +510,6 @@ import qualified Web.HttpApiData
data Error = Error data Error = Error
{ {
code :: GHC.Int.Int32, code :: GHC.Int.Int32,
@ -579,8 +571,6 @@ import qualified Web.HttpApiData
data Pet = Pet data Pet = Pet
{ {
id :: GHC.Int.Int64, id :: GHC.Int.Int64,
@ -646,8 +636,6 @@ import qualified Web.HttpApiData
import Test.Schemas.Pet import Test.Schemas.Pet
type Pets = [ Pet ] type Pets = [ Pet ]
--------------------- ---------------------
test.cabal test.cabal

View File

@ -384,6 +384,7 @@ instance Data.Aeson.FromJSON CreateUserRequestBody where
parseJSON = Data.Aeson.withObject "CreateUserRequestBody" $ \o -> parseJSON = Data.Aeson.withObject "CreateUserRequestBody" $ \o ->
CreateUserRequestBody CreateUserRequestBody
<$> o Data.Aeson..:? "nise" <$> o Data.Aeson..:? "nise"
newtype CreateUserResponseBody200 = CreateUserResponseBody200 newtype CreateUserResponseBody200 = CreateUserResponseBody200
{ {
name :: (Data.Maybe.Maybe (Data.Text.Text)) name :: (Data.Maybe.Maybe (Data.Text.Text))
@ -451,8 +452,6 @@ import Test.Schemas.Vehicle
import Test.Response import Test.Response
data GetUserResponse data GetUserResponse
= GetUserResponse200 Vehicle = GetUserResponse200 Vehicle
| GetUserResponse404 | GetUserResponse404
@ -502,8 +501,6 @@ import qualified Web.HttpApiData
import Test.Schemas.Vehicle import Test.Schemas.Vehicle
data Car = Car data Car = Car
{ {
has4WheelDrive :: (Data.Maybe.Maybe (GHC.Types.Bool)), has4WheelDrive :: (Data.Maybe.Maybe (GHC.Types.Bool)),
@ -821,8 +818,6 @@ import qualified Web.HttpApiData
import Test.Schemas.Car import Test.Schemas.Car
import Test.Schemas.Vehicle import Test.Schemas.Vehicle
data Plane = Plane data Plane = Plane
{ {
car :: (Data.Maybe.Maybe (Car)), car :: (Data.Maybe.Maybe (Car)),
@ -904,8 +899,6 @@ import qualified Web.HttpApiData
data Vehicle = Vehicle data Vehicle = Vehicle
{ {
id :: GHC.Int.Int, id :: GHC.Int.Int,