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

Support for Primitive (simple) types in Definitions in Swagger Doc #14

Open
kahlil29 opened this issue Feb 22, 2019 · 5 comments
Open
Assignees
Labels
Webapi-Swagger All issues related to Webapi-swagger (generation of Webapi contracts from Swagger Docs)

Comments

@kahlil29
Copy link
Contributor

The code is written in such a way that we expect the definitions of data in the Definitions HashMap to be complex Arrays/Objects.
Consider the following Definition entry in the swagger Doc :

  CustomRoleKeyOrId:
    description: The 20-hexdigit id or the key for a custom role.
    example: revenue-team
    type: string

For this we should probably create a type alias
type CustomRoleKeyOrId = Text

@kahlil29 kahlil29 self-assigned this Feb 22, 2019
@kahlil29 kahlil29 added the Webapi-Swagger All issues related to Webapi-swagger (generation of Webapi contracts from Swagger Docs) label Feb 22, 2019
@ersran9
Copy link
Contributor

ersran9 commented Feb 22, 2019 via email

@kahlil29
Copy link
Contributor Author

@ersran9 Okay.
I was thinking of extending the current type we store in the State
It is currently

data CreateNewType = SumType String [String] [String] | ProductType NewData 

data NewData = NewData
  {
    mName :: String
  , mRecordTypes :: InnerRecords
  }

Or alternatively, when processing the final State value and generating the types, I could add a check for ProductTypes (if they have only record entry in the list then make a newtype instead of data ...

@ersran9
Copy link
Contributor

ersran9 commented Feb 22, 2019 via email

@kahlil29
Copy link
Contributor Author

The CreateNewType data type was already extended to support TypeAlias (type alias) while fixing #11

So I think what is remaining for this ticket to be solved is to implement the check when parsing the State (and generating types) to convert ProductType values with only one record to NewType.

@kahlil29
Copy link
Contributor Author

kahlil29 commented Apr 1, 2019

As per the discussion today with @ersran9
We will remove the TypeAlias implementation and instead replace it by the strategy of creating

data SomeNewType = SomeNewType 
  {nTypeRec :: Text}

In the future, the ideal thing to do would be to generate it as
newtype SomeNewType = SomeNewType Text

If it's possible (not too expensive and quick), while implementing, we can directly implement the newtype method.

For now we can use the ProductType constructor of CreateNewType to replace TypeAliases

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
None yet
Development

No branches or pull requests

2 participants