Coder Social home page Coder Social logo

Comments (14)

JbIPS avatar JbIPS commented on May 18, 2024

I looked a bit at the code and I'm thinking of adding a case "anyOf" that will call the function again for each key.

What do you think?

from fast-json-stringify.

mcollina avatar mcollina commented on May 18, 2024

Can you add a reference to the part of the JSON Schema for this?

πŸ‘ for a PR anyway.

from fast-json-stringify.

JbIPS avatar JbIPS commented on May 18, 2024

Can you add a reference to the part of the JSON Schema for this?

I'm sorry, do you mean the JSON Schema spec ?

from fast-json-stringify.

mcollina avatar mcollina commented on May 18, 2024

Yes thanks!! a PR would be very welcome!

from fast-json-stringify.

JbIPS avatar JbIPS commented on May 18, 2024

I created #50 (and started it with failing tests) but I'm not sure how to start the implementation. My first guess was to add a case "anyOf" that will call the function again for each key.

What do you think of that?

from fast-json-stringify.

mcollina avatar mcollina commented on May 18, 2024

go for it!

from fast-json-stringify.

JbIPS avatar JbIPS commented on May 18, 2024

Worked a bit on that yesterday and I'm a bit stuck. A achieve to catch anyOf properties and iterate over the children but I can't see how I could tell to 'try' each one until one pass. I though the method $as[...] would throw errors if the type doesn't match but they don't.

Any leads?

Thanks

from fast-json-stringify.

mcollina avatar mcollina commented on May 18, 2024

I don’t know really. Trying multiple paths and throwing errors completely defeat the purpose of this library.

A possibility might be to use Ajv to validate all the various option, but it would be slower.

from fast-json-stringify.

JbIPS avatar JbIPS commented on May 18, 2024

If it's noted clearly that using anyOf cannot lead to any optimization but is supported, it could worth it, don't you think?

from fast-json-stringify.

mcollina avatar mcollina commented on May 18, 2024

Yes definitely.

from fast-json-stringify.

JbIPS avatar JbIPS commented on May 18, 2024

I finally had some time to work on this but I'm hitting an issue: how can I use ajv to validate the data inside the generated code? I tried to require it but require is not defined :/

from fast-json-stringify.

mcollina avatar mcollina commented on May 18, 2024

It should be done following this pattern: https://github.com/fastify/fast-json-stringify/blob/master/index.js#L90-L92

from fast-json-stringify.

JbIPS avatar JbIPS commented on May 18, 2024

Thank you! First draft of my implementation ready here

from fast-json-stringify.

JbIPS avatar JbIPS commented on May 18, 2024

Closed by #50

from fast-json-stringify.

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.