Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessible schema properties #15

Open
brandur opened this issue May 7, 2014 · 7 comments
Open

Accessible schema properties #15

brandur opened this issue May 7, 2014 · 7 comments

Comments

@brandur
Copy link
Contributor

brandur commented May 7, 2014

Nearly all fields in gojsonschema structs are invisible outside the package. This works pretty well as long as its mainly used to call Validate, but it might be useful to be able to re-use gojsonschema to explore a document outside of this context. For example, if I've built a JSON Hyper Schema and would like to enumerate every link that it provides.

Have you put any thought into opening up these interfaces for re-use?

@xeipuuv
Copy link
Owner

xeipuuv commented May 15, 2014

Hi brandur, sorry for the late reply.
Validation being the main and only reasons for using this package, i never really thought about it.
Now that said, you are probably right, it seems pretty nice to have possibilities like theses.
Feel free to open these interfaces, or i might have a look at it later on.

@brandur
Copy link
Contributor Author

brandur commented May 15, 2014

Cool! Thanks of the reply. I mostly just wanted to let you know that this might be something worthwhile to explore. Feel free to close this out if appropriate.

@abecciu
Copy link

abecciu commented Jan 3, 2015

+1 this would be super useful!

@shutej
Copy link

shutej commented Jul 5, 2015

I agree. I'm currently looking at:

https://github.com/interagent/schematic

This seems to be developed by the Heroku folks for use on the Heroku-created Hyper Schema. They've re-implemented some of this package, but because Heroku's schema is now self-referential, their own code generator seems to ... not work.

I would think the design of this might go like so:

  • Make a Visitor interface and a Visit function on a parsed schema.
  • Make a ValidationVisitor struct that implements the visitor interface and tracks errors and validity internally.
  • Make the old validation functions into helpers that instantiate a ValidationVisitor and then call Visit on the schema.

This would then let other users instantiate their own visitors.

@shutej
Copy link

shutej commented Jul 5, 2015

@xeipuuv would you be open to a pull request that moves the design in this direction?

@xeipuuv
Copy link
Owner

xeipuuv commented Jul 7, 2015

Yes i am open to pull requests

@brandur
Copy link
Contributor Author

brandur commented Jul 7, 2015

This seems to be developed by the Heroku folks for use on the Heroku-created Hyper Schema. They've re-implemented some of this package, but because Heroku's schema is now self-referential, their own code generator seems to ... not work.

Yeah, this one is our bad :/ Essentially that project was booted off, but didn't really have a story around longer term maintenance and eventually it stopped working and wasn't fixed. I'm somewhat hopeful that some of the internal reorganization that we're doing will eventually put this in a position where it has some more dedicated maintainers, but that's a few months out at minimum unfortunately.

For what it's worth, I really like the proposed design above. Projects like Schematic shouldn't even think about trying to parse and interpret a JSON Schema for themselves and should instead rely on more complete and better vetted libraries like this one; having a generic visitor pattern would allow us to get there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants