Skip to content

fix: Adjust swagger redirects#1018

Merged
schloerke merged 2 commits intomainfrom
redirect-patch
Jan 27, 2026
Merged

fix: Adjust swagger redirects#1018
schloerke merged 2 commits intomainfrom
redirect-patch

Conversation

@schloerke
Copy link
Collaborator

@schloerke schloerke commented Jan 27, 2026

Summary

This PR adds comprehensive unit tests for the swagger redirect functionality that was fixed in the recent commit addressing issue #1016.

Changes

New Test File

  • tests/testthat/test-swagger-redirects.R (417 lines, 39 tests)
    • Tests redirect structure with default and custom apiPath
    • Tests redirect handlers return correct 301 status codes
    • Tests integration with plumber routers
    • Tests mounting/unmounting behavior
    • Tests edge cases (nested paths, env variables, empty paths)

Updated Test Files

Test Coverage

The new tests verify:

  1. Basic Redirect Functionality

    • Correct redirect structure generation
    • Custom apiPath handling
    • Disabled redirects when plumber.legacyRedirects = FALSE
  2. Redirect Handlers

    • 301 permanent redirect status codes
    • Relative path redirects (../__docs__/) instead of absolute paths
    • Proper handler execution with mock requests/responses
  3. Router Integration

    • Redirects properly mounted on plumber routers
    • Correct behavior with various apiPath configurations (empty, /api/v1, nested)
    • Full request routing through redirect endpoints
  4. Unmounting & Cleanup

    • Proper cleanup when docs are unmounted
    • Overwrite warnings when routes conflict
  5. Edge Cases

    • Nested apiPath values (/api/v1/myapp)
    • Environment variable support (PLUMBER_APIPATH)
    • Empty apiPath handling
    • Multiple independent redirects on same router

Implementation Details

The redirect implementation uses:

  • Redirect keys that include the apiPath prefix (e.g., /api/v2/__swagger__/)
  • Relative path targets (../__docs__/) to ensure redirects work correctly regardless of apiPath configuration
  • This approach works seamlessly with RStudio Connect and other hosting environments

Test Results

All 39 tests pass successfully:

✔ | F W S  OK | Context
✔ |        39 | Swagger redirects

══ Results ═════════════════════════════════════════════════
Duration: 0.8 s

[ FAIL 0 | WARN 0 | SKIP 0 | PASS 39 ]

Integration Verification

Verified the redirects work correctly on a live plumber app:

# With default apiPath
Endpoints: /__swagger__/, /__swagger__/index.html
Redirect: 301../__docs__/

# With custom apiPath (/api/v2)
Endpoints: /api/v2/__swagger__/, /api/v2/__swagger__/index.html
Redirect: 301../__docs__/

Related Issues

Checklist

  • Added comprehensive unit tests
  • All tests pass locally
  • Updated existing tests to match new behavior
  • Verified integration with working plumber apps
  • Tests cover edge cases and various configurations

@schloerke schloerke changed the title Add comprehensive unit tests for swagger redirects fix: Adjust swagger redirects Jan 27, 2026
@schloerke schloerke merged commit 5efb9ab into main Jan 27, 2026
13 checks passed
@schloerke schloerke deleted the redirect-patch branch January 27, 2026 21:09
schloerke added a commit that referenced this pull request Jan 27, 2026
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.

apiPath + redirect breaks default documentation behavior on connect

1 participant