diff --git a/modules/appeals_api/app/controllers/appeals_api/appealable_issues/v0/appealable_issues_controller.rb b/modules/appeals_api/app/controllers/appeals_api/appealable_issues/v0/appealable_issues_controller.rb index bcd584b26fb..295dbaf2191 100644 --- a/modules/appeals_api/app/controllers/appeals_api/appealable_issues/v0/appealable_issues_controller.rb +++ b/modules/appeals_api/app/controllers/appeals_api/appealable_issues/v0/appealable_issues_controller.rb @@ -5,37 +5,27 @@ module AppealsApi::AppealableIssues::V0 class AppealableIssuesController < AppealsApi::V2::DecisionReviews::ContestableIssuesController include AppealsApi::OpenidAuth + include AppealsApi::Schemas - FORM_NUMBER = 'APPEALABLE_ISSUES_HEADERS' - HEADERS = JSON.parse( - File.read(AppealsApi::Engine.root.join('config/schemas/v0/appealable_issues_headers.json')) - )['definitions']['appealableIssuesIndexParameters']['properties'].keys + SCHEMA_OPTIONS = { schema_version: 'v0', api_name: 'appealable_issues' }.freeze OAUTH_SCOPES = { GET: %w[veteran/AppealableIssues.read representative/AppealableIssues.read system/AppealableIssues.read] }.freeze def schema - render json: AppealsApi::JsonSchemaToSwaggerConverter.remove_comments( - AppealsApi::FormSchemas.new( - SCHEMA_ERROR_TYPE, - schema_version: 'v0' - ).schema(self.class::FORM_NUMBER) - ) + render json: AppealsApi::JsonSchemaToSwaggerConverter.remove_comments(headers_schema) end private + def header_names = headers_schema['definitions']['appealableIssuesIndexParameters']['properties'].keys + def token_validation_api_key # FIXME: rename token storage key Settings.dig(:modules_appeals_api, :token_validation, :contestable_issues, :api_key) end - def validate_json_schema_for_headers - AppealsApi::FormSchemas.new(SCHEMA_ERROR_TYPE, schema_version: 'v0') - .validate!(self.class::FORM_NUMBER, request_headers) - end - def filtered_caseflow_response(decision_review_type, caseflow_response, filter) super diff --git a/modules/appeals_api/app/controllers/appeals_api/higher_level_reviews/v0/higher_level_reviews_controller.rb b/modules/appeals_api/app/controllers/appeals_api/higher_level_reviews/v0/higher_level_reviews_controller.rb index d611e322f0a..f44a1448897 100644 --- a/modules/appeals_api/app/controllers/appeals_api/higher_level_reviews/v0/higher_level_reviews_controller.rb +++ b/modules/appeals_api/app/controllers/appeals_api/higher_level_reviews/v0/higher_level_reviews_controller.rb @@ -6,14 +6,8 @@ module AppealsApi::HigherLevelReviews::V0 class HigherLevelReviewsController < AppealsApi::V2::DecisionReviews::HigherLevelReviewsController include AppealsApi::OpenidAuth - FORM_NUMBER = '200996_WITH_SHARED_REFS' API_VERSION = 'V0' - SCHEMA_VERSION = 'v2' - HEADERS = JSON.parse( - File.read( - AppealsApi::Engine.root.join('config/schemas/v2/200996_with_shared_refs_headers.json') - ) - )['definitions']['hlrCreateParameters']['properties'].keys + SCHEMA_OPTIONS = { schema_version: 'v0', api_name: 'higher_level_reviews' }.freeze OAUTH_SCOPES = { GET: %w[veteran/HigherLevelReviews.read representative/HigherLevelReviews.read system/HigherLevelReviews.read], @@ -23,6 +17,8 @@ class HigherLevelReviewsController < AppealsApi::V2::DecisionReviews::HigherLeve private + def header_names = headers_schema['definitions']['hlrCreateParameters']['properties'].keys + def token_validation_api_key Settings.dig(:modules_appeals_api, :token_validation, :higher_level_reviews, :api_key) end diff --git a/modules/appeals_api/app/controllers/appeals_api/legacy_appeals/v0/legacy_appeals_controller.rb b/modules/appeals_api/app/controllers/appeals_api/legacy_appeals/v0/legacy_appeals_controller.rb index e5386a2fa9e..f653e118594 100644 --- a/modules/appeals_api/app/controllers/appeals_api/legacy_appeals/v0/legacy_appeals_controller.rb +++ b/modules/appeals_api/app/controllers/appeals_api/legacy_appeals/v0/legacy_appeals_controller.rb @@ -4,26 +4,17 @@ module AppealsApi::LegacyAppeals::V0 class LegacyAppealsController < AppealsApi::V2::DecisionReviews::LegacyAppealsController + include AppealsApi::Schemas include AppealsApi::OpenidAuth - FORM_NUMBER = 'LEGACY_APPEALS_HEADERS_WITH_SHARED_REFS' - HEADERS = JSON.parse( - File.read( - AppealsApi::Engine.root.join('config/schemas/v2/legacy_appeals_headers_with_shared_refs.json') - ) - )['definitions']['legacyAppealsIndexParameters']['properties'].keys + SCHEMA_OPTIONS = { schema_version: 'v0', api_name: 'legacy_appeals' }.freeze OAUTH_SCOPES = { GET: %w[veteran/LegacyAppeals.read representative/LegacyAppeals.read system/LegacyAppeals.read] }.freeze def schema - render json: AppealsApi::JsonSchemaToSwaggerConverter.remove_comments( - AppealsApi::FormSchemas.new( - SCHEMA_ERROR_TYPE, - schema_version: 'v2' - ).schema(self.class::FORM_NUMBER) - ) + render json: AppealsApi::JsonSchemaToSwaggerConverter.remove_comments(headers_schema) end private diff --git a/modules/appeals_api/app/controllers/appeals_api/notice_of_disagreements/v0/notice_of_disagreements_controller.rb b/modules/appeals_api/app/controllers/appeals_api/notice_of_disagreements/v0/notice_of_disagreements_controller.rb index 469ac51192e..1a39b09616e 100644 --- a/modules/appeals_api/app/controllers/appeals_api/notice_of_disagreements/v0/notice_of_disagreements_controller.rb +++ b/modules/appeals_api/app/controllers/appeals_api/notice_of_disagreements/v0/notice_of_disagreements_controller.rb @@ -6,14 +6,8 @@ module AppealsApi::NoticeOfDisagreements::V0 class NoticeOfDisagreementsController < AppealsApi::V2::DecisionReviews::NoticeOfDisagreementsController include AppealsApi::OpenidAuth - FORM_NUMBER = '10182_WITH_SHARED_REFS' API_VERSION = 'V0' - SCHEMA_VERSION = 'v2' - HEADERS = JSON.parse( - File.read( - AppealsApi::Engine.root.join('config/schemas/v2/10182_with_shared_refs_headers.json') - ) - )['definitions']['nodCreateParameters']['properties'].keys + SCHEMA_OPTIONS = { schema_version: 'v0', api_name: 'notice_of_disagreements' }.freeze OAUTH_SCOPES = { GET: %w[ @@ -34,14 +28,7 @@ class NoticeOfDisagreementsController < AppealsApi::V2::DecisionReviews::NoticeO }.freeze def schema - response = AppealsApi::JsonSchemaToSwaggerConverter.remove_comments( - AppealsApi::FormSchemas.new( - SCHEMA_ERROR_TYPE, - schema_version: self.class::SCHEMA_VERSION - ).schema(self.class::FORM_NUMBER) - ) - - render json: response + render json: AppealsApi::JsonSchemaToSwaggerConverter.remove_comments(form_schema) end private diff --git a/modules/appeals_api/app/controllers/appeals_api/schemas/shared_schemas_controller.rb b/modules/appeals_api/app/controllers/appeals_api/schemas/shared_schemas_controller.rb index 0717f3ff598..67b0faa4031 100644 --- a/modules/appeals_api/app/controllers/appeals_api/schemas/shared_schemas_controller.rb +++ b/modules/appeals_api/app/controllers/appeals_api/schemas/shared_schemas_controller.rb @@ -13,13 +13,10 @@ class AppealsApi::Schemas::SharedSchemasController < AppealsApi::ApplicationCont timezone ].freeze - SCHEMA_METADATA = { - 'contestable_issues_v0' => { shared_schema_version: 'v1', form: 'headers' }, - 'legacy_appeals_v0' => { shared_schema_version: 'v1', form: 'headers' }, - 'notice_of_disagreements_v1' => { shared_schema_version: 'v1', form: '10182' }, - 'notice_of_disagreements_v0' => { shared_schema_version: 'v1', form: '10182' }, - 'higher_level_reviews_v0' => { shared_schema_version: 'v1', form: '200996' }, - 'supplemental_claims_v0' => { shared_schema_version: 'v1', form: '200995' } + FORM_NUMBERS = { + 'notice_of_disagreements' => '10182', + 'higher_level_reviews' => '200996', + 'supplemental_claims' => '200995' }.freeze def show @@ -32,16 +29,16 @@ def uri @uri ||= URI(request.path) end - def appeal_type_with_version - "#{uri.path.split('/')[3]}_#{uri.path.split('/')[4]}".tr('-', '_') + def api_name + uri.path.split('/')[3].tr('-', '_') end - def schema_version - SCHEMA_METADATA[appeal_type_with_version][:shared_schema_version] + def api_version + uri.path.split('/')[4] end - def schema_form - SCHEMA_METADATA[appeal_type_with_version][:form] + def schema_form_name + FORM_NUMBERS[api_name] || 'headers' end def schema_type @@ -49,7 +46,7 @@ def schema_type end def shared_schemas_file - Rails.root.join('modules', 'appeals_api', 'config', 'schemas', 'shared', schema_version, "#{schema_type}.json") + Rails.root.join('modules', 'appeals_api', 'config', 'schemas', 'shared', api_version, "#{schema_type}.json") end def file_as_json @@ -70,7 +67,7 @@ def invalid_schema_type_error code: 'InvalidSchemaType', status: '404', source: { parameter: schema_type }, - meta: { 'available_options': [schema_form] + ACCEPTED_SCHEMA_TYPES } + meta: { 'available_options': [schema_form_name] + ACCEPTED_SCHEMA_TYPES } } end end diff --git a/modules/appeals_api/app/controllers/appeals_api/supplemental_claims/v0/supplemental_claims_controller.rb b/modules/appeals_api/app/controllers/appeals_api/supplemental_claims/v0/supplemental_claims_controller.rb index b2f7695e8c6..13d097debef 100644 --- a/modules/appeals_api/app/controllers/appeals_api/supplemental_claims/v0/supplemental_claims_controller.rb +++ b/modules/appeals_api/app/controllers/appeals_api/supplemental_claims/v0/supplemental_claims_controller.rb @@ -6,14 +6,8 @@ module AppealsApi::SupplementalClaims::V0 class SupplementalClaimsController < AppealsApi::V2::DecisionReviews::SupplementalClaimsController include AppealsApi::OpenidAuth - FORM_NUMBER = '200995_WITH_SHARED_REFS' API_VERSION = 'V0' - SCHEMA_VERSION = 'v2' - HEADERS = JSON.parse( - File.read( - AppealsApi::Engine.root.join('config/schemas/v2/200995_with_shared_refs_headers.json') - ) - )['definitions']['scCreateParameters']['properties'].keys + SCHEMA_OPTIONS = { schema_version: 'v0', api_name: 'supplemental_claims' }.freeze OAUTH_SCOPES = { GET: %w[veteran/SupplementalClaims.read representative/SupplementalClaims.read system/SupplementalClaims.read], diff --git a/modules/appeals_api/app/controllers/appeals_api/v1/decision_reviews/notice_of_disagreements/evidence_submissions_controller.rb b/modules/appeals_api/app/controllers/appeals_api/v1/decision_reviews/notice_of_disagreements/evidence_submissions_controller.rb index 1c12f08a00d..81e367c905f 100644 --- a/modules/appeals_api/app/controllers/appeals_api/v1/decision_reviews/notice_of_disagreements/evidence_submissions_controller.rb +++ b/modules/appeals_api/app/controllers/appeals_api/v1/decision_reviews/notice_of_disagreements/evidence_submissions_controller.rb @@ -7,14 +7,12 @@ class EvidenceSubmissionsController < AppealsApi::ApplicationController include AppealsApi::StatusSimulation include SentryLogging include AppealsApi::CharacterUtilities + include AppealsApi::Schemas class EvidenceSubmissionRequestValidatorError < StandardError; end - HEADERS = JSON.parse( - File.read( - AppealsApi::Engine.root.join('config/schemas/v1/10182_headers.json') - ) - )['definitions']['nodCreateHeadersRoot']['properties'].keys + SCHEMA_OPTIONS = { schema_version: 'v1', api_name: 'decision_reviews' }.freeze + FORM_NUMBER = AppealsApi::V1::DecisionReviews::NoticeOfDisagreementsController::FORM_NUMBER skip_before_action :authenticate before_action :nod_uuid_present?, only: :create @@ -53,6 +51,8 @@ def show private + def header_names = headers_schema['definitions']['nodCreateHeadersRoot']['properties'].keys + def nod_uuid_present? nod_uuid_missing_error unless params[:nod_uuid] end @@ -73,7 +73,7 @@ def submission_attributes end def request_headers - HEADERS.index_with { |key| request.headers[key] }.compact + header_names.index_with { |key| request.headers[key] }.compact end def log_error(error_detail) diff --git a/modules/appeals_api/app/controllers/appeals_api/v1/decision_reviews/notice_of_disagreements_controller.rb b/modules/appeals_api/app/controllers/appeals_api/v1/decision_reviews/notice_of_disagreements_controller.rb index 32b37d1b291..bbc6c4d9b12 100644 --- a/modules/appeals_api/app/controllers/appeals_api/v1/decision_reviews/notice_of_disagreements_controller.rb +++ b/modules/appeals_api/app/controllers/appeals_api/v1/decision_reviews/notice_of_disagreements_controller.rb @@ -8,6 +8,7 @@ class AppealsApi::V1::DecisionReviews::NoticeOfDisagreementsController < Appeals include AppealsApi::StatusSimulation include AppealsApi::CharacterUtilities include AppealsApi::HeaderModification + include AppealsApi::Schemas skip_before_action :authenticate before_action :validate_json_format, if: -> { request.post? } @@ -15,14 +16,9 @@ class AppealsApi::V1::DecisionReviews::NoticeOfDisagreementsController < Appeals before_action :new_notice_of_disagreement, only: %i[create validate] before_action :find_notice_of_disagreement, only: %i[show] + SCHEMA_OPTIONS = { schema_version: 'v1', api_name: 'decision_reviews' }.freeze FORM_NUMBER = '10182' MODEL_ERROR_STATUS = 422 - HEADERS = JSON.parse( - File.read( - AppealsApi::Engine.root.join('config/schemas/v1/10182_headers.json') - ) - )['definitions']['nodCreateHeadersRoot']['properties'].keys - SCHEMA_ERROR_TYPE = Common::Exceptions::DetailedSchemaErrors def create deprecate_headers @@ -51,28 +47,20 @@ def validate def schema deprecate_headers - render json: AppealsApi::JsonSchemaToSwaggerConverter.remove_comments( - AppealsApi::FormSchemas.new.schema(self.class::FORM_NUMBER) - ) + render json: AppealsApi::JsonSchemaToSwaggerConverter.remove_comments(form_schema) end private + def header_names = headers_schema['definitions']['nodCreateHeadersRoot']['properties'].keys + def validate_json_schema - validate_json_schema_for_headers - validate_json_schema_for_body - rescue SCHEMA_ERROR_TYPE => e + validate_headers(request_headers) + validate_form_data(@json_body) + rescue Common::Exceptions::DetailedSchemaErrors => e render json: { errors: e.errors }, status: :unprocessable_entity end - def validate_json_schema_for_headers - AppealsApi::FormSchemas.new(SCHEMA_ERROR_TYPE).validate!("#{FORM_NUMBER}_HEADERS", request_headers) - end - - def validate_json_schema_for_body - AppealsApi::FormSchemas.new(SCHEMA_ERROR_TYPE).validate!(FORM_NUMBER, @json_body) - end - def validation_success { data: { @@ -85,7 +73,7 @@ def validation_success end def request_headers - HEADERS.index_with { |key| request.headers[key] }.compact + header_names.index_with { |key| request.headers[key] }.compact end def new_notice_of_disagreement diff --git a/modules/appeals_api/app/controllers/appeals_api/v2/decision_reviews/contestable_issues_controller.rb b/modules/appeals_api/app/controllers/appeals_api/v2/decision_reviews/contestable_issues_controller.rb index 469bed4e602..f3a98841ebc 100644 --- a/modules/appeals_api/app/controllers/appeals_api/v2/decision_reviews/contestable_issues_controller.rb +++ b/modules/appeals_api/app/controllers/appeals_api/v2/decision_reviews/contestable_issues_controller.rb @@ -7,19 +7,20 @@ module AppealsApi::V2 module DecisionReviews class ContestableIssuesController < AppealsApi::ApplicationController - FORM_NUMBER = 'CONTESTABLE_ISSUES_HEADERS' - HEADERS = JSON.parse( - File.read( - AppealsApi::Engine.root.join('config/schemas/v2/contestable_issues_headers.json') - ) - )['definitions']['contestableIssuesIndexParameters']['properties'].keys - SCHEMA_ERROR_TYPE = Common::Exceptions::DetailedSchemaErrors + include AppealsApi::Schemas + skip_before_action :authenticate before_action :validate_json_schema, only: %i[index] before_action :validate_params, only: %i[index] VALID_DECISION_REVIEW_TYPES = %w[higher_level_reviews notice_of_disagreements supplemental_claims].freeze + SCHEMA_OPTIONS = { + api_name: 'decision_reviews', + headers_schema_name: 'contestable_issues_headers', + schema_version: 'v2' + }.freeze + UNUSABLE_RESPONSE_ERROR = { errors: [ { @@ -43,6 +44,8 @@ def index private + def header_names = headers_schema['definitions']['contestableIssuesIndexParameters']['properties'].keys + attr_reader :caseflow_response, :backend_service_exception def get_contestable_issues_from_caseflow(filter: true) @@ -157,7 +160,7 @@ def render_unprocessable_entity(message) end def request_headers - self.class::HEADERS.index_with { |key| request.headers[key] }.compact + header_names.index_with { |key| request.headers[key] }.compact end def caseflow_request_headers @@ -165,17 +168,10 @@ def caseflow_request_headers end def validate_json_schema - validate_json_schema_for_headers + validate_headers(request_headers) validate_params end - def validate_json_schema_for_headers - AppealsApi::FormSchemas.new( - SCHEMA_ERROR_TYPE, - schema_version: 'v2' - ).validate!(self.class::FORM_NUMBER, request_headers) - end - def caseflow_benefit_type_mapping { 'compensation' => 'compensation', diff --git a/modules/appeals_api/app/controllers/appeals_api/v2/decision_reviews/higher_level_reviews_controller.rb b/modules/appeals_api/app/controllers/appeals_api/v2/decision_reviews/higher_level_reviews_controller.rb index caba92d2d88..f2b99ea3826 100644 --- a/modules/appeals_api/app/controllers/appeals_api/v2/decision_reviews/higher_level_reviews_controller.rb +++ b/modules/appeals_api/app/controllers/appeals_api/v2/decision_reviews/higher_level_reviews_controller.rb @@ -8,6 +8,7 @@ class AppealsApi::V2::DecisionReviews::HigherLevelReviewsController < AppealsApi include AppealsApi::StatusSimulation include AppealsApi::CharacterUtilities include AppealsApi::MPIVeteran + include AppealsApi::Schemas skip_before_action :authenticate before_action :validate_index_headers, only: %i[index] @@ -18,14 +19,8 @@ class AppealsApi::V2::DecisionReviews::HigherLevelReviewsController < AppealsApi FORM_NUMBER = '200996' API_VERSION = 'V2' - SCHEMA_VERSION = 'v2' MODEL_ERROR_STATUS = 422 - HEADERS = JSON.parse( - File.read( - AppealsApi::Engine.root.join('config/schemas/v2/200996_headers.json') - ) - )['definitions']['hlrCreateParameters']['properties'].keys - SCHEMA_ERROR_TYPE = Common::Exceptions::DetailedSchemaErrors + SCHEMA_OPTIONS = { schema_version: 'v2', api_name: 'decision_reviews' }.freeze ALLOWED_COLUMNS = %i[id status code detail created_at updated_at].freeze ICN_HEADER = 'X-VA-ICN' ICN_REGEX = /^[0-9]{10}V[0-9]{6}$/ @@ -53,12 +48,7 @@ def validate end def schema - render json: AppealsApi::JsonSchemaToSwaggerConverter.remove_comments( - AppealsApi::FormSchemas.new( - SCHEMA_ERROR_TYPE, - schema_version: self.class::SCHEMA_VERSION - ).schema(self.class::FORM_NUMBER) - ) + render json: AppealsApi::JsonSchemaToSwaggerConverter.remove_comments(form_schema) end def show @@ -68,6 +58,8 @@ def show private + def header_names = headers_schema['definitions']['hlrCreateParameters']['properties'].keys + def validate_index_headers validation_errors = [] @@ -81,27 +73,13 @@ def validate_index_headers end def validate_json_schema - validate_json_schema_for_headers - validate_json_schema_for_body + validate_headers(request_headers) + validate_form_data(@json_body) validate_json_schema_for_pdf_fit rescue JsonSchema::JsonApiMissingAttribute => e render json: e.to_json_api, status: e.code end - def validate_json_schema_for_headers - AppealsApi::FormSchemas.new( - SCHEMA_ERROR_TYPE, - schema_version: self.class::SCHEMA_VERSION - ).validate!("#{self.class::FORM_NUMBER}_HEADERS", request_headers) - end - - def validate_json_schema_for_body - AppealsApi::FormSchemas.new( - SCHEMA_ERROR_TYPE, - schema_version: self.class::SCHEMA_VERSION - ).validate!(self.class::FORM_NUMBER, @json_body) - end - def validate_json_schema_for_pdf_fit status, error = AppealsApi::HigherLevelReviews::PdfFormFieldV2Validator.new( @json_body, @@ -125,7 +103,7 @@ def validation_success end def request_headers - self.class::HEADERS.index_with { |key| request.headers[key] }.compact + header_names.index_with { |key| request.headers[key] }.compact end def new_higher_level_review diff --git a/modules/appeals_api/app/controllers/appeals_api/v2/decision_reviews/legacy_appeals_controller.rb b/modules/appeals_api/app/controllers/appeals_api/v2/decision_reviews/legacy_appeals_controller.rb index 287a5f2a27e..830bd2f881e 100644 --- a/modules/appeals_api/app/controllers/appeals_api/v2/decision_reviews/legacy_appeals_controller.rb +++ b/modules/appeals_api/app/controllers/appeals_api/v2/decision_reviews/legacy_appeals_controller.rb @@ -5,13 +5,13 @@ require 'appeals_api/form_schemas' class AppealsApi::V2::DecisionReviews::LegacyAppealsController < AppealsApi::ApplicationController - FORM_NUMBER = 'LEGACY_APPEALS_HEADERS' - HEADERS = JSON.parse( - File.read( - AppealsApi::Engine.root.join('config/schemas/v2/legacy_appeals_headers.json') - ) - )['definitions']['legacyAppealsIndexParameters']['properties'].keys - SCHEMA_ERROR_TYPE = Common::Exceptions::DetailedSchemaErrors + include AppealsApi::Schemas + + SCHEMA_OPTIONS = { + schema_version: 'v2', + api_name: 'decision_reviews', + headers_schema_name: 'legacy_appeals_headers' + }.freeze UNUSABLE_RESPONSE_ERROR = { errors: [ @@ -39,10 +39,12 @@ def index private + def header_names = headers_schema['definitions']['legacyAppealsIndexParameters']['properties'].keys + attr_reader :caseflow_response, :caseflow_exception_response def request_headers - self.class::HEADERS.index_with { |key| request.headers[key] }.compact + header_names.index_with { |key| request.headers[key] }.compact end def caseflow_request_headers @@ -50,14 +52,7 @@ def caseflow_request_headers end def validate_json_schema - validate_json_schema_for_headers - end - - def validate_json_schema_for_headers - AppealsApi::FormSchemas.new( - SCHEMA_ERROR_TYPE, - schema_version: 'v2' - ).validate!(self.class::FORM_NUMBER, request_headers) + validate_headers(request_headers) end def get_legacy_appeals_from_caseflow diff --git a/modules/appeals_api/app/controllers/appeals_api/v2/decision_reviews/notice_of_disagreements/evidence_submissions_controller.rb b/modules/appeals_api/app/controllers/appeals_api/v2/decision_reviews/notice_of_disagreements/evidence_submissions_controller.rb index 8914418de25..aa594a61fdf 100644 --- a/modules/appeals_api/app/controllers/appeals_api/v2/decision_reviews/notice_of_disagreements/evidence_submissions_controller.rb +++ b/modules/appeals_api/app/controllers/appeals_api/v2/decision_reviews/notice_of_disagreements/evidence_submissions_controller.rb @@ -7,14 +7,12 @@ class EvidenceSubmissionsController < AppealsApi::ApplicationController include AppealsApi::StatusSimulation include SentryLogging include AppealsApi::CharacterUtilities + include AppealsApi::Schemas - class EvidenceSubmissionRequestValidatorError < StandardError; end + SCHEMA_OPTIONS = { schema_version: 'v2', api_name: 'decision_reviews' }.freeze + FORM_NUMBER = AppealsApi::V2::DecisionReviews::NoticeOfDisagreementsController::FORM_NUMBER - HEADERS = JSON.parse( - File.read( - AppealsApi::Engine.root.join('config/schemas/v2/10182_headers.json') - ) - )['definitions']['nodCreateParameters']['properties'].keys + class EvidenceSubmissionRequestValidatorError < StandardError; end skip_before_action :authenticate before_action :nod_uuid_present?, only: :create @@ -53,6 +51,8 @@ def show private + def header_names = headers_schema['definitions']['nodCreateParameters']['properties'].keys + def nod_uuid_present? nod_uuid_missing_error if params[:nod_uuid].blank? end @@ -78,7 +78,7 @@ def submission_attributes end def request_headers - HEADERS.index_with { |key| request.headers[key] }.compact + header_names.index_with { |key| request.headers[key] }.compact end def log_error(error_detail) diff --git a/modules/appeals_api/app/controllers/appeals_api/v2/decision_reviews/notice_of_disagreements_controller.rb b/modules/appeals_api/app/controllers/appeals_api/v2/decision_reviews/notice_of_disagreements_controller.rb index 88ee61fd9c2..2be6cd1d0af 100644 --- a/modules/appeals_api/app/controllers/appeals_api/v2/decision_reviews/notice_of_disagreements_controller.rb +++ b/modules/appeals_api/app/controllers/appeals_api/v2/decision_reviews/notice_of_disagreements_controller.rb @@ -4,6 +4,7 @@ require 'appeals_api/form_schemas' class AppealsApi::V2::DecisionReviews::NoticeOfDisagreementsController < AppealsApi::ApplicationController + include AppealsApi::Schemas include AppealsApi::JsonFormatValidation include AppealsApi::StatusSimulation include AppealsApi::CharacterUtilities @@ -17,14 +18,8 @@ class AppealsApi::V2::DecisionReviews::NoticeOfDisagreementsController < Appeals FORM_NUMBER = '10182' API_VERSION = 'V2' - SCHEMA_VERSION = 'v2' MODEL_ERROR_STATUS = 422 - HEADERS = JSON.parse( - File.read( - AppealsApi::Engine.root.join('config/schemas/v2/10182_headers.json') - ) - )['definitions']['nodCreateParameters']['properties'].keys - SCHEMA_ERROR_TYPE = Common::Exceptions::DetailedSchemaErrors + SCHEMA_OPTIONS = { schema_version: 'v2', api_name: 'decision_reviews' }.freeze ALLOWED_COLUMNS = %i[id status code detail created_at updated_at].freeze ICN_HEADER = 'X-VA-ICN' ICN_REGEX = /^[0-9]{10}V[0-9]{6}$/ @@ -57,12 +52,7 @@ def validate def schema # TODO: Return full schema after we've validated all Non-Veteran Claimant functionality - response = AppealsApi::JsonSchemaToSwaggerConverter.remove_comments( - AppealsApi::FormSchemas.new( - SCHEMA_ERROR_TYPE, - schema_version: self.class::SCHEMA_VERSION - ).schema(self.class::FORM_NUMBER) - ) + response = AppealsApi::JsonSchemaToSwaggerConverter.remove_comments(form_schema) response.tap do |s| s.dig(*%w[definitions nodCreate properties data properties attributes properties]).delete('claimant') end @@ -72,6 +62,8 @@ def schema private + def header_names = headers_schema['definitions']['nodCreateParameters']['properties'].keys + def validate_index_headers validation_errors = [] @@ -85,24 +77,12 @@ def validate_index_headers end def validate_json_schema - validate_json_schema_for_headers - validate_json_schema_for_body - rescue SCHEMA_ERROR_TYPE => e + validate_headers(request_headers) + validate_form_data(@json_body) + rescue Common::Exceptions::DetailedSchemaErrors => e render json: { errors: e.errors }, status: :unprocessable_entity end - def validate_json_schema_for_headers - AppealsApi::FormSchemas.new( - SCHEMA_ERROR_TYPE, - schema_version: self.class::SCHEMA_VERSION - ).validate!("#{self.class::FORM_NUMBER}_HEADERS", request_headers) - end - - def validate_json_schema_for_body - schema = AppealsApi::FormSchemas.new(SCHEMA_ERROR_TYPE, schema_version: self.class::SCHEMA_VERSION) - schema.validate!(self.class::FORM_NUMBER, @json_body) - end - def validation_success { data: { @@ -115,7 +95,7 @@ def validation_success end def request_headers - self.class::HEADERS.index_with { |key| request.headers[key] }.compact + header_names.index_with { |key| request.headers[key] }.compact end def new_notice_of_disagreement diff --git a/modules/appeals_api/app/controllers/appeals_api/v2/decision_reviews/supplemental_claims/evidence_submissions_controller.rb b/modules/appeals_api/app/controllers/appeals_api/v2/decision_reviews/supplemental_claims/evidence_submissions_controller.rb index ffe9350de5a..577e2cded6a 100644 --- a/modules/appeals_api/app/controllers/appeals_api/v2/decision_reviews/supplemental_claims/evidence_submissions_controller.rb +++ b/modules/appeals_api/app/controllers/appeals_api/v2/decision_reviews/supplemental_claims/evidence_submissions_controller.rb @@ -7,14 +7,12 @@ class EvidenceSubmissionsController < AppealsApi::ApplicationController include AppealsApi::StatusSimulation include SentryLogging include AppealsApi::CharacterUtilities + include AppealsApi::Schemas class EvidenceSubmissionRequestValidatorError < StandardError; end - HEADERS = JSON.parse( - File.read( - AppealsApi::Engine.root.join('config/schemas/v2/200995_headers.json') - ) - )['definitions']['scCreateParameters']['properties'].keys + SCHEMA_OPTIONS = { schema_version: 'v2', api_name: 'decision_reviews' }.freeze + FORM_NUMBER = AppealsApi::V2::DecisionReviews::SupplementalClaimsController::FORM_NUMBER skip_before_action :authenticate before_action :supplemental_claim_uuid?, only: :create @@ -53,6 +51,8 @@ def show private + def header_names = headers_schema['definitions']['scCreateParameters']['properties'].keys + def supplemental_claim_uuid? uuid_missing_error unless params[:sc_uuid] end @@ -78,7 +78,7 @@ def submission_attributes end def request_headers - HEADERS.index_with { |key| request.headers[key] }.compact + header_names.index_with { |key| request.headers[key] }.compact end def log_error(error_detail) diff --git a/modules/appeals_api/app/controllers/appeals_api/v2/decision_reviews/supplemental_claims_controller.rb b/modules/appeals_api/app/controllers/appeals_api/v2/decision_reviews/supplemental_claims_controller.rb index f4cf67392cd..098d0096f2b 100644 --- a/modules/appeals_api/app/controllers/appeals_api/v2/decision_reviews/supplemental_claims_controller.rb +++ b/modules/appeals_api/app/controllers/appeals_api/v2/decision_reviews/supplemental_claims_controller.rb @@ -7,6 +7,7 @@ class AppealsApi::V2::DecisionReviews::SupplementalClaimsController < AppealsApi include AppealsApi::StatusSimulation include AppealsApi::CharacterUtilities include AppealsApi::MPIVeteran + include AppealsApi::Schemas skip_before_action :authenticate before_action :validate_index_headers, only: %i[index] @@ -15,14 +16,8 @@ class AppealsApi::V2::DecisionReviews::SupplementalClaimsController < AppealsApi FORM_NUMBER = '200995' API_VERSION = 'V2' - SCHEMA_VERSION = 'v2' MODEL_ERROR_STATUS = 422 - HEADERS = JSON.parse( - File.read( - AppealsApi::Engine.root.join('config/schemas/v2/200995_headers.json') - ) - )['definitions']['scCreateParameters']['properties'].keys - SCHEMA_ERROR_TYPE = Common::Exceptions::DetailedSchemaErrors + SCHEMA_OPTIONS = { schema_version: 'v2', api_name: 'decision_reviews' }.freeze ALLOWED_COLUMNS = %i[id status code detail created_at updated_at].freeze ICN_HEADER = 'X-VA-ICN' ICN_REGEX = /^[0-9]{10}V[0-9]{6}$/ @@ -60,12 +55,7 @@ def validate end def schema - response = AppealsApi::JsonSchemaToSwaggerConverter.remove_comments( - AppealsApi::FormSchemas.new( - SCHEMA_ERROR_TYPE, - schema_version: self.class::SCHEMA_VERSION - ).schema(self.class::FORM_NUMBER) - ) + response = AppealsApi::JsonSchemaToSwaggerConverter.remove_comments(form_schema) unless Flipper.enabled?(:decision_review_sc_pact_act_boolean) response.tap do |s| @@ -88,6 +78,8 @@ def show private + def header_names = headers_schema['definitions']['scCreateParameters']['properties'].keys + def validate_index_headers validation_errors = [] @@ -101,22 +93,8 @@ def validate_index_headers end def validate_json_schema - validate_json_schema_for_headers - validate_json_schema_for_body - end - - def validate_json_schema_for_headers - AppealsApi::FormSchemas.new( - SCHEMA_ERROR_TYPE, - schema_version: self.class::SCHEMA_VERSION - ).validate!("#{self.class::FORM_NUMBER}_HEADERS", request_headers) - end - - def validate_json_schema_for_body - AppealsApi::FormSchemas.new( - SCHEMA_ERROR_TYPE, - schema_version: self.class::SCHEMA_VERSION - ).validate!(self.class::FORM_NUMBER, @json_body) + validate_headers(request_headers) + validate_form_data(@json_body) end def validation_success @@ -131,7 +109,7 @@ def validation_success end def request_headers - self.class::HEADERS.index_with { |key| request.headers[key] }.compact + header_names.index_with { |key| request.headers[key] }.compact end def render_model_errors(model) diff --git a/modules/appeals_api/app/controllers/concerns/appeals_api/schemas.rb b/modules/appeals_api/app/controllers/concerns/appeals_api/schemas.rb new file mode 100644 index 00000000000..a2b3c2cd67d --- /dev/null +++ b/modules/appeals_api/app/controllers/concerns/appeals_api/schemas.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +module AppealsApi::Schemas + extend ActiveSupport::Concern + + def headers_schema = form_schemas.schema(headers_schema_name.upcase) + def form_schema = form_schemas.schema(form_number) + + def validate_headers(headers_hash) = form_schemas.validate!(headers_schema_name.upcase, headers_hash) + def validate_form_data(data_hash) = form_schemas.validate!(form_number, data_hash) + + private + + def schema_options + return self.class::SCHEMA_OPTIONS if defined? self.class::SCHEMA_OPTIONS + + raise "Expected SCHEMA_OPTIONS to be defined in #{self.class.name}" + end + + def api_name = schema_options.fetch(:api_name) + def schema_version = schema_options.fetch(:schema_version) + def error_type = schema_options.fetch(:error_type, Common::Exceptions::DetailedSchemaErrors) + + def form_number + self.class::FORM_NUMBER if defined? self.class::FORM_NUMBER + end + + def form_schemas = @form_schemas ||= AppealsApi::FormSchemas.new(error_type, schema_version:, api_name:) + + def headers_schema_name + schema_options.fetch(:headers_schema_name, form_number ? "#{form_number}_HEADERS" : 'HEADERS') + end +end diff --git a/modules/appeals_api/app/swagger/appeals_api/v1/nod_json_schema_swagger_helper.rb b/modules/appeals_api/app/swagger/appeals_api/v1/nod_json_schema_swagger_helper.rb index fd8437b6121..9c2d6ac9ea5 100644 --- a/modules/appeals_api/app/swagger/appeals_api/v1/nod_json_schema_swagger_helper.rb +++ b/modules/appeals_api/app/swagger/appeals_api/v1/nod_json_schema_swagger_helper.rb @@ -53,11 +53,11 @@ def read_json_from_same_dir(filename) end def headers_json_schema - @headers_json_schema ||= read_json(['config', 'schemas', 'v1', '10182_headers.json']) + @headers_json_schema ||= read_json(['config', 'schemas', 'decision_reviews', 'v1', '10182_headers.json']) end def nod_create_json_schema - @nod_create_json_schema ||= read_json(['config', 'schemas', 'v1', '10182.json']) + @nod_create_json_schema ||= read_json(['config', 'schemas', 'decision_reviews', 'v1', '10182.json']) end def example_min_fields_used diff --git a/modules/appeals_api/app/swagger/appeals_api/v1/schemas/notice_of_disagreements.rb b/modules/appeals_api/app/swagger/appeals_api/v1/schemas/notice_of_disagreements.rb index dfa9a478418..3988cbdd19f 100644 --- a/modules/appeals_api/app/swagger/appeals_api/v1/schemas/notice_of_disagreements.rb +++ b/modules/appeals_api/app/swagger/appeals_api/v1/schemas/notice_of_disagreements.rb @@ -8,7 +8,9 @@ class NoticeOfDisagreements def self.nod_json_schemas read_file = ->(path) { File.read(AppealsApi::Engine.root.join(*path)) } - read_json_schema = ->(filename) { JSON.parse read_file[['config', 'schemas', 'v1', filename]] } + read_json_schema = lambda do |filename| + JSON.parse read_file[['config', 'schemas', 'decision_reviews', 'v1', filename]] + end nod_create_schemas = AppealsApi::JsonSchemaToSwaggerConverter.new( read_json_schema['10182.json'] diff --git a/modules/appeals_api/config/schemas/v0/appealable_issues_headers.json b/modules/appeals_api/config/schemas/appealable_issues/v0/headers.json similarity index 100% rename from modules/appeals_api/config/schemas/v0/appealable_issues_headers.json rename to modules/appeals_api/config/schemas/appealable_issues/v0/headers.json diff --git a/modules/appeals_api/config/schemas/v1/10182.json b/modules/appeals_api/config/schemas/decision_reviews/v1/10182.json similarity index 100% rename from modules/appeals_api/config/schemas/v1/10182.json rename to modules/appeals_api/config/schemas/decision_reviews/v1/10182.json diff --git a/modules/appeals_api/config/schemas/v1/10182_headers.json b/modules/appeals_api/config/schemas/decision_reviews/v1/10182_headers.json similarity index 100% rename from modules/appeals_api/config/schemas/v1/10182_headers.json rename to modules/appeals_api/config/schemas/decision_reviews/v1/10182_headers.json diff --git a/modules/appeals_api/config/schemas/v2/10182.json b/modules/appeals_api/config/schemas/decision_reviews/v2/10182.json similarity index 100% rename from modules/appeals_api/config/schemas/v2/10182.json rename to modules/appeals_api/config/schemas/decision_reviews/v2/10182.json diff --git a/modules/appeals_api/config/schemas/v2/10182_headers.json b/modules/appeals_api/config/schemas/decision_reviews/v2/10182_headers.json similarity index 100% rename from modules/appeals_api/config/schemas/v2/10182_headers.json rename to modules/appeals_api/config/schemas/decision_reviews/v2/10182_headers.json diff --git a/modules/appeals_api/config/schemas/v2/200995.json b/modules/appeals_api/config/schemas/decision_reviews/v2/200995.json similarity index 100% rename from modules/appeals_api/config/schemas/v2/200995.json rename to modules/appeals_api/config/schemas/decision_reviews/v2/200995.json diff --git a/modules/appeals_api/config/schemas/v2/200995_headers.json b/modules/appeals_api/config/schemas/decision_reviews/v2/200995_headers.json similarity index 100% rename from modules/appeals_api/config/schemas/v2/200995_headers.json rename to modules/appeals_api/config/schemas/decision_reviews/v2/200995_headers.json diff --git a/modules/appeals_api/config/schemas/v2/200996.json b/modules/appeals_api/config/schemas/decision_reviews/v2/200996.json similarity index 100% rename from modules/appeals_api/config/schemas/v2/200996.json rename to modules/appeals_api/config/schemas/decision_reviews/v2/200996.json diff --git a/modules/appeals_api/config/schemas/v2/200996_headers.json b/modules/appeals_api/config/schemas/decision_reviews/v2/200996_headers.json similarity index 100% rename from modules/appeals_api/config/schemas/v2/200996_headers.json rename to modules/appeals_api/config/schemas/decision_reviews/v2/200996_headers.json diff --git a/modules/appeals_api/config/schemas/v2/contestable_issues_headers.json b/modules/appeals_api/config/schemas/decision_reviews/v2/contestable_issues_headers.json similarity index 100% rename from modules/appeals_api/config/schemas/v2/contestable_issues_headers.json rename to modules/appeals_api/config/schemas/decision_reviews/v2/contestable_issues_headers.json diff --git a/modules/appeals_api/config/schemas/v2/legacy_appeals_headers.json b/modules/appeals_api/config/schemas/decision_reviews/v2/legacy_appeals_headers.json similarity index 100% rename from modules/appeals_api/config/schemas/v2/legacy_appeals_headers.json rename to modules/appeals_api/config/schemas/decision_reviews/v2/legacy_appeals_headers.json diff --git a/modules/appeals_api/config/schemas/v2/200996_with_shared_refs.json b/modules/appeals_api/config/schemas/higher_level_reviews/v0/200996.json similarity index 100% rename from modules/appeals_api/config/schemas/v2/200996_with_shared_refs.json rename to modules/appeals_api/config/schemas/higher_level_reviews/v0/200996.json diff --git a/modules/appeals_api/config/schemas/v2/200996_with_shared_refs_headers.json b/modules/appeals_api/config/schemas/higher_level_reviews/v0/200996_headers.json similarity index 100% rename from modules/appeals_api/config/schemas/v2/200996_with_shared_refs_headers.json rename to modules/appeals_api/config/schemas/higher_level_reviews/v0/200996_headers.json diff --git a/modules/appeals_api/config/schemas/v2/legacy_appeals_headers_with_shared_refs.json b/modules/appeals_api/config/schemas/legacy_appeals/v0/headers.json similarity index 100% rename from modules/appeals_api/config/schemas/v2/legacy_appeals_headers_with_shared_refs.json rename to modules/appeals_api/config/schemas/legacy_appeals/v0/headers.json diff --git a/modules/appeals_api/config/schemas/v2/10182_with_shared_refs.json b/modules/appeals_api/config/schemas/notice_of_disagreements/v0/10182.json similarity index 100% rename from modules/appeals_api/config/schemas/v2/10182_with_shared_refs.json rename to modules/appeals_api/config/schemas/notice_of_disagreements/v0/10182.json diff --git a/modules/appeals_api/config/schemas/v2/10182_with_shared_refs_headers.json b/modules/appeals_api/config/schemas/notice_of_disagreements/v0/10182_headers.json similarity index 100% rename from modules/appeals_api/config/schemas/v2/10182_with_shared_refs_headers.json rename to modules/appeals_api/config/schemas/notice_of_disagreements/v0/10182_headers.json diff --git a/modules/appeals_api/config/schemas/shared/v1/address.json b/modules/appeals_api/config/schemas/shared/v0/address.json similarity index 100% rename from modules/appeals_api/config/schemas/shared/v1/address.json rename to modules/appeals_api/config/schemas/shared/v0/address.json diff --git a/modules/appeals_api/config/schemas/shared/v1/non_blank_string.json b/modules/appeals_api/config/schemas/shared/v0/non_blank_string.json similarity index 100% rename from modules/appeals_api/config/schemas/shared/v1/non_blank_string.json rename to modules/appeals_api/config/schemas/shared/v0/non_blank_string.json diff --git a/modules/appeals_api/config/schemas/shared/v1/phone.json b/modules/appeals_api/config/schemas/shared/v0/phone.json similarity index 100% rename from modules/appeals_api/config/schemas/shared/v1/phone.json rename to modules/appeals_api/config/schemas/shared/v0/phone.json diff --git a/modules/appeals_api/config/schemas/shared/v1/timezone.json b/modules/appeals_api/config/schemas/shared/v0/timezone.json similarity index 100% rename from modules/appeals_api/config/schemas/shared/v1/timezone.json rename to modules/appeals_api/config/schemas/shared/v0/timezone.json diff --git a/modules/appeals_api/config/schemas/v2/200995_with_shared_refs.json b/modules/appeals_api/config/schemas/supplemental_claims/v0/200995.json similarity index 100% rename from modules/appeals_api/config/schemas/v2/200995_with_shared_refs.json rename to modules/appeals_api/config/schemas/supplemental_claims/v0/200995.json diff --git a/modules/appeals_api/config/schemas/v2/200995_with_shared_refs_headers.json b/modules/appeals_api/config/schemas/supplemental_claims/v0/200995_headers.json similarity index 100% rename from modules/appeals_api/config/schemas/v2/200995_with_shared_refs_headers.json rename to modules/appeals_api/config/schemas/supplemental_claims/v0/200995_headers.json diff --git a/modules/appeals_api/lib/appeals_api/form_schemas.rb b/modules/appeals_api/lib/appeals_api/form_schemas.rb index 876668fee65..45ce72330c9 100644 --- a/modules/appeals_api/lib/appeals_api/form_schemas.rb +++ b/modules/appeals_api/lib/appeals_api/form_schemas.rb @@ -4,19 +4,20 @@ module AppealsApi class FormSchemas < JsonSchema::FormSchemas - def initialize(error_type = JsonSchema::JsonApiMissingAttribute, schema_version: 'v1') + def initialize(error_type = JsonSchema::JsonApiMissingAttribute, api_name: 'decision_reviews', schema_version: 'v1') + @api_name = api_name @error_type = error_type @schema_version = schema_version end - attr_accessor :schema_version + attr_accessor :schema_version, :api_name def base_dir - Rails.root.join('modules', 'appeals_api', Settings.modules_appeals_api.schema_dir, schema_version) + Rails.root.join('modules', 'appeals_api', Settings.modules_appeals_api.schema_dir, api_name, schema_version) end def shared_dir(file) - Rails.root.join('modules', 'appeals_api', Settings.modules_appeals_api.schema_dir, 'shared', 'v1', file) + Rails.root.join('modules', 'appeals_api', Settings.modules_appeals_api.schema_dir, 'shared', schema_version, file) end def validate!(form, payload) diff --git a/modules/appeals_api/spec/config/schemas/v2/200996_v2_json_spec.rb b/modules/appeals_api/spec/config/schemas/v2/200996_v2_json_spec.rb index 1ec357f5462..870bd5be693 100644 --- a/modules/appeals_api/spec/config/schemas/v2/200996_v2_json_spec.rb +++ b/modules/appeals_api/spec/config/schemas/v2/200996_v2_json_spec.rb @@ -7,7 +7,7 @@ include SchemaHelpers include FixtureHelpers - let(:json_schema) { read_schema '200996.json', 'v2' } + let(:json_schema) { read_schema '200996.json', 'decision_reviews', 'v2' } let(:errors) { validator.validate(json).to_a } let(:errors_minimal) { validator.validate(json_minimal).to_a } diff --git a/modules/appeals_api/spec/services/appeals_api/pdf_construction/generator_spec.rb b/modules/appeals_api/spec/services/appeals_api/pdf_construction/generator_spec.rb index 525f51f63dd..76559977452 100644 --- a/modules/appeals_api/spec/services/appeals_api/pdf_construction/generator_spec.rb +++ b/modules/appeals_api/spec/services/appeals_api/pdf_construction/generator_spec.rb @@ -80,7 +80,7 @@ let(:fixture_name) { 'expected_10182_maxlength.pdf' } let(:nod) do build(:extra_notice_of_disagreement_v2, created_at: '2021-02-03T14:15:16Z') do |appeal| - appeal.form_data = override_max_lengths(appeal, read_schema('10182.json', 'v2')) + appeal.form_data = override_max_lengths(appeal, read_schema('10182.json', 'decision_reviews', 'v2')) appeal.auth_headers.merge!( { 'X-VA-SSN' => 'W' * 9, @@ -158,7 +158,7 @@ end create(:extra_higher_level_review_v2, created_at:) do |appeal| - appeal.form_data = override_max_lengths(appeal, read_schema('200996.json', 'v2')) + appeal.form_data = override_max_lengths(appeal, read_schema('200996.json', 'decision_reviews', 'v2')) # TODO: update countryCodeISO2 in expected_200996_maxlength.pdf with expected override_max_lengths values appeal.form_data['data']['attributes']['veteran']['address']['countryCodeISO2'] = 'US' appeal.form_data['data']['attributes']['claimant']['address']['countryCodeISO2'] = 'US' @@ -308,7 +308,7 @@ end create(:extra_supplemental_claim, created_at:) do |appeal| - appeal.form_data = override_max_lengths(appeal, read_schema('200995.json', 'v2')) + appeal.form_data = override_max_lengths(appeal, read_schema('200995.json', 'decision_reviews', 'v2')) appeal.auth_headers.merge!( 'X-VA-First-Name' => 'W' * 30, 'X-VA-Last-Name' => 'W' * 40, diff --git a/modules/appeals_api/spec/support/rswag_config.rb b/modules/appeals_api/spec/support/rswag_config.rb index 681289027a2..5a640f1f325 100644 --- a/modules/appeals_api/spec/support/rswag_config.rb +++ b/modules/appeals_api/spec/support/rswag_config.rb @@ -444,10 +444,10 @@ def contestable_issues_schema } end - def decision_reviews_hlr_create_schemas = parse_create_schema 'v2', '200996.json' + def decision_reviews_hlr_create_schemas = parse_create_schema('decision_reviews', 'v2', '200996.json') def hlr_create_schemas - hlr_schema = parse_create_schema('v2', '200996_with_shared_refs.json', return_raw: true) + hlr_schema = parse_create_schema('higher_level_reviews', 'v0', '200996.json', return_raw: true) { hlrCreate: { type: 'object' }.merge!(hlr_schema.slice(*%w[description properties required])) } @@ -641,10 +641,10 @@ def hlr_response_schemas } end - def decision_reviews_nod_create_schemas = parse_create_schema 'v2', '10182.json' + def decision_reviews_nod_create_schemas = parse_create_schema('decision_reviews', 'v2', '10182.json') def nod_create_schemas - nod_schema = parse_create_schema('v2', '10182_with_shared_refs.json', return_raw: true) + nod_schema = parse_create_schema('notice_of_disagreements', 'v0', '10182.json', return_raw: true) { nodCreate: { type: 'object' }.merge!(nod_schema.slice(*%w[description properties required])) } @@ -817,7 +817,7 @@ def decision_reviews_nod_response_schemas def nod_response_schemas = decision_reviews_nod_response_schemas def decision_reviews_sc_create_schemas - sc_schema = parse_create_schema 'v2', '200995.json' + sc_schema = parse_create_schema('decision_reviews', 'v2', '200995.json') return sc_schema if wip_doc_enabled?(:sc_v2_potential_pact_act) # Removes 'potentialPactAct' from schema for production docs @@ -827,7 +827,7 @@ def decision_reviews_sc_create_schemas end def sc_create_schemas - sc_schema = parse_create_schema('v2', '200995_with_shared_refs.json', return_raw: true) + sc_schema = parse_create_schema('supplemental_claims', 'v0', '200995.json', return_raw: true) # Removes 'potentialPactAct' from schema for production docs unless wip_doc_enabled?(:sc_v2_potential_pact_act) @@ -1132,15 +1132,15 @@ def appeals_status_response_schemas def shared_schemas(nbs_key: 'non_blank_string') # Keys are strings to override older, non-shared-schema definitions { - 'address' => JSON.parse(File.read(AppealsApi::Engine.root.join('config', 'schemas', 'shared', 'v1', 'address.json')))['properties']['address'], - nbs_key => JSON.parse(File.read(AppealsApi::Engine.root.join('config', 'schemas', 'shared', 'v1', 'non_blank_string.json')))['properties']['nonBlankString'], - 'phone' => JSON.parse(File.read(AppealsApi::Engine.root.join('config', 'schemas', 'shared', 'v1', 'phone.json')))['properties']['phone'], - 'timezone' => JSON.parse(File.read(AppealsApi::Engine.root.join('config', 'schemas', 'shared', 'v1', 'timezone.json')))['properties']['timezone'] + 'address' => JSON.parse(File.read(AppealsApi::Engine.root.join('config', 'schemas', 'shared', 'v0', 'address.json')))['properties']['address'], + nbs_key => JSON.parse(File.read(AppealsApi::Engine.root.join('config', 'schemas', 'shared', 'v0', 'non_blank_string.json')))['properties']['nonBlankString'], + 'phone' => JSON.parse(File.read(AppealsApi::Engine.root.join('config', 'schemas', 'shared', 'v0', 'phone.json')))['properties']['phone'], + 'timezone' => JSON.parse(File.read(AppealsApi::Engine.root.join('config', 'schemas', 'shared', 'v0', 'timezone.json')))['properties']['timezone'] } end - def parse_create_schema(version, schema_file, return_raw: false) - file = File.read(AppealsApi::Engine.root.join('config', 'schemas', version, schema_file)) + def parse_create_schema(api_name, api_version, schema_file, return_raw: false) + file = File.read(AppealsApi::Engine.root.join('config', 'schemas', api_name, api_version, schema_file)) file.gsub! '#/definitions/', '#/components/schemas/' schema = JSON.parse file diff --git a/modules/appeals_api/spec/support/schema_helpers.rb b/modules/appeals_api/spec/support/schema_helpers.rb index 5ad06db8001..5dde68dd1ad 100644 --- a/modules/appeals_api/spec/support/schema_helpers.rb +++ b/modules/appeals_api/spec/support/schema_helpers.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module SchemaHelpers - def read_schema(filename, schema_version = 'v1') + def read_schema(filename, api_name = 'decision_reviews', schema_version = 'v1') JSON.parse( File.read( Rails.root.join( @@ -9,6 +9,7 @@ def read_schema(filename, schema_version = 'v1') 'appeals_api', 'config', 'schemas', + api_name, schema_version, filename )