GithubHelp home page GithubHelp logo

Comments (9)

santhosh-tekuri avatar santhosh-tekuri commented on July 17, 2024 1

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.

Cih2001 avatar Cih2001 commented on July 17, 2024

Thanks Santhosh, we are trying to move away from qri-iolibrary 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.

rubenhazelaar avatar rubenhazelaar commented on July 17, 2024

Thanks Santhosh, we are trying to move away from qri-iolibrary 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.

Cih2001 avatar Cih2001 commented on July 17, 2024

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.

rubenhazelaar avatar rubenhazelaar commented on July 17, 2024

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.

santhosh-tekuri avatar santhosh-tekuri commented on July 17, 2024

@rubenhazelaar

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.

rubenhazelaar avatar rubenhazelaar commented on July 17, 2024

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.

santhosh-tekuri avatar santhosh-tekuri commented on July 17, 2024

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.

rubenhazelaar avatar rubenhazelaar commented on July 17, 2024

Great, thank you. Good luck with your battle against the borrower :)

from jsonschema.

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.