Skip to content

Commit

Permalink
Allow swagger on disabled versions. (#3196)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisx authored Mar 29, 2023
1 parent d3f488f commit b6d2ad8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
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
["api", "swagger.json"] -> False
_ -> True

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

0 comments on commit b6d2ad8

Please sign in to comment.