Skip to content

Allow swagger-servant-ui with redoc to be nested in an API #53

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
merged 1 commit into from
Oct 16, 2018
Merged

Allow swagger-servant-ui with redoc to be nested in an API #53

merged 1 commit into from
Oct 16, 2018

Conversation

KtorZ
Copy link
Contributor

@KtorZ KtorZ commented Aug 9, 2018

In the current state, if we were to declare a servant-swagger-ui server behind some path, for instance:

type API =
    "docs" :> ServantSwaggerUI "swagger-ui" "swagger.json"

One would correctly have access to the template in <host>/docs/swagger.ui but the template would refer to a swagger.json at /swagger.json whereas it is hosted under /docs/swagger.json. To cope with this, we can use relative paths in the template, making sure that the current url is always ending with a slash.
Note also that without a trailing slash, it will fail at loading assets like the initial redoc.min.hs bundle, so it is rather important to enforce strict URL-routing here.

In the current state, if we were to declare a servant-swagger-ui server behind some path, for instance:

    type API =
        "docs" :> ServantSwaggerUI "swagger-ui" "swagger.json"

One would correctly have access to the template in `<host>/docs/swagger.ui`
but the template would refer to a swagger.json at `/swagger.json`
whereas it is hosted under `/docs/swagger.json`. To cope with this, we
can use relative paths in the template, making sure that the current url
is always ending with a slash.
@phadej
Copy link
Contributor

phadej commented Aug 9, 2018

This isn't a problem with vanilla servant-swagger-ui ?

@KtorZ
Copy link
Contributor Author

KtorZ commented Aug 9, 2018

I am not sure but could be. It depends on how the assets are referenced in the template I suppose. Haven't verified for the jensoleg package either.

KtorZ added a commit to input-output-hk/cardano-sl that referenced this pull request Aug 14, 2018
There's actually a bug in the current template which serves the swagger specs on an absolute url
, completely ignoring any sub-path in the URL. A PR has been submitted to the upstream library
(servant-swagger-ui-redoc) haskell-servant/servant-swagger-ui#53 but until
it gets accepted, we need a way to serve our documentation
@KtorZ
Copy link
Contributor Author

KtorZ commented Sep 27, 2018

Apologies for the delay!
No, this is not an issue with vanilla servant-swagger-ui because the template uses a similar trick:

https://github.com/haskell-servant/servant-swagger-ui/blob/master/servant-swagger-ui/index.html.tmpl#L12-L21

@phadej phadej merged commit b245b4c into haskell-servant:master Oct 16, 2018
@KtorZ KtorZ deleted the fix/redoc-template-nested-paths branch October 16, 2018 12:44
KtorZ added a commit to input-output-hk/cardano-sl that referenced this pull request Nov 9, 2018
There's actually a bug in the current template which serves the swagger specs on an absolute url
, completely ignoring any sub-path in the URL. A PR has been submitted to the upstream library
(servant-swagger-ui-redoc) haskell-servant/servant-swagger-ui#53 but until
it gets accepted, we need a way to serve our documentation
KtorZ added a commit to input-output-hk/cardano-wallet-legacy that referenced this pull request Nov 9, 2018
There's actually a bug in the current template which serves the swagger specs on an absolute url
, completely ignoring any sub-path in the URL. A PR has been submitted to the upstream library
(servant-swagger-ui-redoc) haskell-servant/servant-swagger-ui#53 but until
it gets accepted, we need a way to serve our documentation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants