Code Monkey home page Code Monkey logo

Comments (9)

anymaniax avatar anymaniax commented on May 14, 2024 3

Need to be reimplemented since v5. I will do it if you are still interested or someone else?

from orval.

melloware avatar melloware commented on May 14, 2024 1

+1 for this, this is what openapi-generator does it makes then Date objects.

from orval.

anymaniax avatar anymaniax commented on May 14, 2024

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.

techquestions avatar techquestions commented on May 14, 2024

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 strings (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.

anymaniax avatar anymaniax commented on May 14, 2024

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.

anymaniax avatar anymaniax commented on May 14, 2024

@techquestions I did the implementation and the example in this pull request #107. Can you check if this is what you want?

from orval.

dennisroche avatar dennisroche commented on May 14, 2024

@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.

melloware avatar melloware commented on May 14, 2024

PR Submitted. Wasn't quite sure how to add unit tests.

from orval.

melloware avatar melloware commented on May 14, 2024

Thanks for releasing 6.6.0 i just updated my project and it works like a charm!

from orval.

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.