danielgtaylor / danielgtaylor/huma
Suppress validation for specific types and rely only on Resolve()
- Dominant language
- Go
- Stars
- 4.4k
- Forks
- 285
- Avg merge
- 40m
- Merged PRs (30d)
- 1
Description
Hello,
I am trying to figure out if this is a known or intentional behavior. I want to use `Resolve` instead of the validation done based on the schema, the purpose is to allow deprecated enums to still be allowed but not listed in the generated openapi yaml, It seems that there is no way to include Enum in the Schema and at the same time use a different validation, Is there a way to suppress Schema validation for specific fields?
```
func (e MyEnum) Resolve(ctx huma.Context) []error {
if !e.IsValid() { // allowed to also include an enum called 'd' which should not be listed in the docs
return []error{v2.Error400BadRequest("Invalid enum value for my enum")}
}
return []error{}
}
func (e MyEnum) Schema(r huna.Registry) *huma.Schema {
return &v2.Schema{
Enum: []any{"a", "b", "c"},
Type: "string",
}
}
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by tracing how Huma handles the custom type's Resolve and Schema methods during request validation and OpenAPI generation. Check whether validation can be selectively bypassed while retaining the Schema Enum values; done when the behavior is implemented or clearly documented, with coverage for deprecated enum values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, openapi
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100