mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-24 07:52:14 +03:00
59ffce9ac1
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4855 GitOrigin-RevId: 4cc09d6706e67c69fbbedef72ff816365b9f7b4e
92 lines
2.8 KiB
Haskell
92 lines
2.8 KiB
Haskell
{-# LANGUAGE OverloadedLists #-}
|
|
{-# LANGUAGE QuasiQuotes #-}
|
|
|
|
module Hasura.Backends.DataConnector.API.V0.ConfigSchemaSpec (spec) where
|
|
|
|
import Data.Aeson (toJSON)
|
|
import Data.Aeson.QQ.Simple (aesonQQ)
|
|
import Data.Data (Proxy (..))
|
|
import Data.OpenApi (OpenApiItems (..), OpenApiType (..), Reference (..), Referenced (..), Schema (..), toSchema)
|
|
import Hasura.Backends.DataConnector.API.V0
|
|
import Hasura.Prelude
|
|
import Test.Aeson.Utils (testToFromJSON)
|
|
import Test.Hspec
|
|
|
|
spec :: Spec
|
|
spec = do
|
|
describe "ConfigSchemaResponse" $ do
|
|
let tableNameSchema =
|
|
mempty
|
|
{ _schemaType = Just OpenApiString,
|
|
_schemaNullable = Just False
|
|
}
|
|
tablesSchema =
|
|
mempty
|
|
{ _schemaDescription = Just "List of tables to make available in the schema and for querying",
|
|
_schemaType = Just OpenApiArray,
|
|
_schemaNullable = Just True,
|
|
_schemaItems = Just $ OpenApiItemsObject (Ref $ Reference "TableName")
|
|
}
|
|
_csrConfigSchema =
|
|
mempty
|
|
{ _schemaType = Just OpenApiObject,
|
|
_schemaNullable = Just False,
|
|
_schemaProperties =
|
|
[("tables", Ref $ Reference "Tables")]
|
|
}
|
|
_csrOtherSchemas =
|
|
[ ("Tables", tablesSchema),
|
|
("TableName", tableNameSchema)
|
|
]
|
|
val = ConfigSchemaResponse {..}
|
|
jsonVal =
|
|
[aesonQQ|
|
|
{
|
|
"configSchema": {
|
|
"type": "object",
|
|
"nullable": false,
|
|
"properties": {
|
|
"tables": { "$ref": "#/otherSchemas/Tables" }
|
|
}
|
|
},
|
|
"otherSchemas": {
|
|
"Tables": {
|
|
"description": "List of tables to make available in the schema and for querying",
|
|
"type": "array",
|
|
"items": { "$ref": "#/otherSchemas/TableName" },
|
|
"nullable": true
|
|
},
|
|
"TableName": {
|
|
"nullable": false,
|
|
"type": "string"
|
|
}
|
|
}
|
|
}
|
|
|]
|
|
testToFromJSON val jsonVal
|
|
|
|
it "OpenAPI spec is as expected" $
|
|
toJSON (toSchema (Proxy @ConfigSchemaResponse))
|
|
`shouldBe` [aesonQQ|
|
|
{
|
|
"required": [
|
|
"configSchema",
|
|
"otherSchemas"
|
|
],
|
|
"type": "object",
|
|
"nullable": false,
|
|
"properties": {
|
|
"configSchema": {
|
|
"$ref": "#/components/schemas/OpenApiSchema"
|
|
},
|
|
"otherSchemas": {
|
|
"additionalProperties": {
|
|
"$ref": "#/components/schemas/OpenApiSchema"
|
|
},
|
|
"type": "object",
|
|
"nullable": false
|
|
}
|
|
}
|
|
}
|
|
|]
|