-
Notifications
You must be signed in to change notification settings - Fork 102
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
implementing json.Marshaler interface #154
Comments
this library uses few drawbacks if we implement marshalling feature:
then mentioned library does reference resolution during validation time. see here so it has to update keyword struct during validation. because of this its validation is not thread safe. in fact they have an issue for this. to conclude, it is possible to implement
currently I have no plans to implement this. since |
Thanks Santhosh, we are trying to move away from Thanks for your time and explanation. |
@Cih2001 Would it be possible for you to share this implementation? I am running into the same issue where I would like to show the schema as JSON through an endpoint. |
Unfortunately, I can't share codes with you, as it is an internal implementation. But the idea could be as simple as wrapping the type Schema struct {
schema jsonschema.Schema
raw []byte
} now you can define your custom marshaller and unmarshaller methods there: func (s *Schema) UnmarshalJSON(data []byte) error {
schema, err := jsonschema.CompileString("", string(data))
if err != nil {
return err
}
s.raw = data
s.schema = schema
return nil
} Similarly, you can define all other methods you need. If you depend heavily on functions provided by the jsonschema pkg, you may consider exporting |
Thank you @Cih2001, our requirements are quite specific as the marshalled schema must be valid and executable by other json schema libraries. This results in merging all refs in I have implemented it now, quite robustly I believe (although I am not an export on JSON Schema), but I am unsure if this is what you or others are looking for. @santhosh-tekuri has already indicated (#154 (comment)) he has no plans to implement something like this, which I can understand. @santhosh-tekuri would you consider looking at a PR in which I integrate my current solution into this library? I do need to make some time for this and of course I respect it if you think this is out-of-scope. |
I recently ported this library to rust (https://github.com/santhosh-tekuri/boon) while doing this I noticed that current implementation can be improved for better maintenance and some difficult to solve issues can be resolved. So planning to do major rewrite soon. So not currently in position to accept any new features. I might considering adding marshalling feature but only in new revised implementation |
Ok, thank you. Very curious about the rewrite and what the improvements will be. For now I will continue to use the current version and our own implementation. Do have some indication about a timeframe? |
The rewrite is mainly for better maintenance.
I started it few days back. while reading the boon code, I found a bug in it. currently fighting with rust borrower to fix the bug. from user point of view there should not be much difference other than minor api changes. |
Great, thank you. Good luck with your battle against the borrower :) |
Hey, will you consider implementing
json.Marshaller
interface on theSchema
? We are currently using https://github.com/qri-io/jsonschema in one project, and we rely on the fact that loaded schemas there can be marshalled back to a byte stream / string. https://github.com/qri-io/jsonschema/blob/780655b2ba0ed03f11ecc8606a8f6e7380bb57be/schema.go#L342We use this to store loaded schemas in the memory to store in a database a json byte array. We would love to switch to your library, but unfortunately, because of this missing feature, we are unable to do so. Will you consider adding this to the package? I might even be able to help on this one.
Thanks.
The text was updated successfully, but these errors were encountered: