Comments (4)
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.
@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.
@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.
- Collecting reflection info for params https://github.com/danielgtaylor/huma/blob/main/huma.go#L108
- Result object with
Each
method https://github.com/danielgtaylor/huma/blob/main/huma.go#L292 - Calling
Each
to process each value https://github.com/danielgtaylor/huma/blob/main/huma.go#L818
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.
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)
- Error return for huma.StreamResponse.Body HOT 1
- Schema(r huma.Registry) *huma.Schema not working on Pointer
- Validation errors localization HOT 2
- Question: Is there a way to add comments to fields? HOT 1
- Version Chi v4 Into Separate Release
- Removing schema reference in response HOT 2
- Multiline doc description for struct fields
- Bug: API doc hidden is not *real* hidden HOT 1
- Allow custom query param types.
- Required query parameter not going through validation when it is omitted HOT 1
- Generating Huma Code from OpenAPI Spec HOT 2
- Generating the openapi.json offline HOT 2
- Defining Servers Causes 404 from OpenAPI Endpoint HOT 1
- Unexported Fields in Schemas are Not Considered for Schema Generation HOT 2
- Any sample code to get http.Request.RemoteAddr in huma.context
- The validation of format:"email" is not perfect. HOT 3
- The default error response field value in openapi docs is "DEFAULT" HOT 2
- Support multiple query parameters with the same name
- Accessing validation results in the request pipeline
- Need to explicitly call PrecomputeMessages() when using custom RequestBody
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 huma.