2022-06-27 19:32:25 +03:00
|
|
|
-- | This module exports an OpenAPI specification for the GraphQL Engine
|
|
|
|
-- metadata API.
|
|
|
|
--
|
|
|
|
-- The OpenAPI specification for metadata is experimental and incomplete. Please
|
|
|
|
-- do not incorporate it into essential workflows at this time.
|
|
|
|
module Hasura.Server.MetadataOpenAPI (metadataOpenAPI) where
|
|
|
|
|
2022-09-12 23:29:51 +03:00
|
|
|
import Autodocodec.OpenAPI (declareNamedSchemaViaCodec)
|
2022-06-27 19:32:25 +03:00
|
|
|
import Data.HashMap.Strict.InsOrd qualified as HM
|
2022-09-12 23:29:51 +03:00
|
|
|
import Data.OpenApi (Components (..), NamedSchema (..), OpenApi (..))
|
|
|
|
import Data.OpenApi.Declare (MonadDeclare (declare), runDeclare)
|
2022-06-27 19:32:25 +03:00
|
|
|
import Data.Proxy (Proxy (..))
|
|
|
|
import Hasura.Metadata.DTO.Metadata (MetadataDTO)
|
|
|
|
import Hasura.Prelude
|
|
|
|
|
|
|
|
-- | An OpenApi document includes \"schemas\" that describe the data that may be
|
|
|
|
-- produced or consumed by an API. It can also include \"paths\" which describe
|
|
|
|
-- REST endpoints, and the document can include other API metadata. This example
|
|
|
|
-- only includes schemas.
|
|
|
|
--
|
|
|
|
-- The OpenAPI specification for metadata is experimental and incomplete. Please
|
|
|
|
-- do not incorporate it into essential workflows at this time.
|
|
|
|
metadataOpenAPI :: OpenApi
|
|
|
|
metadataOpenAPI =
|
2022-09-12 23:29:51 +03:00
|
|
|
mempty {_openApiComponents = mempty {_componentsSchemas = definitions}}
|
2022-06-27 19:32:25 +03:00
|
|
|
where
|
2022-09-12 23:29:51 +03:00
|
|
|
definitions = fst $
|
|
|
|
flip runDeclare mempty $ do
|
|
|
|
NamedSchema mName codecSchema <- declareNamedSchemaViaCodec (Proxy @MetadataDTO)
|
|
|
|
declare $ HM.fromList [(fromMaybe "MetadataDTO" mName, codecSchema)]
|
|
|
|
pure codecSchema
|