Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not work with the following example #9

Closed
tannakartikey opened this issue Aug 20, 2018 · 1 comment
Closed

Does not work with the following example #9

tannakartikey opened this issue Aug 20, 2018 · 1 comment

Comments

@tannakartikey
Copy link

My schema definition is defined as the following:

  SCHEMA = {
    "type": "object",
    "required": [
      "type_of_formative_quiz",
      "email_notification",
      "email_notification_tutorial_taken",
      "email_notification_quiz_completed",
      "email_notification_question_missed",
    ],
    "properties": {
      "type_of_formative_quiz": {
        "type": "string",
        "enum": ["practice", "graded"],
      },
      'formative_quiz_passing_score': {
        "type": "number",
        "minimum": 0,
        "maximum": 100,
      },
      'will_have_summative_quiz': {
        "type": "boolean",
      },
      'completion_required_for_summative_quiz': {
        "type": "boolean",
      },
      'summative_quiz_passing_score': {
        "type": "number",
        "minimum": 0,
        "maximum": 100,
      },
      'email_notification': {
        "type": "boolean",
      },
      'email_notification_tutorial_taken': {
        "type": "boolean",
      },
      'email_notification_quiz_completed': {
        "type": "boolean",
      },
      'email_notification_question_missed': {
        "type": "boolean",
      },
      'missed_question_threshold_type': {
        "type": "string",
        "enum": ["percentage", "people"],
      },
      'missed_question_threshold': {
        "type": "number",
        "minimum": 0,
        "maximum": 100,
      },
    },
    "dependencies": {
      "will_have_summative_quiz": {
        "required": [
          "completion_required_for_summative_quiz",
          "summative_quiz_passing_score"
        ],
      },
    },
  }

I am doing the following:

schemer = JSONSchemer.schema(SCHEMA)
pp schemer.validate({'abc': 'def'}).to_a

The output is blank array.
=> []

It should thorw the errors as required keys are missing. It works fine as described in the example on README. What am I doing wrong?

@davishmcclurg
Copy link
Owner

The keys in your schema (and data) are symbols, which won't work currently.

> {'abc': 'def'}
=> {:abc=>"def"}

You should get the error you expect if you switch to string keys.

I'm going to leave this issue open because it's an easy mistake to make and there should at least be an error when passing schemas with symbol keys.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants