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

Changes introduced by aeson-1 #69

Closed
phadej opened this issue Aug 7, 2016 · 5 comments
Closed

Changes introduced by aeson-1 #69

phadej opened this issue Aug 7, 2016 · 5 comments

Comments

@phadej
Copy link
Collaborator

phadej commented Aug 7, 2016

I'm not sure if we should take them into account. At least how Map and HashMap can be serialised in aeson-1.

Please discuss.

@fizruk
Copy link
Member

fizruk commented Aug 7, 2016

We should change these ToSchema instances:

instance ToSchema a => ToSchema (Map T.Text  a)
instance ToSchema a => ToSchema (Map TL.Text a)

instance ToSchema a => ToSchema (HashMap String  a)
instance ToSchema a => ToSchema (HashMap T.Text  a)
instance ToSchema a => ToSchema (HashMap TL.Text a)

To do that we have to either introduce a new ToSchemaKey class corresponding to ToJSONKey, or to use ToParamSchema. I am not sure which we should use.

The rest of the changes we can probably safely ignore.

@phadej
Copy link
Collaborator Author

phadej commented Aug 7, 2016

From ToJSONKey we'll know whether Map is serialised as object or array,
I'm not sure whether swagger spec supports specifying what kind the keys are in Dict<key,value? So this is almost correct:

instance (ToJSONKey k, ToSchema a) => ToSchema (Map k a) where
  declareNamedSchema _ | isObjectEncoding (Proxy :: Proxy k) = do
    schema <- declareSchemaRef (Proxy :: Proxy a)
    return $ unnamed $ mempty
      & type_ .~ SwaggerObject
      & additionalProperties ?~ schema
  where
    isObjectEncoding p = ...

@fizruk
Copy link
Member

fizruk commented Aug 8, 2016

Hmm, you're right, toJSONKey provides all necessary info:

instance (ToJSONKey k, ToSchema a) => ToSchema (Map k a) where
  declareNamedSchema _ = case toJSONKey :: ToJSONKeyFunction a of
    ToJSONKeyText  _ _ -> declareObjectMapSchema
    ToJSONKeyValue _ _ -> declareNamedSchema (Proxy :: Proxy [(k, a)])
  where
    declareObjectMapSchema = do
      schema <- declareSchemaRef (Proxy :: Proxy a)
      return $ unnamed $ mempty
        & type_ .~ SwaggerObject
        & additionalProperties ?~ schema

@fizruk
Copy link
Member

fizruk commented Aug 8, 2016

@phadej do we need to address any of the other changes aeson-1.0.0.0 introduced?

@fizruk
Copy link
Member

fizruk commented Aug 8, 2016

Hmm, that instance above requires also ToSchema k which is only used for array representation, but I guess that's not a problem.

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

2 participants