Comments (9)
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.
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.
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.
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.
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.
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.
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.
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.
yep, it looks it can't be done without modification of validate
function
from jsonschema.
Related Issues (20)
- Extension.Validate provides data in inconsistent order HOT 1
- Getting property name when compiling and validating user-defined keyword via extensions HOT 5
- Feature request: Pass custom compiler into "convenience" functions like CompileString HOT 2
- Performance drop when schema has "uniqueItems" set to true HOT 7
- `format` field of json schemas is not being validated HOT 1
- CompileString - stat .: permission denied HOT 1
- How can I validate to Python re flavor regex? HOT 4
- Proposal: Add Method to Generate Go Types from JSON Schema HOT 1
- Error when loading valid draft7 json schema HOT 2
- Validating json with json-schema HOT 4
- Draft2020 accepts invalid email address. HOT 5
- Support for $defs and definition keyword in Schema object. HOT 3
- ReadOnly and WriteOnly are getting ignored HOT 7
- i18n support
- Detailed output missing info
- Compiling a subresource with an extension validates the subresource against the root extension schema. HOT 6
- unexpected validation error which LSP is fine with HOT 10
- Provide CLI binaries with release HOT 2
- Link in README for YAML playground example is broken HOT 1
- Issue with custom Regex Library HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsonschema.