@@ -722,9 +722,6 @@ deriveJSONDefault ''Scheme
722722deriveJSON' ''Tag
723723deriveJSON' ''ExternalDocs
724724
725−deriveToJSON' ''Operation
726−deriveToJSON' ''Response
727−deriveToJSON' ''PathItem
728725deriveToJSON' ''Xml
729726
730727-- =======================================================================
@@ -747,7 +744,7 @@ instance ToJSON OAuth2Flow where
747744 , "tokenUrl" .= tokenUrl ]
748745
749746instance ToJSON OAuth2Params where
750− toJSON = genericToJSONWithSub "flow" (jsonPrefix "oauth2")
747+ toJSON = omitEmpties . genericToJSONWithSub "flow" (jsonPrefix "oauth2")
751748
752749instance ToJSON SecuritySchemeType where
753750 toJSON SecuritySchemeBasic
@@ -760,7 +757,7 @@ instance ToJSON SecuritySchemeType where
760757 <+> object [ "type" .= ("oauth2" :: Text) ]
761758
762759instance ToJSON Swagger where
763− toJSON = addVersion . genericToJSON (jsonPrefix "")
760+ toJSON = omitEmpties . addVersion . genericToJSON (jsonPrefix "")
764761 where
765762 addVersion (Object o) = Object (HashMap.insert "swagger" "2.0" o)
766763 addVersion _ = error "impossible"
@@ -769,7 +766,7 @@ instance ToJSON SecurityScheme where
769766 toJSON = genericToJSONWithSub "type" (jsonPrefix "securityScheme")
770767
771768instance ToJSON Schema where
772− toJSON = genericToJSONWithSub "paramSchema" (jsonPrefix "schema")
769+ toJSON = omitEmpties . genericToJSONWithSub "paramSchema" (jsonPrefix "schema")
773770
774771instance ToJSON Header where
775772 toJSON = genericToJSONWithSub "paramSchema" (jsonPrefix "header")
@@ -804,7 +801,17 @@ instance ToJSON SchemaItems where
804801 toJSON (SchemaItemsArray xs) = toJSON xs
805802
806803instance ToJSON Responses where
807− toJSON (Responses def rs) = toJSON (hashMapMapKeys show rs) <+> object [ "default" .= def ]
804+ toJSON (Responses def rs) = omitEmpties $
805+ toJSON (hashMapMapKeys show rs) <+> object [ "default" .= def ]
806+
807+instance ToJSON Response where
808+ toJSON = omitEmpties . genericToJSON (jsonPrefix "response")
809+
810+instance ToJSON Operation where
811+ toJSON = omitEmpties . genericToJSON (jsonPrefix "operation")
812+
813+instance ToJSON PathItem where
814+ toJSON = omitEmpties . genericToJSON (jsonPrefix "pathItem")
808815
809816instance ToJSON Example where
810817 toJSON = toJSON . Map.mapKeys show . getExample