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

Unused definitions produced for simple newtypes #37

Closed
fizruk opened this issue Jan 16, 2016 · 0 comments
Closed

Unused definitions produced for simple newtypes #37

fizruk opened this issue Jan 16, 2016 · 0 comments

Comments

@fizruk
Copy link
Member

fizruk commented Jan 16, 2016

Generic mechanism sometimes declares unused definitions.
Below is an example of when this happens.

Declare a common type with a named schema:

>>> newtype Id = Id String deriving Generic
>>> instance ToParamSchema Id where toParamSchema _ = toParamSchema (Proxy :: Proxy String) & schemaFormat ?~ "uuid"
>>> instance ToSchema Id where declareNamedSchema = return . paramSchemaToNamedSchema defaultSchemaOptions

Wrap that named typed in a simple newtype:

>>> newtype UserId = UserId Id deriving Generic
>>> instance ToSchema UserId

Generic mechanism does not need to produce definition for Id, but it does so nonetheless.

>>> encode $ runDeclare (declareNamedSchema (Proxy :: Proxy UserId)) mempty
"[{\"Id\":{\"format\":\"uuid\",\"type\":\"string\"}},[\"UserId\",{\"format\":\"uuid\",\"type\":\"string\"}]]"

Fix should be simple enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant