Skip to content

Commit cffc5eb

Browse files
authored
Merge pull request #61 from ysangkok/janus/ghc-9.4
Updated for doctest on GHC 9.4
2 parents 8285df8 + 7d649ee commit cffc5eb

File tree

6 files changed

+25
-9
lines changed

6 files changed

+25
-9
lines changed

openapi3.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ test-suite doctests
148148
hs-source-dirs: test
149149
main-is: doctests.hs
150150
type: exitcode-stdio-1.0
151+
build-depends: base, openapi3
151152

152153
executable example
153154
hs-source-dirs: examples

src/Data/OpenApi.hs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,13 @@ import Data.OpenApi.Internal
137137
-- >>> import Data.Proxy
138138
-- >>> import GHC.Generics
139139
-- >>> import qualified Data.ByteString.Lazy.Char8 as BSL
140+
-- >>> import Data.OpenApi.Internal
141+
-- >>> import Data.OpenApi.Internal.Schema
142+
-- >>> import qualified Data.HashMap.Strict.InsOrd as IOHM
140143
-- >>> import Data.OpenApi.Internal.Utils
144+
-- >>> import Data.OpenApi.Lens
141145
-- >>> :set -XDeriveGeneric
142146
-- >>> :set -XOverloadedStrings
143-
-- >>> :set -XOverloadedLists
144147
-- >>> :set -fno-warn-missing-methods
145148

146149
-- $howto
@@ -211,9 +214,9 @@ import Data.OpenApi.Internal
211214
--
212215
-- >>> :{
213216
-- BSL.putStrLn $ encodePretty $ (mempty :: OpenApi)
214-
-- & components . schemas .~ [ ("User", mempty & type_ ?~ OpenApiString) ]
217+
-- & components . schemas .~ IOHM.fromList [ ("User", mempty & type_ ?~ OpenApiString) ]
215218
-- & paths .~
216-
-- [ ("/user", mempty & get ?~ (mempty
219+
-- IOHM.fromList [ ("/user", mempty & get ?~ (mempty
217220
-- & at 200 ?~ ("OK" & _Inline.content.at "application/json" ?~ (mempty & schema ?~ Ref (Reference "User")))
218221
-- & at 404 ?~ "User info not found")) ]
219222
-- :}

src/Data/OpenApi/Internal/Schema.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ unname (NamedSchema _ schema) = unnamed schema
9393
rename :: Maybe T.Text -> NamedSchema -> NamedSchema
9494
rename name (NamedSchema _ schema) = NamedSchema name schema
9595

96+
-- $setup
97+
-- >>> import Data.Aeson.Types (toJSONKeyText)
98+
-- >>> import qualified Data.ByteString.Lazy.Char8 as BSL
99+
-- >>> import Data.OpenApi.Internal
100+
-- >>> import Data.OpenApi.Internal.Utils (encodePretty)
101+
-- >>> import Data.OpenApi.Lens (name, schema)
102+
96103
-- | Convert a type into @'Schema'@.
97104
--
98105
-- An example type and instance:

src/Data/OpenApi/Internal/Schema/Validation.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ import Data.OpenApi.Internal.Schema
5959
import Data.OpenApi.Internal.Utils
6060
import Data.OpenApi.Lens
6161

62+
-- $setup
63+
-- >>> import Data.OpenApi.Internal.Schema.Validation
64+
6265
-- | Validate @'ToJSON'@ instance matches @'ToSchema'@ for a given value.
6366
-- This can be used with QuickCheck to ensure those instances are coherent:
6467
--

src/Data/OpenApi/Operation.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,13 @@ import qualified Data.HashSet.InsOrd as InsOrdHS
5555
-- >>> import Data.Proxy
5656
-- >>> import Data.Time
5757
-- >>> import qualified Data.ByteString.Lazy.Char8 as BSL
58+
-- >>> import qualified Data.HashMap.Strict.InsOrd as IOHM
5859
-- >>> import Data.OpenApi.Internal.Utils
5960

6061
-- | Prepend path piece to all operations of the spec.
6162
-- Leading and trailing slashes are trimmed/added automatically.
6263
--
63-
-- >>> let api = (mempty :: OpenApi) & paths .~ [("/info", mempty)]
64+
-- >>> let api = (mempty :: OpenApi) & paths .~ IOHM.fromList [("/info", mempty)]
6465
-- >>> BSL.putStrLn $ encodePretty $ prependPath "user/{user_id}" api ^. paths
6566
-- {
6667
-- "/user/{user_id}/info": {}
@@ -83,8 +84,8 @@ allOperations = paths.traverse.template
8384
-- by both path and method.
8485
--
8586
-- >>> let ok = (mempty :: Operation) & at 200 ?~ "OK"
86-
-- >>> let api = (mempty :: OpenApi) & paths .~ [("/user", mempty & get ?~ ok & post ?~ ok)]
87-
-- >>> let sub = (mempty :: OpenApi) & paths .~ [("/user", mempty & get ?~ mempty)]
87+
-- >>> let api = (mempty :: OpenApi) & paths .~ IOHM.fromList [("/user", mempty & get ?~ ok & post ?~ ok)]
88+
-- >>> let sub = (mempty :: OpenApi) & paths .~ IOHM.fromList [("/user", mempty & get ?~ mempty)]
8889
-- >>> BSL.putStrLn $ encodePretty api
8990
-- {
9091
-- "components": {},
@@ -215,7 +216,7 @@ declareResponse cType proxy = do
215216
--
216217
-- Example:
217218
--
218-
-- >>> let api = (mempty :: OpenApi) & paths .~ [("/user", mempty & get ?~ mempty)]
219+
-- >>> let api = (mempty :: OpenApi) & paths .~ IOHM.fromList [("/user", mempty & get ?~ mempty)]
219220
-- >>> let res = declareResponse "application/json" (Proxy :: Proxy Day)
220221
-- >>> BSL.putStrLn $ encodePretty $ api & setResponse 200 res
221222
-- {

src/Data/OpenApi/Optics.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818
-- >>> import Optics.Core
1919
-- >>> :set -XOverloadedLabels
2020
-- >>> import qualified Data.ByteString.Lazy.Char8 as BSL
21+
-- >>> import qualified Data.HashMap.Strict.InsOrd as IOHM
2122
--
2223
-- Example from the "Data.OpenApi" module using @optics@:
2324
--
2425
-- >>> :{
2526
-- BSL.putStrLn $ encodePretty $ (mempty :: OpenApi)
26-
-- & #components % #schemas .~ [ ("User", mempty & #type ?~ OpenApiString) ]
27+
-- & #components % #schemas .~ IOHM.fromList [ ("User", mempty & #type ?~ OpenApiString) ]
2728
-- & #paths .~
28-
-- [ ("/user", mempty & #get ?~ (mempty
29+
-- IOHM.fromList [ ("/user", mempty & #get ?~ (mempty
2930
-- & at 200 ?~ ("OK" & #_Inline % #content % at "application/json" ?~ (mempty & #schema ?~ Ref (Reference "User")))
3031
-- & at 404 ?~ "User info not found")) ]
3132
-- :}

0 commit comments

Comments
 (0)