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

ToParamSchema class #17

Merged
merged 23 commits into from
Dec 10, 2015
Merged

ToParamSchema class #17

merged 23 commits into from
Dec 10, 2015

Conversation

fizruk
Copy link
Member

@fizruk fizruk commented Dec 8, 2015

Closes #16.

This PR is incomplete.

@fizruk
Copy link
Member Author

fizruk commented Dec 8, 2015

So here's some design problem:

We have Param, Items and Header all pretty similar:

  • Header is exactly Items with description;
  • Items is a restricted Param (without location, allowEmptyValue and without file type).

So we can probably factor out the common part (Items) and only consider that for a class (ignoring location).

@fizruk
Copy link
Member Author

fizruk commented Dec 8, 2015

Okay, so I've moved type, format and items to SchemaCommon.
Now it represents the thing we should make a class for, that can be used for Param, Items and Header.

At this moment I realize that Schema also has SchemaCommon and that we can have something like this:

class ToSchemaCommon a t i where
  toSchemaCommon :: proxy a -> SchemaCommon t i

-- | Generate a 'NamedSchema' for a type with 'ToSchemaCommon' instance.
-- This can be used as an implementation of `toNamedSchema` for plain types.
toNamedSchemaCommon ::
  (..., ToSchemaCommon a (SwaggerType Schema) SchemaItems)
  => proxy a -> NamedSchema
toNamedSchemaCommon _ =
  ( genericToName (Proxy :: Proxy a)
  , mempty & schemaSchemaCommon .~ toSchemaCommon (Proxy :: Proxy a) )

With toNamedSchemaCommon it should be possible to avoid some code duplication (for non-object schemas):

instance ToSchemaCommon Bool t i where ...

instance ToSchema Bool where toNamedSchema = toNamedSchemaCommon

@dmjio
Copy link
Collaborator

dmjio commented Dec 8, 2015

That's fine with me.

@fizruk
Copy link
Member Author

fizruk commented Dec 9, 2015

I think the PR is ready for merge.

@dmjio please, take a look.

Once this one is merged I am going for resolving #13.
Then the package should finally be ready to be used in servant-swagger.

@dmjio
Copy link
Collaborator

dmjio commented Dec 10, 2015

👍

fizruk added a commit that referenced this pull request Dec 10, 2015
@fizruk fizruk merged commit e89e06f into master Dec 10, 2015
@fizruk fizruk deleted the to-param-#16 branch December 10, 2015 21:05
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

Successfully merging this pull request may close these issues.

2 participants