Skip to content
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

ReDoc uses unmodifiable spec path #226

Closed
andrewpmartinez opened this issue Nov 11, 2021 · 2 comments · Fixed by #278
Closed

ReDoc uses unmodifiable spec path #226

andrewpmartinez opened this issue Nov 11, 2021 · 2 comments · Fixed by #278

Comments

@andrewpmartinez
Copy link

andrewpmartinez commented Nov 11, 2021

It appears that when ReDoc is used, the OpenAPI 2.0/Swagger spec is defaulted to "/swagger.json" and ignores basePath while also providing no way to directly or indirectly set .SpecURL in the Redoc template.

In my situation, I'm hosting multiple separate APIs from the same listener. I can load Redoc from myhost/api-type/api-sub-type/version/docs but the rendered template always points to myhost/swagger.json.

I could not find a way to provide an override, alter the value directly, or make the basePath from my OpenApi 2.0 spec be referenced in any way.

Changes to runtime appear to be:

  • alter RedocOpts field SpecURL to be a relative path: "./swagger.json" or "swagger.json" instead of "/swagger.json"
  • alter RedocOpts field SpecURL to take BasePath into account
  • provide a way to override/set the SpecURL externally from Context

If there is a different way to handle this or I am missing something please let me know!

@andrewpmartinez
Copy link
Author

This still seems to be an issue.

@fredbi
Copy link
Member

fredbi commented Dec 10, 2023

Studying this issue report, I gather that:

  1. When used independenctly, the Redoc middleware is configurable as far as SpecURL is concerned.
    • BasePath and Path tell this middleware how to serve the UI asset, SpecURL tells where to find the spec document
    • SpecURL, BasePath and Path are unrelated parameters
  2. When used independently, the Spec middleware is configurable as far as the path is concerned.
    • the document name "swagger.json" is hard-coded
  3. When using the fully assembled API middleware stack exposed by Context, the spec document is served at "/swagger.json", the UI (redoc) is served at "{API base path}/docs". These are not currently configurable.

fredbi added a commit to fredbi/runtime that referenced this issue Dec 11, 2023
- refactored UI middleware
  * factorized chore middleware to remove duplicated code
  * factorized UI middleware options: to avoid breaking changes in the
    options types, there is a decode/encode to a common structure
  * added more options:
    * allows to fully customize the UI template
  * added more unit tests

- Spec middleware: added support for optional SpecOption argument
  * allows to serve the spec from a custom path / document name

- serving with or without trailing "/" (cf. issue go-openapi#238)
  * replaced path.Join() by path.Clean(), which is the intended behavior
    (i.e. serve the path, irrespective of the presence of a trailing
    slash)
  * generalized this behavior to all UI and Spec middleware, not just
    swaggerUI

- API Context:
  * exposed middleware to serve RapiDoc UI
  * allowed new UIOption (...UIOption) to the APIHandler, etc middleware
  * coordinated UI / Spec middleware to be consistent when non-default
    path/document URL is served

* fixes go-openapi#192
* fixes go-openapi#226

Signed-off-by: Frederic BIDON <[email protected]>
fredbi added a commit to fredbi/runtime that referenced this issue Dec 11, 2023
- refactored UI middleware
  * factorized chore middleware to remove duplicated code
  * factorized UI middleware options: to avoid breaking changes in the
    options types, there is a decode/encode to a common structure
  * added more options:
    * allows to fully customize the UI template
  * added more unit tests

- Spec middleware: added support for optional SpecOption argument
  * allows to serve the spec from a custom path / document name

- serving with or without trailing "/" (cf. issue go-openapi#238)
  * replaced path.Join() by path.Clean(), which is the intended behavior
    (i.e. serve the path, irrespective of the presence of a trailing
    slash)
  * generalized this behavior to all UI and Spec middleware, not just
    swaggerUI

- API Context:
  * exposed middleware to serve RapiDoc UI
  * allowed new UIOption (...UIOption) to the APIHandler, etc middleware
  * coordinated UI / Spec middleware to be consistent when non-default
    path/document URL is served

* fixes go-openapi#192
* fixes go-openapi#226

Signed-off-by: Frederic BIDON <[email protected]>
fredbi added a commit that referenced this issue Dec 12, 2023
- refactored UI middleware
  * factorized chore middleware to remove duplicated code
  * factorized UI middleware options: to avoid breaking changes in the
    options types, there is a decode/encode to a common structure
  * added more options:
    * allows to fully customize the UI template
  * added more unit tests

- Spec middleware: added support for optional SpecOption argument
  * allows to serve the spec from a custom path / document name

- serving with or without trailing "/" (cf. issue #238)
  * replaced path.Join() by path.Clean(), which is the intended behavior
    (i.e. serve the path, irrespective of the presence of a trailing
    slash)
  * generalized this behavior to all UI and Spec middleware, not just
    swaggerUI

- API Context:
  * exposed middleware to serve RapiDoc UI
  * allowed new UIOption (...UIOption) to the APIHandler, etc middleware
  * coordinated UI / Spec middleware to be consistent when non-default
    path/document URL is served

* fixes #192
* fixes #226

Signed-off-by: Frederic BIDON <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants