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

Add ToFormData class #30

Closed
fizruk opened this issue Dec 24, 2015 · 2 comments
Closed

Add ToFormData class #30

fizruk opened this issue Dec 24, 2015 · 2 comments

Comments

@fizruk
Copy link
Member

fizruk commented Dec 24, 2015

Form data is halfway between ParamSchema and Schema with an extra property that it can handle SwaggerFile. I think it makes sense to introduce a class ToFormData for that. Instances of this class can be derived generically for records where each field has a ParamSchema instance.

The correspondence of type-level and value-level classes is this:

  • ToParamSchemaToHttpApiData;
  • ToFormDataToFormUrlEncoded;
  • ToSchemaToJSON.

Having ToFormData class with Generic-based deriving should reduce a significant amount of boilerplate.

The problem I currently have with ToFormData class is that swagger2 model does not allow for this class to be pretty:

type FormDataParam =
  ( ParamSchema ParamOtherSchema
  , Maybe Bool -- required?
  , Maybe Bool -- allow empty values?
  )

class ToFormData a where
  toFormData :: proxy a -> HashMap ParamName FormDataParam

Basically, FormDataParam should be just Param with the restriction that ParamLocation is ParamFormData. But we cannot specify that constraint in current model.
Actually I don't know if we can specify it at all (without resorting to existentials like SomeParam).

For now we can define a data type for form data parameters together with conversion function:

data FormDataParam = FormDataParam
  { formDataParamDescription     :: Maybe Text
  , formDataParamRequired        :: Maybe Bool
  , formDataParamAllowEmptyValue :: Maybe Bool
  , formDataParamParamSchema     :: ParamSchema ParamOtherSchema
  }

formDataParamToParam :: FormDataParam -> Param
formDataParamToParam = ...

@dmjio what do you think about this hacky solution?

@fizruk
Copy link
Member Author

fizruk commented Sep 2, 2016

Forms are now in http-api-data-0.3!

@fizruk
Copy link
Member Author

fizruk commented Feb 22, 2018

Closing this as I don't currently see much use for this class.

@fizruk fizruk closed this as completed Feb 22, 2018
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