Giter VIP home page Giter VIP logo

Comments (11)

xeipuuv avatar xeipuuv commented on August 15, 2024

I don't understand, would you like to read a schema directly from a string like NewJsonSchemaDocument({"a":1}) ?

from gojsonschema.

c4milo avatar c4milo commented on August 15, 2024

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.

xeipuuv avatar xeipuuv commented on August 15, 2024

I see, what about http://golang.org/pkg/encoding/json/#Unmarshal ?

from gojsonschema.

c4milo avatar c4milo commented on August 15, 2024

you mean using it to bind the JSON string to map[string]interface{}?

from gojsonschema.

xeipuuv avatar xeipuuv commented on August 15, 2024

Yes exactly, go allows to do that quite easily with a few lines of code.

from gojsonschema.

c4milo avatar c4milo commented on August 15, 2024

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.

xeipuuv avatar xeipuuv commented on August 15, 2024

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.

xealot avatar xealot commented on August 15, 2024

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.

xeipuuv avatar xeipuuv commented on August 15, 2024

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.

xeipuuv avatar xeipuuv commented on August 15, 2024

JSON Strings are now allowed as arguments.

from gojsonschema.

c4milo avatar c4milo commented on August 15, 2024

👯 thank you!

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.