diff --git a/src/Data/Swagger/Internal.hs b/src/Data/Swagger/Internal.hs index 8506d43..2022c12 100644 --- a/src/Data/Swagger/Internal.hs +++ b/src/Data/Swagger/Internal.hs @@ -816,9 +816,9 @@ referencedToJSON :: ToJSON a => Text -> Referenced a -> Value referencedToJSON prefix (Ref (Reference ref)) = object [ "$ref" .= (prefix <> ref) ] referencedToJSON _ (Inline x) = toJSON x -instance ToJSON (Referenced Schema) where toJSON = referencedToJSON "#/definitions/" -instance ToJSON (Referenced Parameter) where toJSON = referencedToJSON "#/parameters/" -instance ToJSON (Referenced Response) where toJSON = referencedToJSON "#/responses/" +instance ToJSON (Referenced Schema) where toJSON = referencedToJSON "#/definitions/" +instance ToJSON (Referenced Param) where toJSON = referencedToJSON "#/parameters/" +instance ToJSON (Referenced Response) where toJSON = referencedToJSON "#/responses/" instance ToJSON (SwaggerType t) where toJSON SwaggerArray = "array" @@ -976,9 +976,9 @@ referencedParseJSON prefix js@(Object o) = do Nothing -> fail $ "expected $ref of the form \"" <> Text.unpack prefix <> "*\", but got " <> show s Just suffix -> pure (Reference suffix) -instance FromJSON (Referenced Schema) where parseJSON = referencedParseJSON "#/definitions/" -instance FromJSON (Referenced Parameter) where parseJSON = referencedParseJSON "#/parameters/" -instance FromJSON (Referenced Response) where parseJSON = referencedParseJSON "#/responses/" +instance FromJSON (Referenced Schema) where parseJSON = referencedParseJSON "#/definitions/" +instance FromJSON (Referenced Param) where parseJSON = referencedParseJSON "#/parameters/" +instance FromJSON (Referenced Response) where parseJSON = referencedParseJSON "#/responses/" instance FromJSON Xml where parseJSON = genericParseJSON (jsonPrefix "xml") diff --git a/src/Data/Swagger/Schema/Validation.hs b/src/Data/Swagger/Schema/Validation.hs index 5b3c8f7..ba595a5 100644 --- a/src/Data/Swagger/Schema/Validation.hs +++ b/src/Data/Swagger/Schema/Validation.hs @@ -1,4 +1,5 @@ {-# LANGUAGE DeriveFunctor #-} +{-# LANGUAGE GADTs #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE PackageImports #-} {-# LANGUAGE RankNTypes #-} @@ -87,13 +88,13 @@ validateWithSchema schema value validateType = case (schema ^. schemaType, value) of - (SchemaNull, Null) -> valid - (SchemaBoolean, Bool _) -> valid - (SchemaInteger, Number n) -> validateInteger n - (SchemaNumber, Number n) -> validateNumber n - (SchemaString, String s) -> validateString s - (SchemaArray, Array xs) -> validateArray xs - (SchemaObject, Object o) -> validateObject o + (SwaggerNull, Null) -> valid + (SwaggerBoolean, Bool _) -> valid + (SwaggerInteger, Number n) -> validateInteger n + (SwaggerNumber, Number n) -> validateNumber n + (SwaggerString, String s) -> validateString s + (SwaggerArray, Array xs) -> validateArray xs + (SwaggerObject, Object o) -> validateObject o (t, _) -> invalid $ "expected JSON value of type " ++ show t ++ ": " ++ show (encode value) validateInteger n