Giter Club home page Giter Club logo

Comments (9)

santhosh-tekuri avatar santhosh-tekuri commented on May 14, 2024

see the example

line 25 shows how it extracted the value of the custom keyword powerOf.
same way you can extract the value of your keyword which gives the uri-reference in string format.

from jsonschema.

santhosh-tekuri avatar santhosh-tekuri commented on May 14, 2024

got it. you need the location the the json document that is being verified.

the library don't ask for the document location. the user parses the json himself and calls Schema.Validate(interface{})

from jsonschema.

alexberdnik avatar alexberdnik commented on May 14, 2024

Well, here an example:

{
  "$id": "https://some.doc/doc1",
  "links": [
    "link": {
      "ref": "some/data-model.json"
    }
  ]
}

I want to validate that the "ref" is referencing to an existing document. For that I need to construct full URL: "https://some.doc/doc1/some/data-model.json". It is not possible to do that, because the context doesn't provide any information about current document.

from jsonschema.

santhosh-tekuri avatar santhosh-tekuri commented on May 14, 2024

assuming the example you have provided is instance document, you want to validate some/data-model.json relative to instance document. this library no where captures the instance document location. you have to do this at your end.

from jsonschema.

alexberdnik avatar alexberdnik commented on May 14, 2024

Again, I don't really need an instance location. I need an access to currently validated document (in addition to currently validated value) so I can extract the value from "$id" property. For example above, simplified schema could be:

"$id": {
  "type": "string",
  "format": "uri"
}
"links": {
  "type": "array",
  "items": {
    "type": "string",
    "format": "uri-schema",
    "validJson": true
  }
}

Where "validJson" is my custom keyword.

from jsonschema.

santhosh-tekuri avatar santhosh-tekuri commented on May 14, 2024

you are actually trying to validate the document that is being referred to using validJson Keyword.

I do not think i can pass the while instance document for validation(currently only the portion that is documented is passed)

I can suggest a workaround. since each instance document has single $id you can extract its value before validation and use it in your extension.

from jsonschema.

alexberdnik avatar alexberdnik commented on May 14, 2024

I currently use the workaround you mentioned, however I thought that it could be useful to have the whole document during the validation. This will add more possibilities for custom keywords.

type ValidationContext struct {
        document interface {}
	result          validationResult
	validate        func(sch *Schema, schPath string, v interface{}, vpath string) error
	validateInplace func(sch *Schema, schPath string) error
	validationError func(keywordPath string, format string, a ...interface{}) *ValidationError
}

from jsonschema.

santhosh-tekuri avatar santhosh-tekuri commented on May 14, 2024

problem is: func (s *Schema) validate(scope []schemaRef, vscope int, spath string, v interface{}, vloc string) is called recursively and when creating ValidationContext I do not have reference to the whole document.

otherwise, I have to modify func (s *Schema) validate(...) to add another argument to pass the while document along the call chain.

from jsonschema.

alexberdnik avatar alexberdnik commented on May 14, 2024

yep, it looks it can't be done without modification of validate function

from jsonschema.

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.