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

Validate against a schema fragment. #56

Closed
arnaudbriche opened this issue Jun 5, 2013 · 3 comments
Closed

Validate against a schema fragment. #56

arnaudbriche opened this issue Jun 5, 2013 · 3 comments
Labels

Comments

@arnaudbriche
Copy link

I'm new to json-schema so it might not be a relevant issue.
I have one big json file describing a lot of schemas (mostly small ones) with a lot $ref between schemas, and I need to be able to validate data against one of these "inner" schemas. I can't find a way to do this with json-schema.
Does json-schema support this use case, or am I doing it wrong ?

@hoxworth
Copy link
Contributor

This library does not currently provide functionality to validate against a specific fragment of an existing schema; however, I really like that idea and will add it as a future feature. More than likely, the validate commands will accept a :fragment option or such with a valid JSON pointer (http://tools.ietf.org/html/draft-pbryan-zyp-json-pointer-02) as a value.

I'll take a look into adding this functionality this week.

@hoxworth
Copy link
Contributor

hoxworth commented Jul 3, 2013

I just added this functionality in version 2.1.0.

To use, pass a :fragment option along with your validation.

  require 'rubygems'
  require 'json-schema'

  schema = {
    "type" => "object",
    "required" => ["a","b"],
    "properties" => {
      "a" => {"type" => "integer"},
      "b" => {"type" => "string"},
      "c" => {
        "type" => "object",
        "properties" => {
          "z" => {"type" => "integer"}
        }
      }
    }
  }

  data = {
    "z" => 1
  }

  JSON::Validator.validate(schema, data, :fragment => "#/properties/c")

@hoxworth hoxworth closed this as completed Jul 3, 2013
@arnaudbriche
Copy link
Author

Works great ! Thx Hoxworth.

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

No branches or pull requests

2 participants