From 6d3182a6eb2de6998a832669f5a81c31512455ed Mon Sep 17 00:00:00 2001 From: David Roetzel Date: Fri, 29 May 2026 10:39:51 +0200 Subject: [PATCH] Move Collections API to `v1` namespace (#39210) --- .../collection_items_controller.rb | 2 +- .../collections_controller.rb | 6 ++-- .../in_collections_controller.rb | 6 ++-- config/routes/api.rb | 18 ++++++++++-- lib/mastodon/version.rb | 2 +- .../{v1_alpha => v1}/collection_items_spec.rb | 0 .../api/{v1_alpha => v1}/collections_spec.rb | 28 +++++++++---------- .../{v1_alpha => v1}/in_collections_spec.rb | 12 ++++---- 8 files changed, 44 insertions(+), 30 deletions(-) rename app/controllers/api/{v1_alpha => v1}/collection_items_controller.rb (95%) rename app/controllers/api/{v1_alpha => v1}/collections_controller.rb (90%) rename app/controllers/api/{v1_alpha => v1}/in_collections_controller.rb (79%) rename spec/requests/api/{v1_alpha => v1}/collection_items_spec.rb (100%) rename spec/requests/api/{v1_alpha => v1}/collections_spec.rb (87%) rename spec/requests/api/{v1_alpha => v1}/in_collections_spec.rb (75%) diff --git a/app/controllers/api/v1_alpha/collection_items_controller.rb b/app/controllers/api/v1/collection_items_controller.rb similarity index 95% rename from app/controllers/api/v1_alpha/collection_items_controller.rb rename to app/controllers/api/v1/collection_items_controller.rb index 2c46cc4f9f..eaa46a4430 100644 --- a/app/controllers/api/v1_alpha/collection_items_controller.rb +++ b/app/controllers/api/v1/collection_items_controller.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Api::V1Alpha::CollectionItemsController < Api::BaseController +class Api::V1::CollectionItemsController < Api::BaseController include Authorization before_action :check_feature_enabled diff --git a/app/controllers/api/v1_alpha/collections_controller.rb b/app/controllers/api/v1/collections_controller.rb similarity index 90% rename from app/controllers/api/v1_alpha/collections_controller.rb rename to app/controllers/api/v1/collections_controller.rb index 1ca1cd6923..3c1841237d 100644 --- a/app/controllers/api/v1_alpha/collections_controller.rb +++ b/app/controllers/api/v1/collections_controller.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Api::V1Alpha::CollectionsController < Api::BaseController +class Api::V1::CollectionsController < Api::BaseController include Authorization DEFAULT_COLLECTIONS_LIMIT = 40 @@ -98,13 +98,13 @@ class Api::V1Alpha::CollectionsController < Api::BaseController def next_path return unless records_continue? - api_v1_alpha_account_collections_url(@account, pagination_params(offset: offset_param + limit_param(DEFAULT_COLLECTIONS_LIMIT))) + api_v1_account_collections_url(@account, pagination_params(offset: offset_param + limit_param(DEFAULT_COLLECTIONS_LIMIT))) end def prev_path return if offset_param.zero? - api_v1_alpha_account_collections_url(@account, pagination_params(offset: offset_param - limit_param(DEFAULT_COLLECTIONS_LIMIT))) + api_v1_account_collections_url(@account, pagination_params(offset: offset_param - limit_param(DEFAULT_COLLECTIONS_LIMIT))) end def records_continue? diff --git a/app/controllers/api/v1_alpha/in_collections_controller.rb b/app/controllers/api/v1/in_collections_controller.rb similarity index 79% rename from app/controllers/api/v1_alpha/in_collections_controller.rb rename to app/controllers/api/v1/in_collections_controller.rb index 087464989e..54a1334e3c 100644 --- a/app/controllers/api/v1_alpha/in_collections_controller.rb +++ b/app/controllers/api/v1/in_collections_controller.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Api::V1Alpha::InCollectionsController < Api::BaseController +class Api::V1::InCollectionsController < Api::BaseController include Authorization DEFAULT_COLLECTIONS_LIMIT = 40 @@ -44,13 +44,13 @@ class Api::V1Alpha::InCollectionsController < Api::BaseController def next_path return unless records_continue? - api_v1_alpha_account_in_collections_url(@account, pagination_params(offset: offset_param + limit_param(DEFAULT_COLLECTIONS_LIMIT))) + api_v1_account_in_collections_url(@account, pagination_params(offset: offset_param + limit_param(DEFAULT_COLLECTIONS_LIMIT))) end def prev_path return if offset_param.zero? - api_v1_alpha_account_in_collections_url(@account, pagination_params(offset: offset_param - limit_param(DEFAULT_COLLECTIONS_LIMIT))) + api_v1_account_in_collections_url(@account, pagination_params(offset: offset_param - limit_param(DEFAULT_COLLECTIONS_LIMIT))) end def records_continue? diff --git a/config/routes/api.rb b/config/routes/api.rb index 2546b5517a..a212685eb0 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -6,13 +6,16 @@ namespace :api, format: false do # Experimental JSON / REST API namespace :v1_alpha do + resources :async_refreshes, only: :show + end + + # TODO: Remove once apps switch over to v1 + scope :v1_alpha, as: :v1_alpha, module: :v1 do resources :accounts, only: [] do resources :collections, only: [:index] resources :in_collections, only: [:index] end - resources :async_refreshes, only: :show - resources :collections, only: [:show, :create, :update, :destroy] do resources :items, only: [:create, :destroy], controller: 'collection_items' do member do @@ -221,6 +224,9 @@ namespace :api, format: false do resources :email_subscriptions, only: :create end + resources :collections, only: [:index] + resources :in_collections, only: [:index] + member do post :follow post :unfollow @@ -327,6 +333,14 @@ namespace :api, format: false do resources :tags, only: [:index, :show, :update] end + + resources :collections, only: [:show, :create, :update, :destroy] do + resources :items, only: [:create, :destroy], controller: 'collection_items' do + member do + post :revoke + end + end + end end namespace :v2 do diff --git a/lib/mastodon/version.rb b/lib/mastodon/version.rb index 750c83b718..6d5353eefc 100644 --- a/lib/mastodon/version.rb +++ b/lib/mastodon/version.rb @@ -45,7 +45,7 @@ module Mastodon def api_versions { - mastodon: 9, + mastodon: 10, } end diff --git a/spec/requests/api/v1_alpha/collection_items_spec.rb b/spec/requests/api/v1/collection_items_spec.rb similarity index 100% rename from spec/requests/api/v1_alpha/collection_items_spec.rb rename to spec/requests/api/v1/collection_items_spec.rb diff --git a/spec/requests/api/v1_alpha/collections_spec.rb b/spec/requests/api/v1/collections_spec.rb similarity index 87% rename from spec/requests/api/v1_alpha/collections_spec.rb rename to spec/requests/api/v1/collections_spec.rb index f448659bf5..4bf296f293 100644 --- a/spec/requests/api/v1_alpha/collections_spec.rb +++ b/spec/requests/api/v1/collections_spec.rb @@ -2,12 +2,12 @@ require 'rails_helper' -RSpec.describe 'Api::V1Alpha::Collections', feature: :collections do +RSpec.describe 'Api::V1::Collections', feature: :collections do include_context 'with API authentication', oauth_scopes: 'read:collections write:collections' - describe 'GET /api/v1_alpha/accounts/:account_id/collections' do + describe 'GET /api/v1/accounts/:account_id/collections' do subject do - get "/api/v1_alpha/accounts/#{account.id}/collections", headers: headers, params: params + get "/api/v1/accounts/#{account.id}/collections", headers: headers, params: params end let(:params) { {} } @@ -34,7 +34,7 @@ RSpec.describe 'Api::V1Alpha::Collections', feature: :collections do expect(response) .to include_pagination_headers( - next: api_v1_alpha_account_collections_url(account, limit: 1, offset: 1) + next: api_v1_account_collections_url(account, limit: 1, offset: 1) ) end end @@ -50,8 +50,8 @@ RSpec.describe 'Api::V1Alpha::Collections', feature: :collections do expect(response) .to include_pagination_headers( - prev: api_v1_alpha_account_collections_url(account, limit: 1, offset: 0), - next: api_v1_alpha_account_collections_url(account, limit: 1, offset: 2) + prev: api_v1_account_collections_url(account, limit: 1, offset: 0), + next: api_v1_account_collections_url(account, limit: 1, offset: 2) ) end end @@ -96,9 +96,9 @@ RSpec.describe 'Api::V1Alpha::Collections', feature: :collections do end end - describe 'GET /api/v1_alpha/collections/:id' do + describe 'GET /api/v1/collections/:id' do subject do - get "/api/v1_alpha/collections/#{collection.id}", headers: headers + get "/api/v1/collections/#{collection.id}", headers: headers end let(:collection) { Fabricate(:collection) } @@ -140,9 +140,9 @@ RSpec.describe 'Api::V1Alpha::Collections', feature: :collections do end end - describe 'POST /api/v1_alpha/collections' do + describe 'POST /api/v1/collections' do subject do - post '/api/v1_alpha/collections', headers: headers, params: params + post '/api/v1/collections', headers: headers, params: params end let(:params) { {} } @@ -187,9 +187,9 @@ RSpec.describe 'Api::V1Alpha::Collections', feature: :collections do end end - describe 'PATCH /api/v1_alpha/collections/:id' do + describe 'PATCH /api/v1/collections/:id' do subject do - patch "/api/v1_alpha/collections/#{collection.id}", headers: headers, params: params + patch "/api/v1/collections/#{collection.id}", headers: headers, params: params end let(:collection) { Fabricate(:collection) } @@ -256,9 +256,9 @@ RSpec.describe 'Api::V1Alpha::Collections', feature: :collections do end end - describe 'DELETE /api/v1_alpha/collections/:id' do + describe 'DELETE /api/v1/collections/:id' do subject do - delete "/api/v1_alpha/collections/#{collection.id}", headers: headers + delete "/api/v1/collections/#{collection.id}", headers: headers end let(:collection) { Fabricate(:collection) } diff --git a/spec/requests/api/v1_alpha/in_collections_spec.rb b/spec/requests/api/v1/in_collections_spec.rb similarity index 75% rename from spec/requests/api/v1_alpha/in_collections_spec.rb rename to spec/requests/api/v1/in_collections_spec.rb index a4bd3110be..3c41feb2e7 100644 --- a/spec/requests/api/v1_alpha/in_collections_spec.rb +++ b/spec/requests/api/v1/in_collections_spec.rb @@ -2,12 +2,12 @@ require 'rails_helper' -RSpec.describe 'Api::V1Alpha::InCollections', feature: :collections do +RSpec.describe 'Api::V1::InCollections', feature: :collections do include_context 'with API authentication', oauth_scopes: 'read:collections write:collections' - describe 'GET /api/v1_alpha/in_collections' do + describe 'GET /api/v1/in_collections' do subject do - get "/api/v1_alpha/accounts/#{account.id}/in_collections", headers: headers, params: params + get "/api/v1/accounts/#{account.id}/in_collections", headers: headers, params: params end let(:params) { {} } @@ -33,7 +33,7 @@ RSpec.describe 'Api::V1Alpha::InCollections', feature: :collections do expect(response) .to include_pagination_headers( - next: api_v1_alpha_account_in_collections_url(account, limit: 1, offset: 1) + next: api_v1_account_in_collections_url(account, limit: 1, offset: 1) ) end end @@ -49,8 +49,8 @@ RSpec.describe 'Api::V1Alpha::InCollections', feature: :collections do expect(response) .to include_pagination_headers( - prev: api_v1_alpha_account_in_collections_url(account, limit: 1, offset: 0), - next: api_v1_alpha_account_in_collections_url(account, limit: 1, offset: 2) + prev: api_v1_account_in_collections_url(account, limit: 1, offset: 0), + next: api_v1_account_in_collections_url(account, limit: 1, offset: 2) ) end end