Skip to content

Commit

Permalink
validate exam key format, add key validator to section
Browse files Browse the repository at this point in the history
  • Loading branch information
patodevilla committed Mar 7, 2024
1 parent 2fc0c14 commit 13664c5
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ GIT
PATH
remote: .
specs:
json_schema_form (0.15.21)
json_schema_form (0.15.22)
activesupport (~> 6)
dry-schema (~> 1.13)
json_schemer (= 2.1.1)
Expand Down
2 changes: 1 addition & 1 deletion lib/jsf/forms/fixtures/form.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$id": "http://example.com/example.json",
// "$id": "http://example.com/example.json",
// "$schema": "https://json-schema.org/draft/2020-12/schema",
"allOf": [],
"availableLocales": [],
Expand Down
1 change: 1 addition & 0 deletions lib/jsf/forms/fixtures/response.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"const": "no_score_1",
"displayProperties": {
// "color": null,
"i18n": {
"en": "no_score_1_en",
"es": "no_score_1_es"
Expand Down
2 changes: 1 addition & 1 deletion lib/jsf/forms/fixtures/response/failing.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"const": "score_1",
"displayProperties": {
"color": null,
// "color": null,
"i18n": {
"en": "score_1_en",
"es": "score_1_es"
Expand Down
2 changes: 1 addition & 1 deletion lib/jsf/forms/fixtures/response/scoring.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"const": "score_1",
"displayProperties": {
"color": null,
// "color": null,
"i18n": {
"en": "score_1_en",
"es": "score_1_es"
Expand Down
2 changes: 1 addition & 1 deletion lib/jsf/forms/fixtures/response/scoring_and_failing.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"const": "score_1",
"displayProperties": {
"color": null,
// "color": null,
"i18n": {
"en": "score_1_en",
"es": "score_1_es"
Expand Down
2 changes: 1 addition & 1 deletion lib/jsf/forms/form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def dry_schema(passthru)
required(:hasScoring) { bool? }
end
if exam
required(:$id).value(:str?)
required(:$id).filled{ str? & format?(/^((?!#).)*$/) } # does not contain '#'
required(:displayProperties).hash do
required(:component).value(eql?: 'exam')
required(:passingGrade).filled(:integer, gt?: 0, lteq?: 100)
Expand Down
8 changes: 2 additions & 6 deletions lib/jsf/forms/section.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def dry_schema(passthru)
hide_on_create = run_validation?(passthru, :hideOnCreate, optional: true)

Dry::Schema.JSON do
config.validate_keys = true

before(:key_validator) do |result| # result.to_h (shallow dup)
result.to_h.tap do |h|
Expand Down Expand Up @@ -70,12 +71,7 @@ def dry_schema(passthru)
end
optional(:maxItems).filled(:integer)
optional(:minItems).filled(:integer)
required(:items).hash do
# optional(:properties)
# optional(:allOf)
# optional(:required)
# required(:type).value(eql?: 'object')
end
required(:items).hash
required(:type)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/jsf/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module JSF
VERSION = "0.15.21"
VERSION = "0.15.22"
end

0 comments on commit 13664c5

Please sign in to comment.