Giter VIP home page Giter VIP logo

json_schema_tools's People

Contributors

a2800276 avatar agalloch avatar schorsch avatar vidurmalik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

json_schema_tools's Issues

Inquiry, schema version 2

Does this work on things formatted in
http //json-schema.org/draft-02/schema#

as opposed to
http //json-schema.org/draft-04/schema#

I'm having a little trouble implementing, just wondering if i'm wasting my time / if its not compatible with draft-02 of the schema. Thanks!

Error on Key / Method naming clash

Issue

Defining a method on a model that has the same name as a key that has been passed causes an error.

Steps to reproduce

  1. Create a json schema model.
  2. Define a method on the model called foo
  3. Pass a key with the same name (foo) and any value.
  4. Use from_hash to create an instance of the model
  5. See a no method for nil class error at this line
class Bar
  include SchemaTools::Modules::Attributes
  include SchemaTools::Modules::Validations
  include SchemaTools::Modules::AsSchema
  has_schema_attrs 'bar'
  validate_with 'bar'

  def foo
    # do something
  end
end

Bar.from_hash({ 'foo' => 'test value' })

Handle nil values

@VidurMalik added a change for nested objects, which are not present in the output json when nil:
#19

Still need to handle the other field types: plain properties & nested arrays.

A reasonable approach could be to add the following options:

  • ignore_null: true => which would leave out all nil values from the output json
  • strict: true => the parser throws an error when an schema property does not exists on the object e.g obj.respond_to?(field) Such could be needed to find out why a key is missing in the json: does it exists or is it nil?

$ref not honoring absolute or relative paths (for files)

Example:

Directory Structure

  SCHEMA_PATH/v1/child.json
  SCHEMA_PATH/v2/child.json
  SCHEMA_PATH/v2/parent.json

If parent.json references v2/child.json, the current implementation of RefResolver::find_local_file_path will return v1/child.json instead of the expected v2/child.json.
It will also return v1/child.json even if the absolute path to v2/child.json is specified in the $ref.

Is there a way to use this without a filesystem?

Say I wanted to instantiate a schema from the response of a request to a URL or a read from a tuple in a document store, cache or database.

It seems all examples use a path parameter to a filesystem.
Can't I instantiate a schema from a string (or array of strings) so that it can come from anywhere?

Does this tool support self referential json files?

Hello,

I was reviewing this project. I was hoping that it would support a JSON file which contains references to itself. This is valid in JSON Schema, but it appears that this tool will take those references and always look to another json file in the project rather than see if that is a self reference. https://github.com/salesking/json_schema_tools/blob/master/lib/schema_tools/ref_resolver.rb#L32

Here is an example of a self referential JSON Schema:

{
   "title":"Application Dashboards",
   "type":"object",
   "properties":{
      "version":{
         "type":{
            "enum":[
               1.0
            ]
         }
      },
      "dashboards":{
         "type":"array",
         "minItems":1,
         "items":{
            "type":"object",
            "properties":{
               "name":{
                  "type":"string"
               },
               "team":{
                  "$ref":"#/definitions/team"
               },
               "services":{
                  "type":"array",
                  "items":{
                     "$ref":"#/definitions/service"
                  }
               },
               "layout":{
                  "$ref":"#/definitions/layout"
               }
            },
            "required":[
               "name",
               "layout",
               "services"
            ]
         }
      }
   },
   "required":[
      "dashboards",
      "version"
   ],
   "definitions":{
      "layout":{
         "type":"object",
         "oneOf":[
            {
               "title":"Quadrant Dashboard Layout",
               "type":"object",
               "properties":{
                  "type":{
                     "enum":[
                        "grid"
                     ]
                  },
                  "widgets":{
                     "type":"array",
                     "items":{
                        "properties":{
                           "widget_id":{
                              "description":"The unique id that references a specific widget",
                              "type":"string"
                           },
                           "x":{
                              "description":"The grid column on which to place this widget. Origin is upper-left",
                              "type":"integer"
                           },
                           "y":{
                              "description":"The grid row on which to place this widget. Origin is upper-left",
                              "type":"integer"
                           },
                           "span_x":{
                              "description":"How many columns this widget will span",
                              "type":"integer"
                           },
                           "span_y":{
                              "description":"How many rows this widget will span",
                              "type":"integer"
                           }
                        },
                        "required":[
                           "widget_id",
                           "x",
                           "y",
                           "span_x",
                           "span_y"
                        ]
                     }
                  }
               },
               "required":[
                  "type",
                  "widgets"
               ]
            }
         ]
      },
      "team":{
         "description":"The information about the team that supports this dashboard",
         "type":"object",
         "properties":{
            "name":{
               "description":"The name of this team",
               "type":"string"
            },
            "email":{
               "description":"The best contact email address for this team, usually a distribution list",
               "type":"string",
               "format":"email"
            },
            "defects":{
               "description":"A URL to JIRA to input tickets for defects for this team",
               "type":"string",
               "format":"uri"
            },
            "slack":{
               "description":"The slack chat room where a user can get support for this team",
               "type":"string",
               "pattern":"^\\#[a-z-]{1,21}$"
            },
            "pager_duty":{
               "description":"The email @hanoc.pagerduty.com to trigger a PD alert for this team",
               "type":"string",
               "format":"email"
            }
         },
         "required":[
            "name",
            "email"
         ]
      },
      "service":{
         "description":"The information about the service that this dashboard reflects",
         "type":"object",
         "properties":{
            "name":{
               "description":"The name of this application",
               "type":"string"
            },
            "portfolio":{
               "description":"The portfolio that this application supports",
               "type":"string"
            },
            "product":{
               "description":"The product that this application supports",
               "type":"string"
            },
            "slack":{
               "description":"The slack chat room where a user can get support for this application",
               "type":"string",
               "pattern":"^\\#[a-z-]{1,21}$"
            },
            "repositories":{
               "description":"An array of repositories that contribute to this application",
               "type":"array",
               "items":{
                  "type":"object",
                  "properties":{
                     "url":{
                        "description":"The url of the github repo for this application",
                        "type":"string",
                        "format":"uri"
                     }
                  },
                  "required":[
                     "url"
                  ]
               },
               "minItems":1,
               "uniqueItems":true
            }
         },
         "required":[
            "name",
            "repositories",
            "portfolio",
            "product"
         ]
      }
   }
}

Its possible I am missing something, does this project support references?
Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.