GetShopTV / swagger2

Swagger 2.0 data model.
http://hackage.haskell.org/package/swagger2
BSD 3-Clause "New" or "Revised" License
74 stars 59 forks source link

Empty paths field omitted from schema #209

Closed paulyoung closed 4 years ago

paulyoung commented 4 years ago

According to the Swagger 2 spec, the paths field is required, and some tooling considers it to be an error when the field is omitted.

It's possible to generate such JSON using swagger2. I think "paths": {} should be emitted in the case where there are no paths.

paulyoung commented 4 years ago

I'm currently working around this with:

main :: IO ()
main = putStrLn . read . show . encode $ mySwagger
  where
    encode :: Swagger -> LByteString
    encode = Aeson.encode . addPathsField . Aeson.toJSON

    addPathsField :: Aeson.Value -> Aeson.Value
    addPathsField value
      | (Aeson.Object kvs) <- value =
          Aeson.Object $ HashMap.alter (Just . fromMaybe (Aeson.object [])) "paths" kvs
      | otherwise = value
fisx commented 4 years ago

Looks like a valid issue to me.

I did the easy part, and then I found that there is a lot of generics business going on in the aeson instances. Would you like to give it a shot?

fisx commented 4 years ago

no, wait, i have something.

fisx commented 4 years ago

I think #213 is a good enough fix now. Wasn't too hard if you value simplicity over elegance. :)