Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need to explicitly call PrecomputeMessages() when using custom RequestBody #454

Open
guneyizol opened this issue May 27, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@guneyizol
Copy link

guneyizol commented May 27, 2024

for _, k := range s.propertyNames {

When using a custom RequestBody in a huma.Operation given to the huma.Register function, s.propertyNames field is only populated when the PrecomputeMessages() method is explicitly called on the Schema given to a MediaType.

Example:

// Schema definition
// ...

schema.PrecomputeMessages()

huma.Register(
        api,
        huma.Operation{
	        OperationID:   "post-user-attributes",
	        Method:        http.MethodPost,
	        Path:          "/",
	        Description:   "upsert the given attributes for the given user, validating using the given appKey's attributes",
	        Summary:       "upsert attributes",
	        DefaultStatus: http.StatusOK,
	        RequestBody: &huma.RequestBody{
		        Description: "My custom request schema",
		        Required:    true,
		        Content: map[string]*huma.MediaType{
			        "application/json": {
				        Schema: schema,
			        },
		        },
	        },
        },
// handler omitted

If this is a feature, I believe that it should be explicitly documented.

Thanks 🙏

@danielgtaylor danielgtaylor added the bug Something isn't working label Jun 3, 2024
@danielgtaylor
Copy link
Owner

@guneyizol nice catch, this is probably a bug. I'll try and get a fix up to ensure we always precompute at registration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants