git.iko.soy/typeable/openapi3
on master help sign in
Update code after a rebase
b335a6dNickolay Kudasov
src/Data/Swagger/Schema/Validation.hs+7−6
@@ -95,6 +95,7 @@ validateWithSchema schema value
95 (SwaggerString, String s) -> validateString s
95 (SwaggerString, String s) -> validateString s
96 (SwaggerArray, Array xs) -> validateArray xs
96 (SwaggerArray, Array xs) -> validateArray xs
97 (SwaggerObject, Object o) -> validateObject o
97 (SwaggerObject, Object o) -> validateObject o
98+ (t, _) -> invalid $ "expected JSON value of type " ++ show t ++ ": " ++ show (encode value)
98
99
99 validateInteger n
100 validateInteger n
100 = when (not (isInteger n)) (invalid $ "not an integer: " ++ show n)
101 = when (not (isInteger n)) (invalid $ "not an integer: " ++ show n)
@@ -141,23 +142,23 @@ validateWithSchema schema value
141 where
142 where
142 allUnique = Vector.length xs == HashSet.size (HashSet.fromList (Vector.toList xs))
143 allUnique = Vector.length xs == HashSet.size (HashSet.fromList (Vector.toList xs))
143
144
144− validateObject o = case schema ^. schemaDiscriminator of
145+ validateObject o = case schema ^. discriminator of
145 Just name -> validateWithSchemaRef (Ref (Reference name)) value
146 Just name -> validateWithSchemaRef (Ref (Reference name)) value
146 Nothing ->
147 Nothing ->
147− when' (fromIntegral (HashMap.size o) >) schemaMaxProperties
148+ when' (fromIntegral (HashMap.size o) >) maxProperties
148 (\n -> invalid $ "object size exceeds maximum (total number of properties should be <=" ++ show n ++ "): " ++ show (encode o))
149 (\n -> invalid $ "object size exceeds maximum (total number of properties should be <=" ++ show n ++ "): " ++ show (encode o))
149− *> when' (fromIntegral (HashMap.size o) <) schemaMaxProperties
150+ *> when' (fromIntegral (HashMap.size o) <) minProperties
150 (\n -> invalid $ "object size is too small (total number of properties should be >=" ++ show n ++ "): " ++ show (encode o))
151 (\n -> invalid $ "object size is too small (total number of properties should be >=" ++ show n ++ "): " ++ show (encode o))
151 *> validateRequired
152 *> validateRequired
152 *> validateProps
153 *> validateProps
153 where
154 where
154− validateRequired = traverse_ validateReq (schema ^. schemaRequired)
155+ validateRequired = traverse_ validateReq (schema ^. required)
155 validateReq name = when (not (HashMap.member name o))
156 validateReq name = when (not (HashMap.member name o))
156 (invalid $ "property " ++ show name ++ " is required, but not found in " ++ show (encode o))
157 (invalid $ "property " ++ show name ++ " is required, but not found in " ++ show (encode o))
157
158
158 validateProps = for_ (HashMap.toList o) $ \(k, v) ->
159 validateProps = for_ (HashMap.toList o) $ \(k, v) ->
159− case HashMap.lookup k (schema ^. schemaProperties) of
160+ case HashMap.lookup k (schema ^. properties) of
160− Nothing -> case schema ^. schemaAdditionalProperties of
161+ Nothing -> case schema ^. additionalProperties of
161 Nothing -> valid -- TODO: issue a warning
162 Nothing -> valid -- TODO: issue a warning
162 Just s -> validateWithSchema s v
163 Just s -> validateWithSchema s v
163 Just s -> validateWithSchemaRef s v
164 Just s -> validateWithSchemaRef s v