-
Notifications
You must be signed in to change notification settings - Fork 37
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
Generics/TH deriving #2
Comments
@fizruk, For the most part, yes. Apart from
data SwaggerParamType =
StringSwagParam
| NumberSwagParam
| IntegerSwagParam
| BooleanSwagParam
| ArraySwagParam
| FileSwagParam
class ToSwaggerParamType a where toSwaggerParamType :: Proxy a -> SwaggerParamType
instance ToSwaggerParamType Int where toSwaggerParamType = const IntegerSwagParam
instance ToSwaggerParamType Integer where toSwaggerParamType = const IntegerSwagParam
instance ToSwaggerParamType UUID.UUID where toSwaggerParamType = const StringSwagParam
instance ToSwaggerParamType String where toSwaggerParamType = const StringSwagParam
instance ToSwaggerParamType Text where toSwaggerParamType = const StringSwagParam
instance ToSwaggerParamType L.Text where toSwaggerParamType = const StringSwagParam
instance ToSwaggerParamType BL8.ByteString where toSwaggerParamType = const StringSwagParam
instance ToSwaggerParamType B8.ByteString where toSwaggerParamType = const StringSwagParam
instance ToSwaggerParamType Double where toSwaggerParamType = const NumberSwagParam
instance ToSwaggerParamType Float where toSwaggerParamType = const NumberSwagParam
instance ToSwaggerParamType Bool where toSwaggerParamType Proxy = BooleanSwagParam
instance
ToSwaggerParamType a => ToSwaggerParamType [a] where
toSwaggerParamType _ = ArraySwagParam So it would be easy to do something like, newtype UserID = UserID Int deriving (ToSwaggerParamType) So I think In regards to I'd like to avoid template haskell if possible, since it breaks modularity of definitions in a module. |
FWIW, I can confirm that there's no reason to switch from generics to TH just because you need some additional parameterization. Even aeson allows this (in one of several conceivable ways). In aeson, you have generic implementations of instance FromJSON Foo where
parseJSON = genericParseJSON myOptions to use different options. That's still rather verbose compared to an empty instance declaration, but not exactly boilerplate. There are a number of ways to reduce the syntactic clutter somewhat more. Which one's best depends a bit on personal taste. I can go into more details here or on IRC. |
Closed in #9. |
First question is which classes should gain Generics/TH implementation?
My thoughts:
ToSwaggerParamType
might have a Generics-based default implementation;ToSwaggerModel
should have a TH derivation (Generics will not be a good choice here because users will most likely want to customize generated instance with something similar toderiveJSON
options);ToModelExample
might have a Generics-based default implementation (BTW, is this class used anywhere?);I would say that
ToSwaggerModel
is responsible for the most of the boilerplate currently (apart fromRouteInfo
), so it should be addressed first.Does this make sense?
The text was updated successfully, but these errors were encountered: