GithubHelp home page GithubHelp logo

Comments (3)

sigu-399 avatar sigu-399 commented on June 28, 2024

My understanding of the json schema specification is that referencing external file has to be done with a complete URL/URI (http://...). So by default, all your schemas "should" be served by your http server.

Now, because just like you i wanted to reference local files, I added a way to do so.
It has to be in the form: file://..., please note it has to be the full path, non relative one. for example:
"$ref": "file:///usr/something/data/json/schemas/bson_object_id.json#properties/_id"

Please note this is an "experimental" feature.

PS: Please label your issues as questions when they are not proper bugs/issues.

from gojsonschema.

phstc avatar phstc commented on June 28, 2024

Hey @sigu-399, thanks for you reply.

I see, the specification is vague regarding to $ref. I find relative paths useful, in case we have a project with many schemas which can be deployed in different environments (test, development, staging, production etc) with different absolute paths, but always with the same relative path.

PS: Please label your issues as questions when they are not proper bugs/issues.

I'm sorry for using issues as questions. Unfortunately I can't label issues, this feature is only available for project maintainers.


My bson_object_id.json accepts _id as a string _id: '52b8b007cbdb04659d0009e5' or as an object _id: { '$oid': '52b8b007cbdb04659d0009e5' }, as type accepts a string or an array. The "problem" is in case of object, because I would like to define a specific object which only accepts/requires $oid as a property/member. So I created an array of types as follows:

/data/json/schemas/bson_object_id.json

{
  "type": "object",
  "properties": {
    "_id": {
      "type": [ { "type": "string" },
                { "type": "object",
                  "additionalProperties" : false,
                  "properties": {
                    "$oid": {
                      "type": "string"
                    }
                  },
                  "required": [ "$oid" ]
                }
              ]
    }
  }
}

When I try to validate I get type must be of type string/array of strings. Do you have a suggestion how to define this kind of complex types?

PS: I know that the JSON schema still draft and it is vague. So, the implementations of JSON schema can diverge. In this case I'm trying to reuse (and measure how difficult it could be to adapt schemas, create Pull Requests etc) my schemas definitions which work with json-schema-ruby.

from gojsonschema.

sigu-399 avatar sigu-399 commented on June 28, 2024

This is in my opinion a strange way to write a schema given your needs.

I based my work on this http://json-schema.org/latest/json-schema-validation.html#anchor79 for the type keyword.
You could also use the OneOf keyword.

from gojsonschema.

Related Issues (20)

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.