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": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://example.com/product.schema.json",
"title": "Form",
"description": "A form",
"type": "object",
"properties": {
"form_type": {
"description": "",
"type": "string"
},
"start_year": {
"description": "",
"type": "int"
},
"end_year": {
"description": "",
"type": "int"
},
"sections": {
"description": "",
"type": "object",
"properties": {
"page_name": {
"description": "",
"type": "string"
},
schema = {
"$schema": "https://json-schema.org/draft-04/schema#",
"$id": "https://example.com/product.schema.json",
"title": "Form",
"description": "A form",
"type": "object",
"properties": {
"form_type": {
"description": "",
"type": "string"
},
"start_year": {
"description": "",
"type": "int"
},
"end_year": {
"description": "",
"type": "int"
},
"sections": {
"description": "",
"type": "object",
"properties": {
"page_name": {
"description": "",
"type": "string"
},
}
}
}
}
}
begin
# file = File.open("config/forms/2021_2022.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)
puts "Success"

Loading…
Cancel
Save