Skip to content

Commit 2e3a6ec

Browse files
lepsaelland
andauthored
WPB-4240: Migrate from swagger2 to openapi3 (#3570)
--------- Co-authored-by: Igor Ranieri Elland <[email protected]> Co-authored-by: Igor Ranieri <[email protected]>
1 parent 85cb5a9 commit 2e3a6ec

File tree

191 files changed

+890
-579
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

191 files changed

+890
-579
lines changed

changelog.d/4-docs/WPB-4240

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Updating the route documentation from Swagger 2 to OpenAPI 3.

changelog.d/5-internal/WPB-4240

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Updating the route documentation library from swagger2 to openapi3.
2+
3+
This also introduced a breaking change in how we track what federation calls each route makes.
4+
The openapi3 library doesn't support extension fields, and as such tags are being used instead in a similar way.

libs/brig-types/brig-types.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ test-suite brig-types-tests
156156
, brig-types
157157
, bytestring-conversion >=0.3.1
158158
, imports
159+
, openapi3
159160
, QuickCheck >=2.9
160-
, swagger2 >=2.5
161161
, tasty
162162
, tasty-hunit
163163
, tasty-quickcheck

libs/brig-types/default.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
, gitignoreSource
1414
, imports
1515
, lib
16+
, openapi3
1617
, QuickCheck
17-
, swagger2
1818
, tasty
1919
, tasty-hunit
2020
, tasty-quickcheck
@@ -47,8 +47,8 @@ mkDerivation {
4747
base
4848
bytestring-conversion
4949
imports
50+
openapi3
5051
QuickCheck
51-
swagger2
5252
tasty
5353
tasty-hunit
5454
tasty-quickcheck

libs/brig-types/test/unit/Test/Brig/Roundtrip.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module Test.Brig.Roundtrip where
2020
import Data.Aeson (FromJSON, ToJSON, parseJSON, toJSON)
2121
import Data.Aeson.Types (parseEither)
2222
import Data.ByteString.Conversion
23-
import Data.Swagger (ToSchema, validatePrettyToJSON)
23+
import Data.OpenApi (ToSchema, validatePrettyToJSON)
2424
import Imports
2525
import Test.Tasty (TestTree)
2626
import Test.Tasty.QuickCheck (Arbitrary, counterexample, testProperty, (.&&.), (===))
@@ -40,7 +40,7 @@ testRoundTrip = testProperty msg trip
4040

4141
testRoundTripWithSwagger ::
4242
forall a.
43-
(Arbitrary a, Typeable a, ToJSON a, FromJSON a, ToSchema a, Eq a, Show a) =>
43+
(Arbitrary a, ToJSON a, FromJSON a, ToSchema a, Eq a, Show a) =>
4444
TestTree
4545
testRoundTripWithSwagger = testProperty msg (trip .&&. scm)
4646
where

libs/deriving-swagger2/default.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
, gitignoreSource
99
, imports
1010
, lib
11-
, swagger2
11+
, openapi3
1212
}:
1313
mkDerivation {
1414
pname = "deriving-swagger2";
1515
version = "0.1.0";
1616
src = gitignoreSource ./.;
17-
libraryHaskellDepends = [ base extra imports swagger2 ];
17+
libraryHaskellDepends = [ base extra imports openapi3 ];
1818
license = lib.licenses.agpl3Only;
1919
}

libs/deriving-swagger2/deriving-swagger2.cabal

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ library
6262
-Wredundant-constraints -Wunused-packages
6363

6464
build-depends:
65-
base >=4 && <5
65+
base >=4 && <5
6666
, extra
6767
, imports
68-
, swagger2 >=0.6
68+
, openapi3
6969

7070
default-language: GHC2021

libs/deriving-swagger2/src/Deriving/Swagger.hs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{-# LANGUAGE RankNTypes #-}
2+
13
-- This file is part of the Wire Server implementation.
24
--
35
-- Copyright (C) 2022 Wire Swiss GmbH <[email protected]>
@@ -22,10 +24,10 @@ module Deriving.Swagger where
2224
import Data.Char qualified as Char
2325
import Data.Kind (Constraint)
2426
import Data.List.Extra (stripSuffix)
27+
import Data.OpenApi.Internal.Schema (GToSchema)
28+
import Data.OpenApi.Internal.TypeShape
29+
import Data.OpenApi.Schema
2530
import Data.Proxy (Proxy (..))
26-
import Data.Swagger (SchemaOptions, ToSchema (..), constructorTagModifier, defaultSchemaOptions, fieldLabelModifier, genericDeclareNamedSchema)
27-
import Data.Swagger.Internal.Schema (GToSchema)
28-
import Data.Swagger.Internal.TypeShape (TypeHasSimpleShape)
2931
import GHC.Generics (Generic (Rep))
3032
import GHC.TypeLits (ErrorMessage (Text), KnownSymbol, Symbol, TypeError, symbolVal)
3133
import Imports
@@ -81,6 +83,7 @@ import Imports
8183
-- | A newtype wrapper which gives ToSchema instances with modified options.
8284
-- 't' has to have an instance of the 'SwaggerOptions' class.
8385
newtype CustomSwagger t a = CustomSwagger {unCustomSwagger :: a}
86+
deriving (Generic, Typeable)
8487

8588
class SwaggerOptions xs where
8689
swaggerOptions :: SchemaOptions
@@ -94,14 +97,7 @@ instance (StringModifier f, SwaggerOptions xs) => SwaggerOptions (FieldLabelModi
9497
instance (StringModifier f, SwaggerOptions xs) => SwaggerOptions (ConstructorTagModifier f ': xs) where
9598
swaggerOptions = (swaggerOptions @xs) {constructorTagModifier = getStringModifier @f}
9699

97-
instance
98-
( SwaggerOptions t,
99-
Generic a,
100-
GToSchema (Rep a),
101-
TypeHasSimpleShape a "genericDeclareNamedSchemaUnrestricted"
102-
) =>
103-
ToSchema (CustomSwagger t a)
104-
where
100+
instance (SwaggerOptions t, Generic a, Typeable a, GToSchema (Rep a), Typeable (CustomSwagger t a), TypeHasSimpleShape a "genericDeclareNamedSchemaUnrestricted") => ToSchema (CustomSwagger t a) where
105101
declareNamedSchema _ = genericDeclareNamedSchema (swaggerOptions @t) (Proxy @a)
106102

107103
-- ** Specify __what__ to modify

libs/extended/default.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
, servant
2828
, servant-client
2929
, servant-client-core
30+
, servant-openapi3
3031
, servant-server
31-
, servant-swagger
3232
, temporary
3333
, text
3434
, tinylog
@@ -60,8 +60,8 @@ mkDerivation {
6060
servant
6161
servant-client
6262
servant-client-core
63+
servant-openapi3
6364
servant-server
64-
servant-swagger
6565
text
6666
tinylog
6767
unliftio

libs/extended/extended.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ library
9898
, servant
9999
, servant-client
100100
, servant-client-core
101+
, servant-openapi3
101102
, servant-server
102-
, servant-swagger
103103
, text
104104
, tinylog
105105
, unliftio

0 commit comments

Comments
 (0)