Comments (9)
Need to be reimplemented since v5. I will do it if you are still interested or someone else?
from orval.
+1 for this, this is what openapi-generator
does it makes then Date
objects.
from orval.
Hello,
First thanks for your interest and your investigation.
For me, the string is the appropriate default type since the type Date doesn't exist in a JSON. But we could find a proper way to override this and transform them into Date objects. More like a mix of this and the mutator functionality.
To solve this at the moment you could use the mutator feature to transform your payload automatically and normally everything should work correctly since I am using the type returned by the mutator function.
from orval.
For me, the string is the appropriate default type since the type Date doesn't exist in a JSON
JSON is a bit old format which doesn't even have proper support for numbers or object keys, that's why formats like JSON5 are being created. I actually thought that orval
focuses on TypeScript types, not what JSON offers.
To solve this at the moment you could use the mutator feature to transform your payload automatically and normally everything should work correctly since I am using the type returned by the mutator function.
I think this is a different thing. Yes, there will be a need to create a mutator, since Axios also deserializes dates to string
s (JSON.parse()
doesn't have any support for dates). And that is why I suggested this to be an option in orval's configuration, so that by default dates are still typed as strings.
Looking at the current examples, what I want is, in the pet.ts
, the Pet
to have a field of type Date
(if it has such field in the API definition of course).
It will not work out of the box by just using mutator and I believe a change in the library itself is needed. It could be a non-breaking change and it could be turned on via a configuration flag.
from orval.
Ok then we could add a property date: boolean in the override section which will put the type Date in the definition and you would do the parse of the payload in your project with the transformResponse
from axios for example.
from orval.
@techquestions I did the implementation and the example in this pull request #107. Can you check if this is what you want?
from orval.
@anymaniax I'm interested having Date
objects for our models.
How difficult would this be to re-implement on latest? or to have a mutator to use https://github.com/moment/luxon/ DateTime
objects?
from orval.
PR Submitted. Wasn't quite sure how to add unit tests.
from orval.
Thanks for releasing 6.6.0 i just updated my project and it works like a charm!
from orval.
Related Issues (20)
- Zod: Support for OpenApi spec 3.1.0 HOT 2
- SWR client how to get response headers
- Discriminators are not taken into consideration when inlined in response HOT 3
- React Query: Support passing `query.meta` / `mutation.meta` options to axios instance HOT 1
- Feature request: Split polymorphic mocks into it's own functions
- Build setting allParamsOptional is not working as expected HOT 3
- swr: Mutation fetchers are not strongly typed
- OpenAPI: Support for `const` values in string parameter types HOT 4
- Zod: add to @orval/zod support of anyOf/allOf/oneOf in requestBody
- MSW: overrideResponse can be a function HOT 2
- Feature Request: create factory method for instantiating OpenAPI models HOT 2
- ERR_UNSUPPORTED_ESM_URL_SCHEME when using transformer on Windows HOT 3
- faker override to much for nested object HOT 1
- Query options for an operation have no effect
- RangeError when generating mocks HOT 1
- NonReadonly type incorrectly includes readonly fields HOT 4
- Prettier: true fails for zod when not generating a schema
- Unstable return reference of generated hook when using a custom mutator hook.
- Zod: unstable/breaking variable names for validation lengths HOT 7
- Type Issue: RegEx is not accepted in `defineConfig.[name].input.filters.tags`
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 orval.