Skip to content

Commit

Permalink
API-26837 Reorganize appeals schemas (#12835)
Browse files Browse the repository at this point in the history
* Reorganize appeals schemas

Reorganizes the schemas for forms and headers in the Decision Reviews
API and the segmented appeals APIs in a way that makes it clearer which
schemas belong to which API

* Remove SCHEMA_VERSION constant in appeals API controllers

* Minimize FORM_NUMBER constant in appeals API controllers

Adjusts the use of `FORM_NUMBER` so that it only refers to numbers of
forms (e.g. 200995, 200996, etc.), not names of general schemas

* Move schema updates into a dedicated concern
  • Loading branch information
caseywilliams authored Jun 7, 2023
1 parent 1f79f62 commit 83ea402
Show file tree
Hide file tree
Showing 45 changed files with 163 additions and 256 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -32,24 +29,24 @@ 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
@schema_type ||= params[: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
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,17 @@ 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? }
before_action :validate_json_schema, only: %i[create validate]
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
Expand Down Expand Up @@ -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: {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand All @@ -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)
Expand Down Expand Up @@ -157,25 +160,18 @@ 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
request_headers.except('X-VA-ICN')
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',
Expand Down
Loading

0 comments on commit 83ea402

Please sign in to comment.