From 4d7ea3a84109af2ba35ef2ad40f00674975a5da1 Mon Sep 17 00:00:00 2001 From: Marc Sardon Date: Tue, 19 Nov 2024 17:24:43 +0000 Subject: [PATCH] Move API from "api/v2" to "ats-api/v1" The original API in the service is an API that the public can consume to get information about the posted vacancies. The new API is going to be private and only accessible to the ATS so they can Publish their vacancies into our system. To avoid confusion, extracted the new API definition under the following path in our project: "app/controller/publishers/ats_api/v1/...." So developers can identify the scope of this API. To avoid a long convoluted API endpoint for our clients, we will expose it under "/ats-api/v1" path. --- .github/workflows/build_and_deploy.yml | 4 ++-- .../ats_api/v1}/vacancies_controller.rb | 2 +- .../ats_api/v1}/vacancies/_show.json.jbuilder | 0 .../ats_api/v1}/vacancies/create.json.jbuilder | 0 .../ats_api/v1}/vacancies/index.json.jbuilder | 0 .../ats_api/v1}/vacancies/show.jbuilder | 0 .../ats_api/v1}/vacancies/update.jbuilder | 0 config/initializers/rswag_ui.rb | 2 +- config/routes.rb | 14 +++++++++----- .../ats_api/v1}/vacancies_spec.rb | 18 +++++++++--------- spec/swagger_helper.rb | 6 +++--- 11 files changed, 25 insertions(+), 21 deletions(-) rename app/controllers/{api/v2 => publishers/ats_api/v1}/vacancies_controller.rb (94%) rename app/views/{api/v2 => publishers/ats_api/v1}/vacancies/_show.json.jbuilder (100%) rename app/views/{api/v2 => publishers/ats_api/v1}/vacancies/create.json.jbuilder (100%) rename app/views/{api/v2 => publishers/ats_api/v1}/vacancies/index.json.jbuilder (100%) rename app/views/{api/v2 => publishers/ats_api/v1}/vacancies/show.jbuilder (100%) rename app/views/{api/v2 => publishers/ats_api/v1}/vacancies/update.jbuilder (100%) rename spec/requests/{api/v2 => publishers/ats_api/v1}/vacancies_spec.rb (98%) diff --git a/.github/workflows/build_and_deploy.yml b/.github/workflows/build_and_deploy.yml index d3e5715e817..ec58708c78c 100644 --- a/.github/workflows/build_and_deploy.yml +++ b/.github/workflows/build_and_deploy.yml @@ -67,7 +67,7 @@ jobs: id: swagger-cache with: path: 'swagger' - key: ${{ runner.os }}-swagger-${{ hashFiles('spec/requests/api/v2/**') }} + key: ${{ runner.os }}-swagger-${{ hashFiles('spec/requests/publishers/ats_api/v1/**') }} build: if: contains(github.event.pull_request.labels.*.name, 'deploy') || github.event_name != 'pull_request' @@ -137,7 +137,7 @@ jobs: id: swagger-cache with: path: 'swagger' - key: ${{ runner.os }}-swagger-${{ hashFiles('spec/requests/api/v2/**') }} + key: ${{ runner.os }}-swagger-${{ hashFiles('spec/requests/publishers/ats_api/v1/**') }} fail-on-cache-miss: true - name: Build and push docker image from builder target diff --git a/app/controllers/api/v2/vacancies_controller.rb b/app/controllers/publishers/ats_api/v1/vacancies_controller.rb similarity index 94% rename from app/controllers/api/v2/vacancies_controller.rb rename to app/controllers/publishers/ats_api/v1/vacancies_controller.rb index 02266640879..ba9a0f7da3a 100644 --- a/app/controllers/api/v2/vacancies_controller.rb +++ b/app/controllers/publishers/ats_api/v1/vacancies_controller.rb @@ -1,4 +1,4 @@ -class Api::V2::VacanciesController < Api::ApplicationController +class Publishers::AtsApi::V1::VacanciesController < Api::ApplicationController def index @pagy, @vacancies = pagy(vacancies, items: 100) diff --git a/app/views/api/v2/vacancies/_show.json.jbuilder b/app/views/publishers/ats_api/v1/vacancies/_show.json.jbuilder similarity index 100% rename from app/views/api/v2/vacancies/_show.json.jbuilder rename to app/views/publishers/ats_api/v1/vacancies/_show.json.jbuilder diff --git a/app/views/api/v2/vacancies/create.json.jbuilder b/app/views/publishers/ats_api/v1/vacancies/create.json.jbuilder similarity index 100% rename from app/views/api/v2/vacancies/create.json.jbuilder rename to app/views/publishers/ats_api/v1/vacancies/create.json.jbuilder diff --git a/app/views/api/v2/vacancies/index.json.jbuilder b/app/views/publishers/ats_api/v1/vacancies/index.json.jbuilder similarity index 100% rename from app/views/api/v2/vacancies/index.json.jbuilder rename to app/views/publishers/ats_api/v1/vacancies/index.json.jbuilder diff --git a/app/views/api/v2/vacancies/show.jbuilder b/app/views/publishers/ats_api/v1/vacancies/show.jbuilder similarity index 100% rename from app/views/api/v2/vacancies/show.jbuilder rename to app/views/publishers/ats_api/v1/vacancies/show.jbuilder diff --git a/app/views/api/v2/vacancies/update.jbuilder b/app/views/publishers/ats_api/v1/vacancies/update.jbuilder similarity index 100% rename from app/views/api/v2/vacancies/update.jbuilder rename to app/views/publishers/ats_api/v1/vacancies/update.jbuilder diff --git a/config/initializers/rswag_ui.rb b/config/initializers/rswag_ui.rb index 4fe59739a7e..8c7ff73ddc2 100644 --- a/config/initializers/rswag_ui.rb +++ b/config/initializers/rswag_ui.rb @@ -7,7 +7,7 @@ # (under openapi_root) as JSON or YAML endpoints, then the list below should # correspond to the relative paths for those endpoints. - c.openapi_endpoint "/api-docs/v2/swagger.yaml", "API V2 Docs" + c.openapi_endpoint "/ats-api-docs/v1/swagger.yaml", "ATS API V1 Docs" # Add Basic Auth in case your API is private # c.basic_auth_enabled = true diff --git a/config/routes.rb b/config/routes.rb index 98120c7c27a..67b4a7feab6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,8 +2,9 @@ require "sidekiq/cron/web" Rails.application.routes.draw do - mount Rswag::Ui::Engine => "/api-docs" - mount Rswag::Api::Engine => "/api-docs" + mount Rswag::Ui::Engine => "/ats-api-docs" + mount Rswag::Api::Engine => "/ats-api-docs" + if Rails.env.development? mount Sidekiq::Web, at: "/sidekiq" else @@ -343,13 +344,16 @@ get "/organisations", to: "organisations#index", as: :organisations resources :markers, only: %i[show] end - scope "v:api_version", api_version: /2/ do - resources :vacancies, only: %i[index show create update destroy], controller: "v2/vacancies", format: :json - end resources :events, only: %i[create] end + namespace :ats_api, path: "ats-api" do + scope "v:api_version", api_version: /1/ do + resources :vacancies, only: %i[index show create update destroy], controller: "publishers/ats_api/v1/vacancies", format: :json + end + end + scope "/organisation", as: "organisation" do scope constraints: { type: /(published|draft|pending|expired|awaiting_feedback)/ } do get "jobs(/:type)", to: "publishers/vacancies#index", defaults: { type: :published }, as: :jobs_with_type diff --git a/spec/requests/api/v2/vacancies_spec.rb b/spec/requests/publishers/ats_api/v1/vacancies_spec.rb similarity index 98% rename from spec/requests/api/v2/vacancies_spec.rb rename to spec/requests/publishers/ats_api/v1/vacancies_spec.rb index 6354c897601..3226c94d5a5 100644 --- a/spec/requests/api/v2/vacancies_spec.rb +++ b/spec/requests/publishers/ats_api/v1/vacancies_spec.rb @@ -2,8 +2,8 @@ # rubocop:disable RSpec/EmptyExampleGroup # rubocop:disable RSpec/ScatteredSetup -RSpec.describe "api/v2/vacancies" do - path "/api/v{api_version}/vacancies" do +RSpec.describe "ats-api/v1/vacancies" do + path "/ats-api/v{api_version}/vacancies" do parameter name: "api_version", in: :path, type: :string, description: "api_version" get("list vacancies") do @@ -11,7 +11,7 @@ produces "application/json" response(200, "successful") do - let(:api_version) { "2" } + let(:api_version) { "1" } let(:page) { nil } before do @@ -366,7 +366,7 @@ } response(201, "successful") do - let(:api_version) { "2" } + let(:api_version) { "1" } after do |example| example.metadata[:response][:content] = { @@ -394,7 +394,7 @@ end response(400, "error") do - let(:api_version) { "2" } + let(:api_version) { "1" } after do |example| example.metadata[:response][:content] = { @@ -439,7 +439,7 @@ end end - path "/api/v{api_version}/vacancies/{id}" do + path "/ats-api/v{api_version}/vacancies/{id}" do parameter name: "api_version", in: :path, type: :string, description: "api_version" parameter name: "id", in: :path, type: :string, description: "id" @@ -450,7 +450,7 @@ produces "application/json" response(200, "successful") do - let(:api_version) { "2" } + let(:api_version) { "1" } after do |example| example.metadata[:response][:content] = { @@ -529,7 +529,7 @@ produces "application/json" response(200, "successful") do - let(:api_version) { "2" } + let(:api_version) { "1" } run_test! end @@ -539,7 +539,7 @@ consumes "application/json" response(204, "successful") do - let(:api_version) { "2" } + let(:api_version) { "1" } run_test! end diff --git a/spec/swagger_helper.rb b/spec/swagger_helper.rb index aec1260dc2c..8f3868d3cfd 100644 --- a/spec/swagger_helper.rb +++ b/spec/swagger_helper.rb @@ -13,11 +13,11 @@ # document below. You can override this behavior by adding a openapi_spec tag to the # the root example_group in your specs, e.g. describe '...', openapi_spec: 'v2/swagger.json' config.openapi_specs = { - "v2/swagger.yaml" => { + "v1/swagger.yaml" => { openapi: "3.0.1", info: { - title: "API V2", - version: "v2", + title: "Teaching Vacancies ATS API", + version: "v1", }, paths: {}, # servers: [