Comments (11)
I don't understand, would you like to read a schema directly from a string like NewJsonSchemaDocument({"a":1}
) ?
from gojsonschema.
I'm loading my schema JSON through other means, I would like to be able to just pass it to gojsonschema either as a byte array or string.
from gojsonschema.
I see, what about http://golang.org/pkg/encoding/json/#Unmarshal ?
from gojsonschema.
you mean using it to bind the JSON string to map[string]interface{}
?
from gojsonschema.
Yes exactly, go allows to do that quite easily with a few lines of code.
from gojsonschema.
meh, I can do that. It just feels like doing extra work, only so I can use your API. It's also inconsistent with the schemaDocument.Validate
function, which does receive JSON strings.
from gojsonschema.
In a perfect world, schemas are supposed to be loaded from an HTTP URL or a file, also they are supposed to remain in memory (loaded at init for example).
That was the main idea when designing this library. Then, on requests, i added the ability to load map schemas and also accept strings in Validate.
The convention is when you pass a string, NewJsonSchemaDocument takes it as an HTTP URL or file scheme.
If you really want/need this functionality to be part of the library, feel free to write your own and send me a pull request, it is something like 4 lines of code.
Something like NewJsonSchemaDocumentFromString with the json.Unmarshall code inside.
from gojsonschema.
I tend to agree with @c4milo that if this was a JSONSchema validation library then getting the schema should be far outside of the scope of the library itself.
A schema could come from a file, database or url. It could be sent in via an API call or it could be in a secure system somewhere. It could even be HTTP with a complex authentication scheme. There is also added complexity because JSONSchema can specify additional external resources via HTTP which may force the validation library to support retrieving content.
Ideally the validation library should not concern itself necessarily with where the rules come from. I understand however that this project started out as a specific solution to a problem @xeipuuv wanted to solve and there is a bit more nuance.
I am +1 for coming up with a clean way for the library to accept input from the application code.
from gojsonschema.
I also agree with @c4milo, I think there is no need for a debate here: You are both absolutely right.
My last answer was pretty clear i think, i simply explained the why of the current situation, I also gave hints, and explained the tricky part of such a modification; i also gave you a "quick fix" so that you can keep on doing your work.
Now the thing is that I simply dont have time to get back to this repo and make updates at the moment,
but i try my best to read the issues, explain and help when people need to.
That is the good thing with open source, anyone can update, improve, fix, use and enjoy these projects.
from gojsonschema.
JSON Strings are now allowed as arguments.
from gojsonschema.
👯 thank you!
from gojsonschema.
Related Issues (20)
- Validation should fail if required key is Go Zero Value for the corresponding type
- gojsonschema.NewGoLoader() returns NOTHING
- validation mishandles anyOf
- Load schema from string HOT 1
- The validate cannot find unknow fields
- Retry on "Could not read schema from HTTP, response status is 503 Service Temporarily Unavailable" HOT 2
- Validate return err on golang 1.19 HOT 1
- A DOS vulnerability exists in parameter validity check. HOT 3
- can we create json schema from json data HOT 1
- Using Frogbot to scan this repository
- Get all properties under a section
- Wrong validation result for nested objects HOT 2
- Usage of gojsonschema in prominent open-source or large-scale projects?
- Validation errors with integers
- Error "Must be a multiple of 0.01" for Value=2000000.13
- Hostname format false positives
- Support `errorMessage` so as to customise validation errors
- major api improvement HOT 2
- invalid character '{{character}}' looking for beginning of value
- Schema validation does not return error for invalid schema definition
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 gojsonschema.