-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ACD-573: Add schema and sample for the new application detail endpoint
Add new service to validate the response from the CP endpoint (for now court_application_details/all_fields.json) against the schema.
- Loading branch information
Showing
7 changed files
with
673 additions
and
1 deletion.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
app/controllers/api/internal/v2/court_applications_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
module Api | ||
module Internal | ||
module V2 | ||
class CourtApplicationsController < ApplicationController | ||
def show | ||
# TODO: this will be the new application details endpoint | ||
raise NotImplementedError | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require "json-schema" | ||
require "uri" | ||
|
||
class SchemaValidator < ApplicationService | ||
def initialize(schema:, json_response:) | ||
@schema = schema | ||
@json_response = json_response | ||
|
||
load_schema_references | ||
end | ||
|
||
def call | ||
JSON::Validator.validate!(@schema, @json_response) | ||
rescue JSON::Schema::ValidationError => e | ||
Rails.logger.error("JSON Schema Validation Error: #{e.message}") | ||
false | ||
end | ||
|
||
private | ||
|
||
def load_schema_references | ||
refs = [{ | ||
filename: "lib/schemas/global/apiCourtsDefinitions.json", | ||
url: "http://justice.gov.uk/core/courts/external/apiCourtsDefinitions.json", | ||
}, | ||
{ | ||
filename: "lib/schemas/global/apiJudicialResult.json", | ||
url: "http://justice.gov.uk/core/courts/external/apiJudicialResult.json", | ||
}, | ||
{ | ||
filename: "lib/schemas/global/apiDelegatedPowers.json", | ||
url: "http://justice.gov.uk/core/courts/external/apiDelegatedPowers.json", | ||
}] | ||
|
||
refs.each do |ref| | ||
json_schema = JSON::Schema.new( | ||
JSON.parse(File.open(Rails.root.join(ref[:filename]).to_s).read), | ||
Addressable::URI.parse(ref[:url]), | ||
) | ||
JSON::Validator.add_schema(json_schema) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.