Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webapi-Swagger : Restructure generation of Types from Swagger doc. #31

Open
kahlil29 opened this issue Apr 1, 2019 · 1 comment
Open
Assignees
Labels
Webapi-Swagger All issues related to Webapi-swagger (generation of Webapi contracts from Swagger Docs)

Comments

@kahlil29
Copy link
Contributor

kahlil29 commented Apr 1, 2019

This change involves breaking down the generated types into modules.
The planned structure would look like :

New Types Generation Directory Structure

Some things we need to take care of while implementing this change :

  • All imports will be qualified (even in Contract.hs)
  • The modules in GlobalDefinitions would need to be imported into all (all routes, all methods) other Types.hs files.
  • In ResponseDefinitions.hs , we would also need to generate the Header types (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.
@kahlil29 kahlil29 added the Webapi-Swagger All issues related to Webapi-swagger (generation of Webapi contracts from Swagger Docs) label Apr 1, 2019
@kahlil29 kahlil29 self-assigned this Apr 1, 2019
@kahlil29
Copy link
Contributor Author

kahlil29 commented Apr 1, 2019

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 :

  1. Create folder with RouteName name
  2. Create folder with MethodName name
  3. Create a Types.hs module inside the above created folder.
  4. 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)

@kahlil29 kahlil29 moved this from Done to In progress in Webapi-Swagger Restructuring Autogen files Apr 2, 2019
kahlil29 added a commit that referenced this issue Apr 4, 2019
- New Types module, new Types added
- State Type changed to add LevelInfo
- Replace TypeAlias with HNewType
kahlil29 added a commit that referenced this issue Apr 4, 2019
- Pass Route and Method info into lower stages for proper LevelInfo
- Add all generated module names into cabal file
kahlil29 added a commit that referenced this issue Apr 4, 2019
Add wrapper type even if ApiOut or ApiErr are single types. Related to changes for #31
@kahlil29 kahlil29 moved this from In progress to Testing/Review in Webapi-Swagger Restructuring Autogen files Apr 4, 2019
@kahlil29 kahlil29 moved this from Testing/Review to Done in Webapi-Swagger Restructuring Autogen files Apr 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Webapi-Swagger All issues related to Webapi-swagger (generation of Webapi contracts from Swagger Docs)
Projects
No open projects
Development

No branches or pull requests

1 participant