Closed pbrisbin closed 5 months ago
FWIW, changing StringifyModel
to assume (a string-like) ToJSON
rather than Show
makes it work for me,
class Aeson.ToJSON a => StringifyModel a where
-- | Stringifies a showable value
--
-- >>> stringifyModel "Test"
-- "Test"
--
-- >>> stringifyModel 123
-- "123"
stringifyModel :: a -> Text
-- instance StringifyModel String where
-- -- stringifyModel :: String -> String
-- stringifyModel = T.pack
-- instance StringifyModel Text where
-- -- stringifyModel :: Text -> String
-- stringifyModel = id
instance {-# OVERLAPS #-} Aeson.ToJSON a => StringifyModel a where
-- stringifyModel :: Show a => a -> String
stringifyModel x = case Aeson.toJSON x of
Aeson.String t -> t
v -> error $ "Value did not encode to a JSON string: " <> show v
Relying on any super-class and an overlaps instance feels kind of sketch, but if you're going to do it, I think ToJSON
does make more sense than Show
for this -- at least, it's far more likely to do the right thing for any given type, IMO.
Hey @pbrisbin Thank you for the report, this is a good catch! I have implemented a fix based on your suggestion here: https://github.com/Haskell-OpenAPI-Code-Generator/Haskell-OpenAPI-Client-Code-Generator/pull/100 I'll close the issue but let me know if it does not work for your 🙏
Thanks for the quick fix! I'll be able to test it out later this week.
I have a path specified as,
The generated enumeration looks OK, complete with
ToJSON
,But when I make a request, I see the following
path
is used:Looking in the code, it's meant to use
StringifyModel
, but there is no instance for any models anywhere, meaning (I think) it's using the defaultShow a
-based instance, which is why it's producing a path like this. It seems to happen everywhere making the client pretty useless.Am I missing some way to make this work?
I'm currently using a un-released version, since the released version does not work with aeson-2,