-
Notifications
You must be signed in to change notification settings - Fork 332
WPB-6012 create new API version v6 #3815
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
battermann
merged 6 commits into
develop
from
WPB-6012-backend-create-new-api-version-v-6-once-v-5-is-stable
Jan 18, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6d4013d
wip
battermann fc0cebb
Pregenerate swagger-v5.json
718f8d2
change api version in integration tests
battermann a523bb4
changelog
battermann 257cf4e
fix integration test
battermann 9dba9d8
moved swagger tests
battermann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Create new API version V6 and finalize V5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| module Test.Swagger where | ||
|
|
||
| import qualified API.Brig as BrigP | ||
| import qualified Data.Set as Set | ||
| import Data.String.Conversions | ||
| import GHC.Stack | ||
| import Testlib.Assertions | ||
| import Testlib.Prelude | ||
|
|
||
| existingVersions :: Set Int | ||
| existingVersions = Set.fromList [0, 1, 2, 3, 4, 5, 6] | ||
|
|
||
| internalApis :: Set String | ||
| internalApis = Set.fromList ["brig", "cannon", "cargohold", "cannon", "spar"] | ||
|
|
||
| -- | See https://docs.wire.com/understand/api-client-perspective/swagger.html | ||
| testSwagger :: HasCallStack => App () | ||
| testSwagger = do | ||
| bindResponse BrigP.getApiVersions $ \resp -> do | ||
| resp.status `shouldMatchInt` 200 | ||
| actualVersions :: Set Int <- do | ||
| sup <- resp.json %. "supported" & asSetOf asIntegral | ||
| dev <- resp.json %. "development" & asSetOf asIntegral | ||
| pure $ sup <> dev | ||
| assertBool ("unexpected actually existing versions: " <> show actualVersions) $ | ||
| -- make sure nobody has added a new version without adding it to `existingVersions`. | ||
| -- make sure nobody has added a new version without adding it to `existingVersions`. | ||
| -- ("subset" because blocked versions like v3 are not actually existing, but still | ||
| -- ("subset" because blocked versions like v3 are not actually existing, but still | ||
| -- documented.) | ||
| -- documented.) | ||
|
|
||
| -- make sure nobody has added a new version without adding it to `existingVersions`. | ||
| -- ("subset" because blocked versions like v3 are not actually existing, but still | ||
| -- documented.) | ||
| actualVersions `Set.isSubsetOf` existingVersions | ||
|
|
||
| bindResponse BrigP.getSwaggerPublicTOC $ \resp -> do | ||
| resp.status `shouldMatchInt` 200 | ||
| cs resp.body `shouldContainString` "<html>" | ||
|
|
||
| forM_ existingVersions $ \v -> do | ||
| bindResponse (BrigP.getSwaggerPublicAllUI v) $ \resp -> do | ||
| resp.status `shouldMatchInt` 200 | ||
| cs resp.body `shouldContainString` "<!DOCTYPE html>" | ||
| bindResponse (BrigP.getSwaggerPublicAllJson v) $ \resp -> do | ||
| resp.status `shouldMatchInt` 200 | ||
| void resp.json | ||
|
|
||
| -- ! | ||
| -- FUTUREWORK: Implement BrigP.getSwaggerInternalTOC (including the end-point); make sure | ||
| -- newly added internal APIs make this test fail if not added to `internalApis`. | ||
|
|
||
| forM_ internalApis $ \api -> do | ||
| bindResponse (BrigP.getSwaggerInternalUI api) $ \resp -> do | ||
| resp.status `shouldMatchInt` 200 | ||
| cs resp.body `shouldContainString` "<!DOCTYPE html>" | ||
| bindResponse (BrigP.getSwaggerInternalJson api) $ \resp -> do | ||
| resp.status `shouldMatchInt` 200 | ||
| void resp.json | ||
|
|
||
| testSwaggerInternalVersionedNotFound :: HasCallStack => App () | ||
| testSwaggerInternalVersionedNotFound = do | ||
| forM_ internalApis $ \api -> do | ||
| bindResponse (getSwaggerInternalUI api) $ \resp -> do | ||
| resp.status `shouldMatchInt` 404 | ||
| where | ||
| getSwaggerInternalUI :: String -> App Response | ||
| getSwaggerInternalUI srv = | ||
| rawBaseRequest OwnDomain Brig (ExplicitVersion 2) (joinHttpPath ["api-internal", "swagger-ui", srv]) | ||
| >>= submit "GET" | ||
|
|
||
| testSwaggerToc :: HasCallStack => App () | ||
| testSwaggerToc = do | ||
| forM_ ["/api/swagger-ui", "/api/swagger-ui/index.html", "/api/swagger.json"] $ \path -> | ||
| bindResponse (get path) $ \resp -> do | ||
| resp.status `shouldMatchInt` 200 | ||
| let body = cs @_ @String resp.body | ||
| body `shouldMatch` html | ||
| forM_ existingVersions $ \v -> | ||
| body `shouldContainString` ("v" <> show v) | ||
| where | ||
| get :: String -> App Response | ||
| get path = rawBaseRequest OwnDomain Brig Unversioned path >>= submit "GET" | ||
|
|
||
| html :: String | ||
| html = "<html><head></head><body><h2>please pick an api version</h2><a href=\"/v0/api/swagger-ui/\">/v0/api/swagger-ui/</a><br><a href=\"/v1/api/swagger-ui/\">/v1/api/swagger-ui/</a><br><a href=\"/v2/api/swagger-ui/\">/v2/api/swagger-ui/</a><br><a href=\"/v3/api/swagger-ui/\">/v3/api/swagger-ui/</a><br><a href=\"/v4/api/swagger-ui/\">/v4/api/swagger-ui/</a><br><a href=\"/v5/api/swagger-ui/\">/v5/api/swagger-ui/</a><br><a href=\"/v6/api/swagger-ui/\">/v6/api/swagger-ui/</a><br></body>" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A good catch! How did you find it? By running tests or by some other means? Let's add this to the version bump checklist!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked at the previous PR for finalizing V4.