-
Notifications
You must be signed in to change notification settings - Fork 59
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
reuse toJSON instances #127
Comments
@fizruk can you suggest solution, please? |
If you write @fizruk We should add that note, and an example to http://hackage.haskell.org/package/swagger2-2.1.5/docs/Data-Swagger.html#g:4, shouldn't we? |
like instance ToSchema PaymentOptions where
declareNamedSchema _ = do
mIntSchema <- declareSchemaRef (Proxy :: Proxy (Maybe Int))
mPaymentTypeSchema <- declareSchemaRef (Proxy :: Proxy (Maybe PaymentMethod))
return $ NamedSchema (Just "PaymentOptions") $ mempty
& type_ .~ SwaggerObject
& properties .~
[ ("type", mPaymentTypeSchema)
, ("deffered", mIntSchema)
, ("installment", mIntSchema)
]
& required .~ [] |
@Pitometsu yes, that seems like a valid instance. Just two comments:
You have a few options to write your own
instance ToSchema PaymentOptions where
declareNamedSchema = genericDeclareNamedSchema defaultSchemaOptions
{ fieldNameModifier = f }
where
f "poPaymentType" = "type"
f "poPaymentNet" = "deffered"
f "poInstallment" = "installment"
f name = name
I myself rely mostly on the second option ( In any case even with deriving mechanisms you need to ensure that If you also use |
Thank you a lot for detailed answer, things become much more clear now. |
I think #127 (comment) should be added somewhere in the How to use this library section. |
E.g. I have type
And
ToJSON
instance like this:And auto-generated
ToSchema
instance:So, swagger would looks like:
But instead I expect to see something more like:
Without prefixes
The question is: how to do this?
The text was updated successfully, but these errors were encountered: