Browse Source

can't find jsonspec

pull/76/head
magicmilo 3 years ago
parent
commit
6c272dad87
  1. 63
      app/helpers/json_schema_validation.rb

63
app/helpers/json_schema_validation.rb

@ -23,44 +23,45 @@ require "json"
# } # }
# } # }
# }, # },
begin
schema = { schema = {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft-04/schema#",
"$id": "https://example.com/product.schema.json", "$id": "https://example.com/product.schema.json",
"title": "Form", "title": "Form",
"description": "A form", "description": "A form",
"type": "object", "type": "object",
"properties": { "properties": {
"form_type": { "form_type": {
"description": "", "description": "",
"type": "string" "type": "string"
}, },
"start_year": { "start_year": {
"description": "", "description": "",
"type": "int" "type": "int"
}, },
"end_year": { "end_year": {
"description": "", "description": "",
"type": "int" "type": "int"
}, },
"sections": { "sections": {
"description": "", "description": "",
"type": "object", "type": "object",
"properties": { "properties": {
"page_name": { "page_name": {
"description": "", "description": "",
"type": "string" "type": "string"
}, },
}
} }
} }
} }
}
begin
# file = File.open("config/forms/2021_2022.json") # file = File.open("config/forms/2021_2022.json")
file = File.open("spec/fixtures/forms/test_validator.json") file = File.open("spec/fixtures/forms/test_validator.json")
data = JSON.parse(file.read) puts data = JSON.parse(file.read)
puts JSON::Validator.validate(schema, data)
if JSON::Validator.validate!(schema, data) if JSON::Validator.validate!(schema, data)
puts "Success" puts "Success"

Loading…
Cancel
Save