Giter VIP home page Giter VIP logo

Comments (5)

ThomasAribart avatar ThomasAribart commented on June 20, 2024

Hmm I think it really depends on the context. Consider those two cases:

  • I handle validated value => value should be required
  • I input raw value (not validated) to a form or HTTP endpoint => value should be optional

So I think it should be configured through an option: FromSchema<mySchema, { someOption: boolean }>

The question now is what is default behavior of FromSchema ? I feel like it's more frequent to use FromSchema for validated values rather than inputs, so the option should be { keepDefaultedValuesOptional: true } ? That's a breaking change but a rather small one so I would be OK with implementing it.

WDYT ?

from json-schema-to-ts.

sceccotti89 avatar sceccotti89 commented on June 20, 2024

I think it totally make sense.
I tried to do it myself but typings is somewhat a bit dark magic to me.
It would be great you can take care of that, but I'm also curious about the changes that you'll make to implement it.

from json-schema-to-ts.

iamarthurk avatar iamarthurk commented on June 20, 2024

Much needed feature guys, let me know if it is on the roadmap or whether you are open to pull requests.

from json-schema-to-ts.

ThomasAribart avatar ThomasAribart commented on June 20, 2024

Feature is now available in the v3: #153 🙌

Wasn't so long to implement, sorry for the delay !

from json-schema-to-ts.

davidmurdoch avatar davidmurdoch commented on June 20, 2024

I feel like it's more frequent to use FromSchema for validated values rather than inputs

Interesting take. I think the use case of pre/post validation would be 50/50. The interface/function doing the validation of the raw data would need default-less types.

In my specific case I don't need to validate the data with defaults applied, since I'm calling into another API that will apply necessary defaults for me.

Of course this change doesn't really causes any issues, since the keepDefaultedPropertiesOptional option was also added, I just wanted to offer additional perspective on how this (awesome!) library is being used out in the wild. 🚀

from json-schema-to-ts.

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.