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

Handling Field Matching and Validation for application/x-www-form-urlencoded in Huma #642

Open
learning-go123 opened this issue Nov 7, 2024 · 1 comment
Labels
question Further information is requested

Comments

@learning-go123
Copy link

Refer to this: #285
I wrote the following code

var DefaultFormPostFormat = huma.Format{
	Marshal: nil,
	Unmarshal: func(data []byte, v any) error {
		params, err := url.ParseQuery(string(data))
		if err != nil {
			return err
		}
		if vPtr, ok := v.(*interface{}); ok {
			m := map[string]any{}
			for k := range params {
				m[snakeToCamel(k)] = params.Get(k)
			}
			*vPtr = m
			return nil
		}
		return mapForm(v, params)
	},
}

config.Formats["application/x-www-form-urlencoded"] = DefaultFormPostFormat

There is a problem here. If the fields of params are more than the fields of the structure in v, it will not pass the validation. Turning off validation will introduce additional validators. Is there some better way to make the code more unified?

@danielgtaylor danielgtaylor added the question Further information is requested label Nov 13, 2024
@danielgtaylor
Copy link
Owner

@learning-go123 sorry I don't entirely understand the question. Do you have a runnable example or some input example vs. input struct where this fails and what you would prefer to see happen?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants