Add V1 API deprecation middleware (configurable with settings)#506
Merged
Add V1 API deprecation middleware (configurable with settings)#506
Conversation
…precated API endpoints
…onses for deprecated endpoints
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a configurable Django middleware to deprecate the v1 API by returning 410 Gone responses for /v1 endpoint requests. The middleware is controlled by the V1_DEPRECATED environment variable and allows for a clean, centralized deprecation strategy.
Key Changes
- New
V1DeprecationMiddlewarethat intercepts v1 API requests when enabled and returns JSON:API-formatted 410 error responses - Environment-based configuration via
V1_DEPRECATEDsetting with a safe default ofFalse - Comprehensive test suite covering various path patterns, HTTP methods, and configuration states
Reviewed Changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| rorapi/middleware/deprecation.py | New middleware implementation that checks request paths and returns 410 responses for v1 endpoints when deprecation is enabled |
| rorapi/settings.py | Adds V1_DEPRECATED configuration from environment variable and registers the middleware in the MIDDLEWARE list |
| rorapi/tests/tests_unit/tests_deprecation_middleware.py | Comprehensive test suite with 11 test cases covering enabled/disabled states, different path patterns, HTTP methods, and error response format |
| rorapi/middleware/init.py | Package initialization file for the middleware module |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
This PR introduces a new Django middleware to handle the deprecation of the v1 API endpoints. When enabled, this middleware will return a
410 Gonestatus code for any requests targeting/v1paths, along with a message guiding users to migrate to v2.Approach
A new Django middleware,
V1DeprecationMiddleware, has been created. This middleware is added to theMIDDLEWAREsetting and checks the request path. If theV1_DEPRECATEDsetting is enabled (controlled by an environment variable) and the request path starts with/v1/or is exactly/v1, the middleware intercepts the request and returns aJsonResponsewith a410 Gonestatus. Otherwise, it allows the request to proceed to the next middleware or view.Key Modifications
rorapi/middleware/deprecation.pycontainingV1DeprecationMiddleware.rorapi/settings.pyincludesV1_DEPRECATEDsetting, which can be configured via theV1_DEPRECATEDenvironment variable.rorapi/settings.pyaddsrorapi.middleware.deprecation.V1DeprecationMiddlewareto theMIDDLEWARElist.rorapi/tests/tests_unit/tests_deprecation_middleware.pywith comprehensive unit tests for the new middleware.Important Technical Details
V1_DEPRECATEDsetting defaults toFalseif the environment variable is not set./v1/(e.g.,/v1/organizations) and exact/v1paths./v1(e.g.,/v2/,/heartbeat,/) are not affected by this middleware.Types of changes
New feature (non-breaking change which adds functionality)
Bug fix (non-breaking change which fixes an issue)
Breaking change (fix or feature that would cause existing functionality to change)
Reviewer, please remember our guidelines: