Git Product home page Git Product logo

Comments (4)

wolveix avatar wolveix commented on May 28, 2024 2

Understood, thank you for the detailed information! I can see why you put off refactoring it :)

The custom resolver route you suggested seems like it might work, so I'm going to play around with that a little bit. If not, I'll deep dive the codebase a bit to see whether I can figure out what needs to be refactored, and whether it makes sense for me to work on it or not.

Thanks again! Huma is such an excellent project :)

from huma.

danielgtaylor avatar danielgtaylor commented on May 28, 2024 1

@wolveix yes this is a little bit of an inconvenience until I can refactor some of the code to potentially support pointer parameters.

For now I suggest using meaningful zero values, so making it that false means no action is taken, same with numbers that are zero, empty string, time.Time.IsZero(), etc. If that's just not possible for some parameter, you can always load it manually using a resolver. Here's a quick example:

https://go.dev/play/p/S9h07SdH4Zr

The downside of using a resolver is you will need to manually document the parameter using e.g. api.OpenAPI().Paths["/your/path"].Get.Parameters....

from huma.

danielgtaylor avatar danielgtaylor commented on May 28, 2024 1

@wolveix unfortunately it's some of the most complex code in the project which glues together all the smaller pieces and takes the cached reflection info to parse and set values on structs. I just haven't had time to refactor / simplify this code.

The crux of the problem is that the callback to Every is called with a reflect.Value which in the non-pointer case is already an allocated piece of memory we can easily set. In the pointer case it is not, so it needs to be allocated only when needed and the value must be settable, otherwise you potentially need access to the parent. I'm not 100% sure anymore as it's been a while since I looked into this. Hope that helps, and don't feel bad abandoning this idea due to complexity and unfamiliarity with the codebase!

from huma.

wolveix avatar wolveix commented on May 28, 2024

Gotcha, thanks for the suggestions @danielgtaylor! What aspect of the code needs to be refactored to support it? I did have a brief look through, and would be happy to work on this myself if you wouldn't mind pointing out where specifically needs work :)

from huma.

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.