feat: support custom field schemas; add omittable example #145
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds an optional
huma.SchemaProvider
interface, which a type can implement to provide its own custom JSON Schema, disabling the built-in schema generator and enabling customized behavior for request/response body fields.When combined with custom serialization logic, this can enable use-cases like determining whether a field was sent at all, is
null
, or is a value. A new example is added to showcase this functionality.As part of this work, a small change in
huma.go
is made to properly set theoperation.requestBody.required
OpenAPI field, and this field is then later checked to determine whether the body is required. This works much better with custom operation schemas, which would not be required before even when that field was set.Fixes #137.