git.iko.soy/typeable/swagger2
on master help sign in
Update code after a rebase
commitb335a6d18791fd55971f120e0772c9388972ce5f authorNickolay Kudasov <nickolay.kudasov@gmail.com> dateFri 11 Dec 2015, 00:16 (11 years ago) parent340f666
1 file changed+7−6
src/Data/Swagger/Schema/Validation.hs+7−6
src/Data/Swagger/Schema/Validation.hs+7−6
@@ -95,6 +95,7 @@ validateWithSchema schema value
9595 (SwaggerString, String s) -> validateString s
9696 (SwaggerArray, Array xs) -> validateArray xs
9797 (SwaggerObject, Object o) -> validateObject o
98+ (t, _) -> invalid $ "expected JSON value of type " ++ show t ++ ": " ++ show (encode value)
9899
99100 validateInteger n
100101 = when (not (isInteger n)) (invalid $ "not an integer: " ++ show n)
@@ -141,23 +142,23 @@ validateWithSchema schema value
141142 where
142143 allUnique = Vector.length xs == HashSet.size (HashSet.fromList (Vector.toList xs))
143144
144− validateObject o = case schema ^. schemaDiscriminator of
145+ validateObject o = case schema ^. discriminator of
145146 Just name -> validateWithSchemaRef (Ref (Reference name)) value
146147 Nothing ->
147− when' (fromIntegral (HashMap.size o) >) schemaMaxProperties
148+ when' (fromIntegral (HashMap.size o) >) maxProperties
148149 (\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
150151 (\n -> invalid $ "object size is too small (total number of properties should be >=" ++ show n ++ "): " ++ show (encode o))
151152 *> validateRequired
152153 *> validateProps
153154 where
154− validateRequired = traverse_ validateReq (schema ^. schemaRequired)
155+ validateRequired = traverse_ validateReq (schema ^. required)
155156 validateReq name = when (not (HashMap.member name o))
156157 (invalid $ "property " ++ show name ++ " is required, but not found in " ++ show (encode o))
157158
158159 validateProps = for_ (HashMap.toList o) $ \(k, v) ->
159− case HashMap.lookup k (schema ^. schemaProperties) of
160− Nothing -> case schema ^. schemaAdditionalProperties of
160+ case HashMap.lookup k (schema ^. properties) of
161+ Nothing -> case schema ^. additionalProperties of
161162 Nothing -> valid -- TODO: issue a warning
162163 Just s -> validateWithSchema s v
163164 Just s -> validateWithSchemaRef s v