Browse Source

added rake form_definition (can't load json-schema)

pull/76/head
magicmilo 3 years ago
parent
commit
fa86626d37
  1. 3
      README.md
  2. 5
      app/helpers/json_schema_validation.rb
  3. 6
      lib/tasks/form_definition.rake

3
README.md

@ -163,6 +163,9 @@ Assumptions made by the format:
## JSON Form Validation against Schema ## JSON Form Validation against Schema
To validate the form JSON against the schema you can run: To validate the form JSON against the schema you can run:
`rake form_definition:validate`
This will run:
`ruby app/helpers/json_schema_validation.rb` `ruby app/helpers/json_schema_validation.rb`
This will validate all forms in: This will validate all forms in:

5
app/helpers/json_schema_validation.rb

@ -1,5 +1,5 @@
require "json-schema"
require "json" require "json"
require "json-schema"
def get_all_form_paths(directories) def get_all_form_paths(directories)
form_paths = [] form_paths = []
@ -12,7 +12,6 @@ def get_all_form_paths(directories)
end end
begin begin
path = "config/forms/schema/generic.json" path = "config/forms/schema/generic.json"
file = File.open(path) file = File.open(path)
@ -36,8 +35,6 @@ begin
file = File.open(path) file = File.open(path)
data = JSON.parse(file.read) data = JSON.parse(file.read)
puts JSON::Validator.validate(schema, data, :strict => true)
puts JSON::Validator.fully_validate(schema, data, :strict => true) puts JSON::Validator.fully_validate(schema, data, :strict => true)
begin begin

6
lib/tasks/form_definition.rake

@ -0,0 +1,6 @@
namespace :form_definition do
desc "Validate JSON against Generic Form Schema"
task :validate do
ruby "app/helpers/json_schema_validation.rb"
end
end
Loading…
Cancel
Save