webapi
webapi copied to clipboard
Webapi-Swagger : Restructure generation of Types from Swagger doc.
This change involves breaking down the generated types into modules. The planned structure would look like :

Some things we need to take care of while implementing this change :
- All imports will be qualified (even in
Contract.hs) - The modules in
GlobalDefinitionswould need to be imported into all (all routes, all methods) otherTypes.hsfiles. - In
ResponseDefinitions.hs, we would also need to generate theHeadertypes (if any are specified in the Swagger Doc) for the global response types (if any) - We need to take care that while generating the
Contract, we are referring to the correct types at correct places (correct qualification) especially for Params.
Current approach (for collecting types and for generation) is :
Store (in state) a Hashmap with the following structure :
HashMap LevelInfo [ContractInnerType]
data LevelInfo = Global GlobalLocalType | Route (RouteName, MethodName) | Local GlobalLocalType (RouteName, MethodName)
data GlobalLocalType = DefinitionTy | ResponseTy | ParamTy
data ContractInnerType = ParamType CreateDataType | ResponseType CreateDataType | DefinitionType CreateDataType
data CreateDataType = SumType DualSumType | ProductType NewData
data DualSumType = BasicEnum String [String] [String] | ComplexSumType String [(String, String)]
data NewData = NewData
{
mName :: String
, mRecordTypes :: InnerRecords
}
data ApiTypeDetails = ApiTypeDetails
{
apiOut :: (LevelInfo, String)
, apiErr :: (LevelInfo, Maybe String)
, formParam :: (LevelInfo, Maybe String)
, queryParam :: (LevelInfo, Maybe String)
, fileParam :: (LevelInfo, Maybe String)
, headerIn :: (LevelInfo, Maybe String)
, requestBody :: (LevelInfo, Maybe String)
, contentTypes :: (LevelInfo, Maybe String)
, headerOut :: (LevelInfo, Maybe String)
, hasXML :: Bool
}
After we complete collection/calculation of all types from the Swagger Doc, we will generate the Contract and then do the following steps :
- Create folder with RouteName name
- Create folder with MethodName name
- Create a
Types.hsmodule inside the above created folder. - Generate/Write all the types necessary for this module (route-method) to the file. (we would also need to add the appropriate Module declaration, imports and any language extensions that are necessary)