<commit_before>{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE UndecidableInstances #-}
module SwaggerSpec where

import           Universum

import qualified Prelude

import qualified Cardano.Wallet.API.V1 as V1
import           Cardano.Wallet.API.V1.Swagger ()
import           Cardano.Wallet.Orphans.Aeson ()
import           Cardano.Wallet.Orphans.Arbitrary ()
import           Data.String.Conv
import           Data.Swagger
import           Pos.Wallet.Aeson.ClientTypes ()
import           Servant.API.ContentTypes
import           Servant.Swagger.Test
import           Test.Hspec
import           Test.Hspec.QuickCheck
import           Test.QuickCheck.Instances ()


-- Syntethic instances and orphans to be able to use `validateEveryToJSON`.
-- In the future, hopefully, we will never need these.

instance {-# OVERLAPPABLE #-} Buildable a => Prelude.Show a where
    show = toS . pretty

instance ToSchema NoContent where
    declareNamedSchema _ = pure (NamedSchema Nothing mempty)

spec :: Spec
spec = modifyMaxSuccess (const 10) $
    describe "Swagger Integration" $ do
        xdescribe "(V1) ToJSON matches ToSchema" $ validateEveryToJSON (Proxy @ V1.API)
<commit_msg>[CSL-2339] Vendor but use ValidJSON type<commit_after>{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE UndecidableInstances #-}
module SwaggerSpec where

import           Universum

import qualified Prelude

import           Data.String.Conv
import           Data.Swagger
import           Pos.Wallet.Aeson.ClientTypes ()
import           Servant.API.ContentTypes
import           Servant.Swagger.Test ()
import           Test.Hspec
import           Test.Hspec.QuickCheck
import           Test.QuickCheck.Instances ()

import           Cardano.Wallet.API.Response (ValidJSON)
import qualified Cardano.Wallet.API.V1 as V1
import           Cardano.Wallet.API.V1.Swagger ()
import           Cardano.Wallet.Orphans.Aeson ()
import           Cardano.Wallet.Orphans.Arbitrary ()

-- for vendored code
import           Data.Aeson (ToJSON)
import           Servant.Swagger.Internal.Test (props)
import           Servant.Swagger.Internal.TypeLevel (BodyTypes, Every, TMap)
import           Test.QuickCheck (Arbitrary)

-- Syntethic instances and orphans to be able to use `validateEveryToJSON`.
-- In the future, hopefully, we will never need these.

instance {-# OVERLAPPABLE #-} Buildable a => Prelude.Show a where
    show = toS . pretty

instance ToSchema NoContent where
    declareNamedSchema _ = pure (NamedSchema Nothing mempty)

spec :: Spec
spec = modifyMaxSuccess (const 10) $
    describe "Swagger Integration" $ do
        describe "(V1) ToJSON matches ToSchema" $
            validateEveryToJSON' (Proxy @ V1.API)

-- vendored
validateEveryToJSON'
    :: forall proxy api
    . TMap (Every [Typeable, Show, Arbitrary, ToJSON, ToSchema]) (BodyTypes ValidJSON api)
    => proxy api   -- ^ Servant API.
    -> Spec
validateEveryToJSON' _ = props
  (Proxy :: Proxy [ToJSON, ToSchema])
  (null . validateToJSON)
  (Proxy :: Proxy (BodyTypes ValidJSON api))


{'fraction_non_alphanumeric': 0.08837056504599211, 'fraction_numerical': 0.005913272010512484, 'mean_word_length': 2.759259259259259, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1339548', 'n_tokens_mistral': 922, 'n_tokens_neox': 908, 'n_words': 250}