Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/4-docs/unblock-swagger
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow swagger on disabled versions.
11 changes: 9 additions & 2 deletions libs/wire-api/src/Wire/API/Routes/Version/Wai.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ import Wire.API.Routes.Version
-- | Strip off version prefix. Return 404 if the version is not supported.
versionMiddleware :: Set Version -> Middleware
versionMiddleware disabledAPIVersions app req k = case parseVersion (removeVersionHeader req) of
Right (req', v) ->
if v `elem` disabledAPIVersions
Right (req', v) -> do
if v `elem` disabledAPIVersions && requestIsDisableable req'
then err (toUrlPiece v)
else app (addVersionHeader v req') k
Left (BadVersion v) -> err v
Expand All @@ -61,6 +61,13 @@ parseVersion req = do
looksLikeVersion :: Text -> Bool
looksLikeVersion version = case T.splitAt 1 version of (h, t) -> h == "v" && T.all isDigit t

-- | swagger-delivering end-points are not disableable: they should work for all versions.
requestIsDisableable :: Request -> Bool
requestIsDisableable (pathInfo -> path) = case path of
["api", "swagger-ui"] -> False

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It think api-internal is missing. See e.g. https://staging-nginz-https.zinfra.io/api-internal/swagger-ui/brig

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Err nevermind, internal apis are not versioned :)

["api", "swagger.json"] -> False
_ -> True

removeVersionHeader :: Request -> Request
removeVersionHeader req =
req
Expand Down