Comments (9)
this library uses compilation
unlike unmarshalling
which is done by the library mentioned. So it is not trivial to implement marshalling.
few drawbacks if we implement marshalling feature:
- this library does not compile subschemas that are not used. i.e for examples if
$defs
you have two subschemas, but one of then is not used, then we won't compile that unused subschema. so when you marshal compiled schema the generated schema will not have that schema - reference resolution is done at compilation time (the library you mentioned does during validation time). so exact value of
$ref
is not stored anywhere in schema
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 json.Marshaler
. but generated schema may not be identical to original schema:
- it may have some subschemas missing
$ref
values may be different but they resolve to same one as original
currently I have no plans to implement this. since Schema
struct is public
you can implement this outside the library
from jsonschema.
Thanks Santhosh, we are trying to move away from qri-io
library exactly because of the concurrency issue it has. I ended up doing the same as you suggested, creating an internal package that wraps the jsonschema package, where I can implement my own methods.
Thanks for your time and explanation.
from jsonschema.
Thanks Santhosh, we are trying to move away from
qri-io
library exactly because of the concurrency issue it has. I ended up doing the same as you suggested, creating an internal package that wraps the jsonschema package, where I can implement my own methods.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.
from jsonschema.
Unfortunately, I can't share codes with you, as it is an internal implementation. But the idea could be as simple as wrapping the jsonschema.Schema
into another structure and store it's raw format alongside.
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 schema
in your custom Schema
type.
from jsonschema.
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 $defs
of the marshalled schema.
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.
from jsonschema.
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
from jsonschema.
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?
from jsonschema.
The rewrite is mainly for better maintenance.
- easier to understand reference resolution
- better error types
- remove global variables access to public
- show why format validation failed
- better validation error display
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.
from jsonschema.
Great, thank you. Good luck with your battle against the borrower :)
from jsonschema.
Related Issues (20)
- Provide CLI binaries with release HOT 3
- Link in README for YAML playground example is broken HOT 1
- Issue with custom Regex Library HOT 10
- `Compiler.AddResource` for adding pre-compiled schemas HOT 5
- Feature: Adding Context to Validate Method HOT 2
- Create JSONSchema from Compile()'s result HOT 2
- Wrong unevaluatedProperties validation errors HOT 6
- compiler.go bug in 171
- Invalid JSON schema does not error out HOT 2
- [bug] Not reading from stdin HOT 2
- Missing document file path in validation output when validating multiple documents HOT 5
- Error messages are revealing absolute file paths HOT 1
- YouValidateMe JSON Schema library server project built on this library
- ECMA-262 as the default regex in this library? HOT 1
- jsonschema.Compiler has no field or method CompileRegex HOT 7
- Question: parsing Schema to string HOT 1
- error is missing instanceLocation HOT 1
- Cannot install older version than `@latest` HOT 3
- The latest release doesn't build HOT 2
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.