Comments (5)
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.
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.
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.
Feature is now available in the v3: #153 🙌
Wasn't so long to implement, sorry for the delay !
from json-schema-to-ts.
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)
- BUG: Non recursive schema resolves as "any" and fails the build HOT 2
- json-schema-shorthand now compatible w/ json-schema-to-ts HOT 1
- Using release >= 2.9.0 leads to Type instantiation is excessively deep and possibly infinite.deno-ts(2589) HOT 2
- Comparison with `json-schema-to-typescript` HOT 1
- FromSchema returns unknown (code example) HOT 3
- VSCode syntax checking slow HOT 3
- Problem with dates HOT 1
- List on json-schema.org HOT 1
- Dynamically create a schema from a function HOT 1
- Simplest generic function doesn't work, because "too complex"? HOT 2
- Combining 'allOf' with 'If' / 'then' checks Do not resolve correctly in TS HOT 2
- Performance Issues with Generics HOT 2
- Definitons in references not resolved
- Properties with const are not typed as const. HOT 2
- Can no longer import JSONSchema7 HOT 1
- Types not resolving correctly after 2.9.2 HOT 3
- Getting `unknown` as result type HOT 1
- JSDoc sees type as never when marking some properties as required HOT 3
- Question: Is there a way to combine or use FromSchema with imported JSON schema
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 json-schema-to-ts.