Skip to content

Commit

Permalink
Merge pull request #49 from stevladimir/fix-allof-oneof
Browse files Browse the repository at this point in the history
Don't add 'object' type when generating sum schema with allOf/oneOf
  • Loading branch information
maksbotan authored Nov 21, 2022
2 parents ac7058e + 2413197 commit acc5ea7
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 22 deletions.
1 change: 0 additions & 1 deletion openapi3.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ library
, http-media >=0.8.0.0 && <0.9
, insert-ordered-containers >=0.2.3 && <0.3
, lens >=4.16.1 && <5.3
, network >=2.6.3.5 && <3.2
, optics-core >=0.2 && <0.5
, optics-th >=0.2 && <0.5
, scientific >=0.3.6.2 && <0.4
Expand Down
3 changes: 1 addition & 2 deletions src/Data/OpenApi.hs
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,7 @@ import Data.OpenApi.Internal
-- ],
-- "type": "object"
-- }
-- ],
-- "type": "object"
-- ]
-- }

-- $manipulation
Expand Down
1 change: 0 additions & 1 deletion src/Data/OpenApi/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import Data.Text.Encoding (encodeUtf8)
import GHC.Generics (Generic)
import Network.HTTP.Media (MediaType, mainType, parameters, parseAccept, subType, (//),
(/:))
import Network.Socket (HostName, PortNumber)
import Text.Read (readMaybe)

import Data.HashMap.Strict.InsOrd (InsOrdHashMap)
Expand Down
2 changes: 0 additions & 2 deletions src/Data/OpenApi/Internal/Schema.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,6 @@ gdeclareNamedSumSchema opts proxy _
| otherwise = do
(schemas, _) <- runWriterT declareSumSchema
return $ unnamed $ mempty
& type_ ?~ OpenApiObject
& oneOf ?~ (snd <$> schemas)
where
declareSumSchema = gsumToSchema opts proxy
Expand Down Expand Up @@ -1079,7 +1078,6 @@ gsumConToSchemaWith ref opts _ = (tag, schema)

-- In the remaining cases we combine "tag" object and "contents" object using allOf.
_ -> Inline $ mempty
& type_ ?~ OpenApiObject
& allOf ?~ [Inline $ mempty
& type_ ?~ OpenApiObject
& required .~ (T.pack tagField : if isRecord then [] else [T.pack contentsField])
Expand Down
21 changes: 7 additions & 14 deletions test/Data/OpenApi/CommonTestTypes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,7 @@ characterSchemaJSON = [aesonQQ|
}
}
}
],
"type": "object"
]
}

|]
Expand Down Expand Up @@ -398,8 +397,7 @@ characterInlinedSchemaJSON = [aesonQQ|
}
}
}
],
"type": "object"
]
}
|]

Expand Down Expand Up @@ -455,8 +453,7 @@ characterInlinedPlayerSchemaJSON = [aesonQQ|
}
}
}
],
"type": "object"
]
}
|]

Expand Down Expand Up @@ -705,8 +702,7 @@ lightSchemaJSON = [aesonQQ|
}
}
}
],
"type": "object"
]
}
|]

Expand Down Expand Up @@ -789,8 +785,7 @@ lightInlinedSchemaJSON = [aesonQQ|
}
}
}
],
"type": "object"
]
}
|]

Expand Down Expand Up @@ -929,8 +924,7 @@ predicateSchemaDeclareJSON = [aesonQQ|
"required": ["tag", "contents"],
"type": "object"
}
],
"type": "object"
]
},
"Noun": {
"properties": {
Expand Down Expand Up @@ -969,8 +963,7 @@ predicateSchemaDeclareJSON = [aesonQQ|
"required": ["tag", "contents"],
"type": "object"
}
],
"type": "object"
]
},
"Omitted": {
"properties": {
Expand Down
2 changes: 0 additions & 2 deletions test/Data/OpenApiSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,6 @@ petstoreExampleJSON = [aesonQQ|

compositionSchemaExample :: Schema
compositionSchemaExample = mempty
& type_ ?~ OpenApiObject
& Data.OpenApi.allOf ?~ [
Ref (Reference "Other")
, Inline (mempty
Expand All @@ -991,7 +990,6 @@ compositionSchemaExample = mempty
compositionSchemaExampleJSON :: Value
compositionSchemaExampleJSON = [aesonQQ|
{
"type": "object",
"allOf": [
{
"$ref": "#/components/schemas/Other"
Expand Down

0 comments on commit acc5ea7

Please sign in to comment.