diff --git a/src/Data/OpenApi/Internal.hs b/src/Data/OpenApi/Internal.hs index 5395ff25..fd43d12d 100644 --- a/src/Data/OpenApi/Internal.hs +++ b/src/Data/OpenApi/Internal.hs @@ -1339,7 +1339,10 @@ instance ToJSON OpenApiItems where , "maxItems" .= (0 :: Int) , "example" .= Array mempty ] - toJSON (OpenApiItemsArray x) = object [ "items" .= x ] + toJSON (OpenApiItemsArray x) = object [ "items" .= + toJSON (swaggerMempty { _schemaOneOf = Just x + }) + ] instance ToJSON Components where toJSON = sopSwaggerGenericToJSON @@ -1476,8 +1479,12 @@ instance FromJSON Header where instance FromJSON OpenApiItems where parseJSON js@(Object obj) | null obj = pure $ OpenApiItemsArray [] -- Nullary schema. - | otherwise = OpenApiItemsObject <$> parseJSON js - parseJSON js@(Array _) = OpenApiItemsArray <$> parseJSON js + | otherwise = do + refSchema <- parseJSON js + case refSchema of + ( Inline Schema { _schemaOneOf = Just schemas }) + -> pure $ OpenApiItemsArray schemas + r -> pure $ OpenApiItemsObject r parseJSON _ = empty instance FromJSON Components where diff --git a/src/Data/OpenApi/Internal/Schema.hs b/src/Data/OpenApi/Internal/Schema.hs index f8649640..2001f1db 100644 --- a/src/Data/OpenApi/Internal/Schema.hs +++ b/src/Data/OpenApi/Internal/Schema.hs @@ -348,14 +348,16 @@ inlineNonRecursiveSchemas defs = inlineSchemasWhen nonRecursive defs -- "Jack", -- 25 -- ], --- "items": [ --- { --- "type": "string" --- }, --- { --- "type": "number" --- } --- ], +-- "items": { +-- "oneOf": [ +-- { +-- "type": "string" +-- }, +-- { +-- "type": "number" +-- } +-- ] +-- }, -- "type": "array" -- } -- @@ -432,35 +434,37 @@ sketchSchema = sketch . toJSON -- 3 -- ] -- ], --- "items": [ --- { --- "enum": [ --- 1 --- ], --- "maximum": 1, --- "minimum": 1, --- "multipleOf": 1, --- "type": "number" --- }, --- { --- "enum": [ --- 2 --- ], --- "maximum": 2, --- "minimum": 2, --- "multipleOf": 2, --- "type": "number" --- }, --- { --- "enum": [ --- 3 --- ], --- "maximum": 3, --- "minimum": 3, --- "multipleOf": 3, --- "type": "number" --- } --- ], +-- "items": { +-- "oneOf": [ +-- { +-- "enum": [ +-- 1 +-- ], +-- "maximum": 1, +-- "minimum": 1, +-- "multipleOf": 1, +-- "type": "number" +-- }, +-- { +-- "enum": [ +-- 2 +-- ], +-- "maximum": 2, +-- "minimum": 2, +-- "multipleOf": 2, +-- "type": "number" +-- }, +-- { +-- "enum": [ +-- 3 +-- ], +-- "maximum": 3, +-- "minimum": 3, +-- "multipleOf": 3, +-- "type": "number" +-- } +-- ] +-- }, -- "maxItems": 3, -- "minItems": 3, -- "type": "array", @@ -475,26 +479,28 @@ sketchSchema = sketch . toJSON -- 25 -- ] -- ], --- "items": [ --- { --- "enum": [ --- "Jack" --- ], --- "maxLength": 4, --- "minLength": 4, --- "pattern": "Jack", --- "type": "string" --- }, --- { --- "enum": [ --- 25 --- ], --- "maximum": 25, --- "minimum": 25, --- "multipleOf": 25, --- "type": "number" --- } --- ], +-- "items": { +-- "oneOf": [ +-- { +-- "enum": [ +-- "Jack" +-- ], +-- "maxLength": 4, +-- "minLength": 4, +-- "pattern": "Jack", +-- "type": "string" +-- }, +-- { +-- "enum": [ +-- 25 +-- ], +-- "maximum": 25, +-- "minimum": 25, +-- "multipleOf": 25, +-- "type": "number" +-- } +-- ] +-- }, -- "maxItems": 2, -- "minItems": 2, -- "type": "array", diff --git a/test/Data/OpenApi/CommonTestTypes.hs b/test/Data/OpenApi/CommonTestTypes.hs index 048f1226..5a3e9cd0 100644 --- a/test/Data/OpenApi/CommonTestTypes.hs +++ b/test/Data/OpenApi/CommonTestTypes.hs @@ -472,11 +472,12 @@ ispairSchemaJSON :: Value ispairSchemaJSON = [aesonQQ| { "type": "array", - "items": - [ + "items": { + "oneOf": [ { "type": "integer" }, { "type": "string" } - ], + ] + }, "minItems": 2, "maxItems": 2 }