Skip to content

[OpenAPI] Avoid caching request-specific spec URLs in HTML docs#354

Open
RedZapdos123 wants to merge 1 commit into
rage-rb:mainfrom
RedZapdos123:fix-openapi-html-cache-353
Open

[OpenAPI] Avoid caching request-specific spec URLs in HTML docs#354
RedZapdos123 wants to merge 1 commit into
rage-rb:mainfrom
RedZapdos123:fix-openapi-html-cache-353

Conversation

@RedZapdos123

@RedZapdos123 RedZapdos123 commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Description:

Issue #353 reported that the cached OpenAPI HTML page embeds a request-specific spec URL from the first request.

This PR makes the cached HTML page request-independent by deriving the JSON spec URL from window.location.pathname in the browser instead of rendering rack.url_scheme, HTTP_HOST, and SCRIPT_NAME into the cached page.

It also adds a regression spec that covers repeated HTML requests with different hosts and mount paths, and adds a changelog entry for the fix.

Before fix:

  • first request under /docs-a: http://first.test:3000/docs-a/json
  • second request under /docs-b: http://first.test:3000/docs-a/json
  • result: cached HTML reused the first request's spec URL.

After fix:

  • cached HTML no longer embeds request host or mount path.
  • Swagger UI resolves the JSON spec URL from the current window.location.pathname.
  • the cached page works correctly across repeated requests with different hosts and mount paths.
image

Closes #353.

Checklist:

  • I have run focused tests using bundle exec rspec spec/openapi/openapi_spec.rb.
  • I have run broader OpenAPI tests using bundle exec rspec spec/openapi.
  • I have run the full test suite using bundle exec rspec.

The cached OpenAPI HTML page embedded the first request's absolute JSON URL. Derive the JSON path from the current browser pathname so the cached page stays request-independent across hosts and mount paths.

Signed-off-by: Mridankan Mandal <xerontitan90@gmail.com>
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.

[OpenAPI] HTML page caches a request-specific spec URL

1 participant