diff --git a/app/controllers/api_application_controller.rb b/app/controllers/api_application_controller.rb index 6f72ca21ee..ec8a97aa71 100644 --- a/app/controllers/api_application_controller.rb +++ b/app/controllers/api_application_controller.rb @@ -5,10 +5,13 @@ # class ApplicationController < ActionController::Base class ApiApplicationController < StashEngine::ApplicationController + include StashApi::Versioning layout 'layouts/stash_engine/application' before_action :log_request + before_action :set_response_version_header + before_action :check_requested_version skip_before_action :verify_authenticity_token DEFAULT_PAGE_SIZE = 20 diff --git a/app/controllers/stash_api/versioning.rb b/app/controllers/stash_api/versioning.rb new file mode 100644 index 0000000000..93d6481a12 --- /dev/null +++ b/app/controllers/stash_api/versioning.rb @@ -0,0 +1,34 @@ +module StashApi + module Versioning + extend ActiveSupport::Concern + + private + + def set_response_version_header + response.headers['X-API-Version'] = api_version + return if api_version == current_version + + response.headers['X-API-Deprecation'] = 'true' + end + + def check_requested_version + return if !requested_version || requested_version == current_version + + render json: { error: "Unsupported API version: #{requested_version}, latest version is: #{current_version}" }, status: 400 + end + + def current_version + '2.1.0' + end + + def api_version + return requested_version if requested_version + + request.path.include?('/api/v2') ? '2.1.0' : '1.0.0' + end + + def requested_version + @requested_version ||= request.headers['X-API-Version'] + end + end +end diff --git a/app/javascript/react/components/MetadataEntry/ResearchDomain.jsx b/app/javascript/react/components/MetadataEntry/ResearchDomain.jsx index d8770cbb0b..cf60756db5 100644 --- a/app/javascript/react/components/MetadataEntry/ResearchDomain.jsx +++ b/app/javascript/react/components/MetadataEntry/ResearchDomain.jsx @@ -52,6 +52,7 @@ function ResearchDomain({ formik.handleSubmit(); }} > +